Commit 3b580cde authored by Arnaud Fontaine's avatar Arnaud Fontaine

zope4py3: Update CookieCrumbler monkey-patch to properly handle bytes().

parent af0cefdc
from future import standard_library
standard_library.install_aliases()
from urllib.parse import unquote
return unquote(value).decode('base64').split(':', 1)[0]
from base64 import standard_b64decode
return standard_b64decode(unquote(value)).split(b':', 1)[0].decode()
from future import standard_library
standard_library.install_aliases()
from past.utils import old_div
from urllib.parse import urlparse
portal = context.getPortalObject()
......@@ -12,7 +9,7 @@ else:
expire_interval /= 86400. # seconds -> days
now = DateTime()
kw['expires'] = (now + expire_interval).toZone('GMT').rfc822()
ac_renew = (now + old_div(expire_interval, 2)).millis()
ac_renew = (now + expire_interval / 2).millis()
portal.portal_sessions[
portal.Base_getAutoLogoutSessionKey(
username=portal.Base_getUsernameFromAuthenticationCookie(
......
......@@ -59,7 +59,9 @@ def encodeKey(key):
"""
# According to the memcached's protocol.txt, the key cannot contain
# control characters and white spaces.
return encodestring(key, True).replace('\n', '').replace('\r', '')
if isinstance(key, str):
key = key.encode()
return encodestring(key, True).replace(b'\n', b'').replace(b'\r', b'')
if memcache is not None:
# Real memcache tool
......
......@@ -25,6 +25,8 @@ Patch CookieCrumbler to prevent came_from to appear in the URL
when ERP5 runs in "require_referer" mode.
"""
import six
from builtins import object
from future import standard_library
standard_library.install_aliases()
......@@ -140,7 +142,11 @@ def modifyRequest(self, req, resp):
attempt = ATTEMPT_LOGIN
name = req[self.name_cookie]
pw = req[self.pw_cookie]
ac = standard_b64encode('%s:%s' % (name, pw))
if six.PY2:
ac = standard_b64encode('%s:%s' % (name, pw)).rstrip()
else:
ac = standard_b64encode(
('%s:%s' % (name, pw)).encode()).rstrip().decode()
self._setAuthHeader(ac, req, resp)
if req.get(self.persist_cookie, 0):
# Persist the user name (but not the pw or session)
......@@ -161,7 +167,10 @@ def modifyRequest(self, req, resp):
ac = unquote(req[self.auth_cookie])
if ac and ac != 'deleted':
try:
if six.PY2:
standard_b64decode(ac)
else:
standard_b64decode(ac.encode())
except:
# Not a valid auth header.
pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment