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.
Created on 2011年12月14日 08:56 by cool-RR, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg149431 - (view) | Author: Ram Rachum (cool-RR) * | Date: 2011年12月14日 08:56 | |
The `rot_13` codec is supposed to work like this, no?
>>> 'qwerty'.encode('utf-8')
b'qwerty'
>>> 'qwerty'.encode('rot_13')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
'qwerty'.encode('rot_13')
TypeError: encoder did not return a bytes object (type=str)
>>> b'qwerty'.decode('utf-8')
'qwerty'
>>> b'qwerty'.decode('rot_13')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
b'qwerty'.decode('rot_13')
File "C:\Python32\lib\encodings\rot_13.py", line 19, in decode
return (input.translate(rot13_map), len(input))
AttributeError: 'memoryview' object has no attribute 'translate'
|
|||
| msg149434 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2011年12月14日 09:08 | |
See #7475. |
|||
| msg149436 - (view) | Author: Petri Lehtinen (petri.lehtinen) * (Python committer) | Date: 2011年12月14日 09:30 | |
Ram Rachum wrote:
> The `rot_13` codec is supposed to work like this, no?
No it isn't. In Python 3, str.encode() always encodes to bytes and bytes.decode() always decodes to str. IOW, str.encode() encodes text (Unicode) to data (bytes), and bytes.decode() decodes data to text. ROT-13 is not a character encoding, so it cannot be used in this manner.
It's still available in the codecs module, though:
>>> import codecs
>>> codecs.lookup('rot-13').encode('qwerty')
('djregl', 6)
Other text->text and bytes->bytes codecs are also available there.
|
|||
| msg149437 - (view) | Author: Ram Rachum (cool-RR) * | Date: 2011年12月14日 09:47 | |
Then I suggest replacing this error message:
encoder did not return a bytes object (type=str)
and this one:
'memoryview' object has no attribute 'translate'
With something like:
Please use `codecs.lookup('rot-13').encode`
|
|||
| msg149438 - (view) | Author: Petri Lehtinen (petri.lehtinen) * (Python committer) | Date: 2011年12月14日 10:48 | |
Issue #7475 discusses fixing the error messages, too. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:24 | admin | set | github: 57809 |
| 2011年12月14日 10:48:42 | petri.lehtinen | set | status: open -> closed superseder: codecs missing: base64 bz2 hex zlib hex_codec ... messages: + msg149438 components: + Library (Lib) resolution: duplicate stage: resolved -> |
| 2011年12月14日 09:47:55 | cool-RR | set | status: closed -> open assignee: docs@python components: + Documentation, - Library (Lib) nosy: + docs@python messages: + msg149437 resolution: not a bug -> (no value) |
| 2011年12月14日 09:30:35 | petri.lehtinen | set | status: open -> closed type: behavior nosy: + petri.lehtinen messages: + msg149436 resolution: not a bug stage: resolved |
| 2011年12月14日 09:08:07 | ezio.melotti | set | nosy:
+ ezio.melotti messages: + msg149434 |
| 2011年12月14日 08:56:36 | cool-RR | create | |