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.

classification
Title: string module requires bytes type for maketrans, but calling method on regular string does not
Type: Stage:
Components: Documentation Versions: Python 3.1
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: MechPaul, benjamin.peterson, ezio.melotti, georg.brandl, rhettinger
Priority: normal Keywords:

Created on 2009-04-02 23:54 by MechPaul, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg85280 - (view) Author: (MechPaul) Date: 2009-04-02 23:54
I was making a simple Caesarian cipher when this issue came up.

#Following code here

>>> import string
>>> CAESER_SHIFT = 13
>>> TranslationTableUpper = [string.ascii_uppercase[(index +
CAESER_SHIFT) % 26] for index in range(26)]
>>> TranslationTableLower = [string.ascii_lowercase[(index +
CAESER_SHIFT) % 26] for index in range(26)]
>>> TranslationTableCipher = ''.join(TranslationTableUpper +
TranslationTableLower)
>>> TranslationTableRegular = string.ascii_uppercase[0:27] +
string.ascii_lowercase[0:27]
>>> Trans = ''.maketrans(TranslationTableCipher, TranslationTableRegular)
>>> print(Trans)
{65: 78, 66: 79, 67: 80, 68: 81, 69: 82, 70: 83, 71: 84, 72: 85, 73: 86,
74: 87, 75: 88, 76: 89, 77: 90, 78: 65, 79: 66, 80: 67, 81: 68, 82: 69,
83: 70, 84: 71, 85: 72, 86: 73, 87: 74, 88: 75, 89: 76, 90: 77, 97: 110,
98: 111, 99: 112, 100: 113, 101: 114, 102: 115, 103: 116, 104: 117, 105:
118, 106: 119, 107: 120, 108: 121, 109: 122, 110: 97, 111: 98, 112: 99,
113: 100, 114: 101, 115: 102, 116: 103, 117: 104, 118: 105, 119: 106,
120: 107, 121: 108, 122: 109}
>>> #Okay... so maketrans() is working okay when calling it on an empty
string, buuuut if called from the string module...
>>> Trans = string.maketrans(TranslationTableCipher,
TranslationTableRegular)
    Trans = string.maketrans(TranslationTableCipher,
TranslationTableRegular)
  File "D:\Python31\lib\string.py", line 55, in maketrans
    raise TypeError("maketrans arguments must be bytes objects")
TypeError: maketrans arguments must be bytes objects
msg85290 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-04-03 01:48
This seems to have been intentional. I'm assigning it to Georg since he
made the commit.
msg85904 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-04-12 15:52
This is (kind of) intentional.  string.maketrans operates on bytes, not
string objects.  However, this is quite confusing, so I added
bytes.maketrans() now in py3k, and deprecated string.maketrans(). (r71521)
msg88610 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-05-31 21:15
The bytearray.maketrans() method isn't documented yet.
msg88612 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-05-31 21:39
Should be fixed in r73086.
History
Date User Action Args
2022-04-11 14:56:47adminsetgithub: 49925
2009-05-31 21:39:03georg.brandlsetstatus: open -> closed

messages: + msg88612
2009-05-31 21:15:48rhettingersetstatus: closed -> open

nosy: + rhettinger
messages: + msg88610

components: + Documentation, - Interpreter Core
2009-04-12 15:52:02georg.brandlsetstatus: open -> closed
resolution: works for me
messages: + msg85904
2009-04-03 01:48:53benjamin.petersonsetassignee: georg.brandl

messages: + msg85290
nosy: + georg.brandl, benjamin.peterson
2009-04-03 00:24:13ezio.melottisetnosy: + ezio.melotti
2009-04-02 23:54:34MechPaulcreate