Changes by Martin Panter vadmium...@gmail.com:
--
nosy: +vadmium
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18679
___
___
Python-bugs-list
R. David Murray added the comment:
Well, you could writing a streaming codec. Even if it didn't get accepted for
the stdlib, you could put it up on pypi.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18679
Derek Wilson added the comment:
Any update on this? Just so you can see what my work around is, I'll paste in
the code I'm using. The major issue I have with this is that performance
doesn't scale to large strings.
This is also a bytes-to-bytes or str-to-str encoding, because this is the type
Derek Wilson added the comment:
using repr(x)[1:-1] is not safe for my use case as i need this for encoding and
decoding data. the deserialization of repr would be eval, and aside from the
security issues with that, if I strip the quotes off I can't reliably eval the
result and get back the
Serhiy Storchaka added the comment:
ast.literal_eval('%s' % e)
e.encode().decode('unicode-escape').encode('latin1').decode()
e.encode('latin1', 'backslashescape').decode('unicode-escape')
--
nosy: +serhiy.storchaka
___
Python tracker
Derek Wilson added the comment:
ast.literal_eval('%s' % e)
this doesn't work if you use the wrong quote. without introspecting the data in
e you can't reliably choose whether to use '%s' '%s' '%s' or
'''%s'''. which ones break (and break siliently) depend on the data.
Serhiy Storchaka added the comment:
this doesn't work if you use the wrong quote. without introspecting the data
in e you can't reliably choose whether to use '%s' '%s' '%s' or
'''%s'''.
Indeed.
and again tools other than python will run into escaped quotes in the data
which may cause
Derek Wilson added the comment:
e.encode('latin1', 'backslashreplace').decode('unicode-escape')
this works, but still the quotes are backslash escaped.
translate will do what i need for my use case, but it doesn't support streaming
for larger chunks of data.
it is nice that there is a
New submission from Derek Wilson:
Escaping strings for serialization or display is a common problem. Currently,
in python3, in order to escape a sting, you need to do this:
'my\tstring'.encode('unicode_escape').decode('ascii')
This would give you a string that was represented like this:
R. David Murray added the comment:
In what way does repr(x)[1:-1] not serve your use case?
--
nosy: +r.david.murray
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18679
___
10 matches
Mail list logo