Skip to content

Commit 9c4d028

Browse files
committed
Add bytes.maketrans() method (issue #51)
1 parent 51d09cb commit 9c4d028

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

future/types/newbytes.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from collections import Iterable
99
from numbers import Integral
10+
import string
1011

1112
from future.utils import istext, isbytes, PY3, with_metaclass
1213
from future.types import no, issubset
@@ -372,7 +373,6 @@ def strip(self, bytes_to_strip=None):
372373
"""
373374
return newbytes(super(newbytes, self).strip(bytes_to_strip))
374375

375-
@no(unicode)
376376
def lower(self):
377377
"""
378378
b.lower() -> copy of b
@@ -390,5 +390,18 @@ def upper(self):
390390
"""
391391
return newbytes(super(newbytes, self).upper())
392392

393+
@classmethod
394+
@no(unicode)
395+
def maketrans(cls, frm, to):
396+
"""
397+
B.maketrans(frm, to) -> translation table
398+
399+
Return a translation table (a bytes object of length 256) suitable
400+
for use in the bytes or bytearray translate method where each byte
401+
in frm is mapped to the byte at the same position in to.
402+
The bytes objects frm and to must be of the same length.
403+
"""
404+
return newbytes(string.maketrans(frm, to))
405+
393406

394407
__all__ = ['newbytes']

0 commit comments

Comments
 (0)