# HG changeset patch # User Goffi # Date 1452279231 -3600 # Node ID f1fc7245b910f99f7fa3dcb194c051c4506b050c # Parent 70939916dc807995b03649882ba911a783f91121 server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url diff -r 70939916dc80 -r f1fc7245b910 src/server/blog.py --- 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 = ' ' - 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))