changeset 1224:62bf4f87c249

server: some encoding fixes following python 3 port
author Goffi <goffi@goffi.org>
date Sun, 06 Oct 2019 22:21:13 +0200
parents 4976eb0f5315
children 63f7a2bd1d4a
files libervia/server/pages.py libervia/server/server.py libervia/server/utils.py
diffstat 3 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/server/pages.py	Sun Aug 25 12:16:34 2019 +0200
+++ b/libervia/server/pages.py	Sun Oct 06 22:21:13 2019 +0200
@@ -1138,7 +1138,7 @@
                 redirect_page = redirect_page.original.children[subpage]
 
         if path_args is not None:
-            args = [quote(a) for a in path_args]
+            args = [quote(a).encode() for a in path_args]
             request.postpath = args + request.postpath
 
         if self._do_cache:
@@ -1277,7 +1277,7 @@
             log.warning("not allowed exception catched")
             self.pageError(request, C.HTTP_FORBIDDEN)
         log.error(_("Uncatched error for HTTP request on {url}: {msg}")
-            .format( url=request.URLPath(), msg=failure_))
+            .format(url=request.URLPath().decode(), msg=failure_))
         self.pageError(request, C.HTTP_INTERNAL_ERROR)
 
     def _on_data_post_error(self, failure_, request):
@@ -1561,9 +1561,10 @@
                 del request.postpath[-1]
 
             # i18n
-            if C.KEY_LANG in request.args:
+            key_lang = C.KEY_LANG.encode()
+            if key_lang in request.args:
                 try:
-                    locale = request.args.pop(C.KEY_LANG)[0]
+                    locale = request.args.pop(key_lang)[0].decode()
                 except IndexError:
                     log.warning("empty lang received")
                 else:
--- a/libervia/server/server.py	Sun Aug 25 12:16:34 2019 +0200
+++ b/libervia/server/server.py	Sun Oct 06 22:21:13 2019 +0200
@@ -1310,11 +1310,10 @@
                         if proxy_port is not None
                         else proxy_server
                     )
-                proxy_netloc = proxy_netloc.decode("utf-8")
                 try:
                     proxy_scheme = request.requestHeaders.getRawHeaders(
                         "x-forwarded-proto"
-                    )[0].decode("utf-8")
+                    )[0]
                 except TypeError:
                     proxy_scheme = None
             else:
--- a/libervia/server/utils.py	Sun Aug 25 12:16:34 2019 +0200
+++ b/libervia/server/utils.py	Sun Oct 06 22:21:13 2019 +0200
@@ -28,7 +28,7 @@
 
 def quote(value, safe="@"):
     """shortcut to quote an unicode value for URL"""
-    return urllib.parse.quote(value.encode("utf-8"), safe=safe)
+    return urllib.parse.quote(value, safe=safe)
 
 
 class ProgressHandler(object):