Richard Hansen <rhan...@bbn.com> added the comment:

> If we change this, the encoder should quote both single and double 
> quotes - simply because it is not known whether the literal 
> will use single or double quotes.

Or document that single quotes are always escaped so that the user knows he/she 
can safely use u''.  I'm not sure if there is a use case where both would 
*need* to be escaped, and escaping both has a size penalty.

I've attached an untested patch that escapes both.

If both are escaped, then the behavior of the string_escape codec should also 
be changed for consistency (it only escapes single quotes).

> The raw_unicode_escape codec would have to be fixed as well.

I'm not sure there's anything to fix.  Adding backslashes to quotes in raw 
strings changes the value of the string -- the backslashes prevent the quotes 
from ending the string literal, but they are not removed when the raw literal 
is evaluated.

Perhaps raw_unicode_escape should be "fixed" by raising an exception when it 
contains any quotes.

----------
Added file: 
http://bugs.python.org/file15729/unicode_escape_single_and_double_quotes.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue7615>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to