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