degal/templates.py
changeset 135 6534c77de93f
parent 127 37d19805b7ca
child 136 29e41a6415d7
--- a/degal/templates.py	Wed Jun 17 18:11:38 2009 +0300
+++ b/degal/templates.py	Fri Jun 26 22:09:13 2009 +0300
@@ -5,14 +5,26 @@
 import html, version
 from html import tags
 
+import urllib
+
+def quote_path (path) :
+    """
+        Return an unicode-safe string with the escaped contents of the given str-able object, suitable for use
+        in HTTP URLs.
+
+        This should provide correct behaviour for use with filesystem Nodes.
+
+        XXX: even this could be abstracted to some kind of "URL" thing
+    """
+
+    return urllib.quote(str(path))
+
 def link_from (source, target) :
     """
-        Returns a partial a tag linking from the given page to the given page
-
-        XXX: URLEncode unicode -> str!
+        Returns a partial a tag linking from the given source page to the target page, escaping binary paths.
     """
 
-    return tags.a(href=source.path_to(target))
+    return tags.a(href=quote_path(source.path_to(target)))
 
 def image_link (from_page, image, target) :
     """
@@ -20,7 +32,7 @@
     """
 
     return link_from(from_page, target)(
-        tags.img(src=image.path_from(from_page))
+        tags.img(src=quote_path(image.path_from(from_page)))
     )
 
 def image_page (image) :