renesd at gmail.com
Tue Apr 26 06:23:32 CEST 2005
repr works quite well, and I've used it with lots of different
>>> a = u'a=\'asdfd\';\n\r\n'
>>> print repr(a)
This is an invalid js string. eek. So first we need to translate it
to the correct charset encoding for the document. However js and
python encoding of unicode in strings is different too.
Here is one below which kind of works for js unicode stuff. But not
correctly, and the output isn't the best(too many backslashes), and it
isn't the fastest.
def encode_js(text, charset = None):
text= text.encode([charset, 'utf-8'][charset==None])
text = text.replace("\r", "\\r").replace("\n", "\\n")
text = text.replace('"', '\\"').replace("'", "\\'")
return "'" + text + "'"
This would be a good function to get right. We need the
specifications, as well as unittests first :)
On 4/26/05, Shannon -jj Behrens <jjinux at gmail.com> wrote:
> Hey guys,
> var s = "$s";
> I need to make $s safe:
> Has anyone coded this yet? Will the same function work for both
> single and double quoted strings? Can I steal some code?
> Thanks :-D
> I have decided to switch to Gmail, but messages to my Yahoo account will
> still get through.
> Web-SIG mailing list
> Web-SIG at python.org
> Web SIG: http://www.python.org/sigs/web-sig
> Unsubscribe: http://mail.python.org/mailman/options/web-sig/renesd%40gmail.com
More information about the Web-SIG