title: Encoding a string the CSS way with python
body: <p>Is there a function or package in python that I can use to encode a string according to make sure it can be used as a <a href="http://www.w3.org/TR/CSS2/syndata.html#strings" rel="nofollow">CSS string</a>? It would need to escape all single and double quotes and backslashes, and replace newlines with <code>\A</code>.</p>
  
  <p>For instance:</p>
  
  <pre><code>This is "it", isn't\
  it?
  </code></pre>
  
  <p>should be converted to</p>
  
  <pre><code>This is \"it\", isn't\\\A it?
  </code></pre>
  
  <p>Non-ASCII characters can be left untouched, if they are printed as utf-8.</p>