This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients ezio.melotti, lemburg, radiocane, serhiy.storchaka, steven.daprano, vstinner
Date 2018-12-20.10:18:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1545301124.81.0.788709270274.issue35544@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-12-20 10:18:44steven.dapranosetrecipients: + steven.daprano, lemburg, vstinner, ezio.melotti, serhiy.storchaka, radiocane
2018-12-20 10:18:44steven.dapranosetmessageid: <1545301124.81.0.788709270274.issue35544@psf.upfronthosting.co.za>
2018-12-20 10:18:44steven.dapranolinkissue35544 messages
2018-12-20 10:18:44steven.dapranocreate