Commit c05c5f63 authored by Recteur LP's avatar Recteur LP

Update auth.py Python 3.9 Compatible

parent 6a6f0327
Pipeline #1576 passed with stages
in 7 minutes and 39 seconds
......@@ -30,6 +30,7 @@ if six.PY3:
def tonative(n, encoding='utf-8'):
"""Return the given string as a native string in the given encoding."""
# In Python 3, the native string type is unicode
n = base64.decodebytes(n)
if isinstance(n, bytes):
return n.decode(encoding)
return n
......@@ -37,6 +38,7 @@ else:
def tonative(n, encoding='utf-8'):
"""Return the given string as a native string in the given encoding."""
# In Python 2, the native string type is bytes.
n = base64.decodestring(n)
if isinstance(n, six.text_type): # unicode for Python 2
return n.encode(encoding)
return n
......@@ -47,8 +49,7 @@ def base64_decode(n, encoding='utf-8'):
# Something Wrong with Python 3 string type ...
if n[0] == "b" and n[1] == "'" and n[-1] == "'":
n = n[2:-1]
decoded = base64.decodestring(n.encode(encoding))
return tonative(decoded, encoding)
return tonative(n.encode(encoding), encoding)
def _parseDigestAuthorization(auth_params):
......
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