changeset 552:d30ae1dca471

macro.pdf2svg: checks if attachment or URL exists
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Mon, 28 Feb 2011 11:36:22 +0100
parents 025a4f729389
children 814c6075c0b0
files data/plugin/macro/pdf2svg.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/macro/pdf2svg.py	Mon Feb 28 11:05:52 2011 +0100
+++ b/data/plugin/macro/pdf2svg.py	Mon Feb 28 11:36:22 2011 +0100
@@ -31,6 +31,17 @@
 CACHE_ARENA = 'sendcache'
 CACHE_SCOPE = 'wiki'
 
+def url_exists(url):
+    content = ""
+    try:
+        item = urllib2.urlopen(url)
+        content = item.read(size=1)
+        item.close()
+    except (IOError, urllib2.HTTPError, ValueError):
+        return False
+    if content:
+        return True
+    return False
 
 def last_modified(request=None, pagename=None, attachment=None, url=""):
     if not url:
@@ -90,9 +101,13 @@
 
     if os.name == 'posix':
         if attachment:
+            if not AttachFile.exists(request, pagename, attachment):
+                return "attachment: %s does not exists" % attachment
             url = AttachFile.getAttachUrl(pagename, attachment, request)
             identifier = last_modified(request, pagename, attachment)
         else:
+            if not url_exists(url):
+                return "url: %s does not exists" % url
             identifier = last_modified(url=url)
         logging.debug("%s: %s" % (url, identifier))