a4e9bd
diff -r abaf4a78f69b paste/auth/digest.py
a4e9bd
--- a/paste/auth/digest.py	Wed Dec 21 09:00:48 2011 -0800
a4e9bd
+++ b/paste/auth/digest.py	Wed Dec 21 16:03:49 2011 -0800
a4e9bd
@@ -38,6 +38,34 @@
a4e9bd
 import time, random
a4e9bd
 from urllib import quote as url_quote
a4e9bd
 
a4e9bd
+def _split_auth_string(auth_string):
a4e9bd
+    """ split a digest auth string into individual key=value strings """
a4e9bd
+    prev = None
a4e9bd
+    for item in auth_string.split(","):
a4e9bd
+        try:
a4e9bd
+            if prev.count('"') == 1:
a4e9bd
+                prev = "%s,%s" % (prev, item)
a4e9bd
+                continue
a4e9bd
+        except AttributeError:
a4e9bd
+            if prev == None:
a4e9bd
+                prev = item
a4e9bd
+                continue
a4e9bd
+            else:
a4e9bd
+                raise StopIteration
a4e9bd
+        yield prev.strip()
a4e9bd
+        prev = item
a4e9bd
+
a4e9bd
+    yield prev.strip()
a4e9bd
+    raise StopIteration
a4e9bd
+
a4e9bd
+def _auth_to_kv_pairs(auth_string):
a4e9bd
+    """ split a digest auth string into key, value pairs """
a4e9bd
+    for item in _split_auth_string(auth_string):
a4e9bd
+        (k, v) = item.split("=", 1)
a4e9bd
+        if v.startswith('"') and len(v) > 1 and v.endswith('"'):
a4e9bd
+            v = v[1:-1]
a4e9bd
+        yield (k, v)
a4e9bd
+
a4e9bd
 def digest_password(realm, username, password):
a4e9bd
     """ construct the appropriate hashcode needed for HTTP digest """
a4e9bd
     return md5("%s:%s:%s" % (username, realm, password)).hexdigest()
a4e9bd
@@ -98,10 +126,7 @@
a4e9bd
         (authmeth, auth) = authorization.split(" ", 1)
a4e9bd
         if 'digest' != authmeth.lower():
a4e9bd
             return self.build_authentication()
a4e9bd
-        amap = {}
a4e9bd
-        for itm in auth.split(","):
a4e9bd
-            (k,v) = [s.strip() for s in itm.strip().split("=", 1)]
a4e9bd
-            amap[k] = v.replace('"', '')
a4e9bd
+        amap = dict(_auth_to_kv_pairs(auth))
a4e9bd
         try:
a4e9bd
             username = amap['username']
a4e9bd
             authpath = amap['uri']