Commits

Hong Minhee  committed 02a1d38

Fixed a bug of `Environment.authorization` property.

  • Participants
  • Parent commits c5ca5a3

Comments (0)

Files changed (1)

File irclog/web/__init__.py

 
            >>> assert isinstance(env, Environment)  # doctest: +SKIP
            >>> env['HTTP_AUTHORIZATION']  # doctest: +SKIP
-           'dXNlcjpwYXNz'
+           'Basic dXNlcjpwYXNz'
            >>> env.authorization  # doctest: +SKIP
            ('user', 'pass')
 
             auth = self["HTTP_AUTHORIZATION"]
         except KeyError:
             return
-        return tuple(base64.b64decode(auth.split()[1]).split(":", 1))
+        type, auth = auth.split()
+        if type.lower() == "basic":
+            return tuple(base64.b64decode(auth).split(":", 1))
+        elif type.lower() == "digest":
+            m = re.search(r'(?:^|,)\s*username\s*=\s*"([^"]*)"\s*(?:,|$)',
+                          auth, re.I)
+            if m:
+                return m.group(1), None
 
     def __repr__(self):
         cls = type(self)