[PATCH 5 of 6 rememberme] [py3] Only decode cookie's value if it's bytes

Denis Laxalde denis.laxalde at logilab.fr
Mon Jun 4 12:06:58 CEST 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1528105116 -7200
#      Mon Jun 04 11:38:36 2018 +0200
# Node ID 15ba39a67d28ec1c81be32f4dd3be04eddf1b787
# Parent  0cf1f1c1a3ef1d352623fb1c7bf3b2fb71311946
# Available At http://hg.logilab.org/review/cubes/rememberme
#              hg pull http://hg.logilab.org/review/cubes/rememberme -r 15ba39a67d28
# EXP-Topic py3
[py3] Only decode cookie's value if it's bytes

Only python3 at least, the value appears to be a unicode string (which
has no "decode" method).

diff --git a/views.py b/views.py
--- a/views.py
+++ b/views.py
@@ -42,9 +42,11 @@ class AuthCookieRetriever(authentication
         """
         cookie = req.get_cookie()
         try:
-            authcookie = cookie['__cw_auth_cookie'].value.decode('ascii')
+            authcookie = cookie['__cw_auth_cookie'].value
         except KeyError:
             raise authentication.NoAuthInfo()
+        if not isinstance(authcookie, text_type):
+            authcookie = authcookie.decode('ascii')
         try:
             login, magic = authcookie.split('|__magic=', 1)
         except ValueError:


More information about the cubicweb-devel mailing list