title: How to split comma-separated key-value pairs with quoted commas
body: <p>I know there are a lot of other posts about parsing comma-separated values, but I couldn't find one that splits key-value pairs and handles quoted commas.</p>
  
  <p>I have strings like this:</p>
  
  <pre><code>age=12,name=bob,hobbies="games,reading",phrase="I'm cool!"
  </code></pre>
  
  <p>And I want to get this:</p>
  
  <pre><code>{
    'age': '12',
    'name': 'bob',
    'hobbies': 'games,reading',
    'phrase': "I'm cool!",
  }
  </code></pre>
  
  <p>I tried using <code>shlex</code> like this:</p>
  
  <pre><code>lexer = shlex.shlex('''age=12,name=bob,hobbies="games,reading",phrase="I'm cool!"''')
  lexer.whitespace_split = True
  lexer.whitespace = ','
  props = dict(pair.split('=', 1) for pair in lexer)
  </code></pre>
  
  <p>The trouble is that <code>shlex</code> will split the <code>hobbies</code> entry into two tokens, i.e. <code>hobbies="games</code> and <code>reading"</code>.  Is there a way to make it take the double quotes into account?  Or is there another module I can use?</p>
  
  <p>EDIT: Fixed typo for <code>whitespace_split</code></p>
  
  <p>EDIT 2: I'm not tied to using <code>shlex</code>. Regex is fine too, but I didn't know how to handle the matching quotes.</p>