Message332208
Encoding and decoding, in the most general sense, can include unicode -> unicode and bytestring -> bytestring.
I can't see any standard unicode->unicode encodings in Python 2.7
https://docs.python.org/2/library/codecs.html
but we can create one:
py> import codecs
py> class NullCodec(codecs.Codec): # "do nothing" codec
... def encode(self, input, errors='strict'):
... return (input, len(input))
... def decode(self, input, errors='strict'):
... return (input, len(input))
...
py> def getregentry(name):
... return codecs.CodecInfo(
... name='null',
... encode=NullCodec().encode,
... decode=NullCodec().decode,
... incrementalencoder=None,
... incrementaldecoder=None,
... streamwriter=None,
... streamreader=None,
... )
...
py> codecs.register(getregentry)
py> u'unicode text'.encode('null')
u'unicode text'
so the documentation is correct, and the Stackoverflow answer is not. |
|
Date |
User |
Action |
Args |
2018-12-20 10:18:44 | steven.daprano | set | recipients:
+ steven.daprano, lemburg, vstinner, ezio.melotti, serhiy.storchaka, radiocane |
2018-12-20 10:18:44 | steven.daprano | set | messageid: <1545301124.81.0.788709270274.issue35544@psf.upfronthosting.co.za> |
2018-12-20 10:18:44 | steven.daprano | link | issue35544 messages |
2018-12-20 10:18:44 | steven.daprano | create | |
|