urlencode native filesystem node paths for template's http URLs
authorTero Marttila <terom@fixme.fi>
Fri, 26 Jun 2009 22:09:13 +0300
changeset 135 6534c77de93f
parent 134 ea05fe81ff67
child 136 29e41a6415d7
urlencode native filesystem node paths for template's http URLs
degal/config.py
degal/templates.py
--- a/degal/config.py	Wed Jun 17 18:11:38 2009 +0300
+++ b/degal/config.py	Fri Jun 26 22:09:13 2009 +0300
@@ -99,6 +99,7 @@
     def debug (self) : self.log_level = logging.DEBUG
 
     # number of threads to use for concurrency
+    # use some heuristic?
     thread_count        = 2
 
     # the name of this folder, only applies on one level
--- 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) :