title: Parse an HTTP request Authorization header with Python
body: <p>I need to take a header like this:</p>
  
  <pre><code> Authorization: Digest qop="chap",
       realm="testrealm@host.com",
       username="Foobear",
       response="6629fae49393a05397450978507c4ef1",
       cnonce="5ccc069c403ebaf9f0171e9517f40e41"
  </code></pre>
  
  <p>And parse it into this using Python:</p>
  
  <pre><code>{'protocol':'Digest',
    'qop':'chap',
    'realm':'testrealm@host.com',
    'username':'Foobear',
    'response':'6629fae49393a05397450978507c4ef1',
    'cnonce':'5ccc069c403ebaf9f0171e9517f40e41'}
  </code></pre>
  
  <p>Is there a library to do this, or something I could look at for inspiration?</p>
  
  <p>I'm doing this on Google App Engine, and I'm not sure if the Pyparsing library is available, but maybe I could include it with my app if it is the best solution.</p>
  
  <p>Currently I'm creating my own MyHeaderParser object and using it with reduce() on the header string.  It's working, but very fragile.</p>
  
  <p>Brilliant solution by nadia below:</p>
  
  <pre><code>import re
  
  reg = re.compile('(\w+)[=] ?"?(\w+)"?')
  
  s = """Digest
  realm="stackoverflow.com", username="kixx"
  """
  
  print str(dict(reg.findall(s)))
  </code></pre>