diff options
author | Helmut Grohne <helmut@subdivi.de> | 2012-06-29 08:47:51 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2012-06-29 19:18:55 +0200 |
commit | 472144ac68188056eb41c9cb198df04b454a1da2 (patch) | |
tree | 1a9b05539161601cd8097b5411d550d9fac971a5 /wsgitools/middlewares.py | |
parent | eba0855c881bea9f533a8d4b359f8711125e5037 (diff) | |
download | wsgitools-472144ac68188056eb41c9cb198df04b454a1da2.tar.gz |
fix hashlib, base64 and other bytes issues
* hashlib.md5 wants bytes now.
* string.decode("base64") is now base64.b64decode and works on bytes
* binascii.unhexlify is now base64.b16decode and also works on bytes
* str.isalnum accepts umlauts, use bytes.isalnum instead
Diffstat (limited to 'wsgitools/middlewares.py')
-rw-r--r-- | wsgitools/middlewares.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/wsgitools/middlewares.py b/wsgitools/middlewares.py index e6ede9d..725deb1 100644 --- a/wsgitools/middlewares.py +++ b/wsgitools/middlewares.py @@ -1,12 +1,14 @@ __all__ = [] +import base64 import time import sys import cgitb -import binascii import collections import io +from wsgitools.internal import bytes2str, str2bytes + if sys.version_info[0] >= 3: def exc_info_for_raise(exc_info): return exc_info[0](exc_info[1]).with_traceback(exc_info[2]) @@ -347,14 +349,14 @@ class BasicAuthMiddleware(AuthenticationMiddleware): self.app401 = app401 def authenticate(self, auth, environ): - """ - @type environ: {str: object} - """ + assert isinstance(auth, str) assert isinstance(environ, dict) + auth = str2bytes(auth) try: - auth_info = auth.decode("base64") - except binascii.Error: + auth_info = base64.b64decode(auth) + except TypeError: raise ProtocolViolation("failed to base64 decode auth_info") + auth_info = bytes2str(auth_info) try: username, password = auth_info.split(':', 1) except ValueError: |