python convert str to javascript literal string
<p>I want to use python to generate javascript code dynamiclly. </p>

<pre><code>def convert(jsstring=''):
    return 'function dosomething () { return %s.toLowerCase(); }' % jsstring
</code></pre>

<p>The problem is <code>jsstring</code> is a python string.</p>

<p>How can i convert it back to javascript string literal to make <code>dosomething</code> a valid javascript function ?</p>

<p>for example</p>

<p>call</p>

<pre><code>convert("javascript")
</code></pre>

<p>now output</p>

<pre><code> function dosomething () { return javascript.toLowerCase(); }
</code></pre>

<p>which is not a valid javascript function</p>

<p>expected output</p>

<pre><code> function dosomething () { return "javascript".toLowerCase(); }
</code></pre>

<p>another example, call</p>

<pre><code>convert("javascript\'")
</code></pre>

<p>expected output</p>

<pre><code> function dosomething () { return "javascript\'".toLowerCase(); }
</code></pre>

<p>Thanks a lot.</p>
