changeset 827:f1fc7245b910

server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
author Goffi <goffi@goffi.org>
date Fri, 08 Jan 2016 19:53:51 +0100
parents 70939916dc80
children 0c824ebe9d87
files src/server/blog.py
diffstat 1 files changed, 22 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/server/blog.py	Fri Jan 08 19:50:40 2016 +0100
+++ b/src/server/blog.py	Fri Jan 08 19:53:51 2016 +0100
@@ -43,6 +43,25 @@
 
 # TODO: chech disco features and use max_items when RSM is not available
 
+
+def _quote(value):
+    """Quote a value for use in url
+
+    @param value(unicode): value to quote
+    @return (str): quoted value
+    """
+    return urllib.quote(value.encode('utf-8'), '')
+
+
+def _unquote(quoted_value):
+    """Unquote a value coming from url
+
+    @param unquote_value(str): value to unquote
+    @return (unicode): unquoted value
+    """
+    return urllib.unquote(quoted_value).decode('utf-8')
+
+
 class TemplateProcessor(object):
 
     THEME = 'default'
@@ -79,22 +98,6 @@
         self.avatars_cache = {}
         self.waiting_deferreds = {}
 
-    def _quote(self, value):
-        """Quote a value for use in url
-
-        @param value(unicode): value to quote
-        @return (str): quoted value
-        """
-        return urllib.quote(value.encode('utf-8'), '')
-
-    def _unquote(self, quoted_value):
-        """Unquote a value coming from url
-
-        @param unquote_value(str): value to unquote
-        @return (unicode): unquoted value
-        """
-        return urllib.unquote(quoted_value).decode('utf-8')
-
     def entityDataUpdatedHandler(self, entity_s, key, value, dummy):
         """Retrieve the avatar we've been waiting for and fires the callback.
 
@@ -135,7 +138,7 @@
         if not request.postpath or len(request.postpath) > 2:
             return self.useTemplate(request, "static_blog_error", {'message': "You must indicate a nickname"})
 
-        prof_requested = self._unquote(request.postpath[0])
+        prof_requested = _unquote(request.postpath[0])
 
         try:
             prof_found = self.host.bridge.getProfileName(prof_requested)
@@ -191,7 +194,7 @@
                 request.item_id = None
             else:
                 request.atom = False
-                request.item_id = request.postpath[1]
+                request.item_id = _unquote(request.postpath[1])
         else:
             request.item_id = None
             request.atom = False
@@ -542,7 +545,7 @@
             self.author = (_("from {}").format(entry['author']))
         else:
             self.author = '&nbsp;'
-            self.url = "{}/{}".format(base_url, entry['id'].encode('utf-8'))
+            self.url = "{}/{}".format(base_url, _quote(entry['id']))
             self.title = self.getText(entry, 'title')
             self.tags = list(common.dict2iter('tag', entry))