diff options
author | Georg Brandl <georg@python.org> | 2009-04-12 15:51:51 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-04-12 15:51:51 (GMT) |
commit | abc387747dc573e05a4b31387797a0272062b2ef (patch) | |
tree | c12c0a0e45cb06edb87798a7831b1c8f79033015 /Lib/test/test_bigmem.py | |
parent | 78532baeabc4234e3894c775f2bb7e0a21c12e0e (diff) | |
download | cpython-abc387747dc573e05a4b31387797a0272062b2ef.zip cpython-abc387747dc573e05a4b31387797a0272062b2ef.tar.gz cpython-abc387747dc573e05a4b31387797a0272062b2ef.tar.bz2 |
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
string.maketrans() which actually works on bytes. (Also closes #5675.)
Diffstat (limited to 'Lib/test/test_bigmem.py')
-rw-r--r-- | Lib/test/test_bigmem.py | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/Lib/test/test_bigmem.py b/Lib/test/test_bigmem.py index 7896748..091893e 100644 --- a/Lib/test/test_bigmem.py +++ b/Lib/test/test_bigmem.py @@ -418,18 +418,15 @@ class BaseStrTest: @bigmemtest(minsize=_2G, memuse=2) def test_translate(self, size): _ = self.from_latin1 - trans = { - ord(_('.')): _('-'), - ord(_('a')): _('!'), - ord(_('Z')): _('$'), - } SUBSTR = _('aZz.z.Aaz.') - if not isinstance(SUBSTR, str): - # Workaround the inexistence of bytes.maketrans() - chars = bytearray(range(256)) - for k, v in trans.items(): - chars[k] = ord(v) - trans = chars + if isinstance(SUBSTR, str): + trans = { + ord(_('.')): _('-'), + ord(_('a')): _('!'), + ord(_('Z')): _('$'), + } + else: + trans = bytes.maketrans(b'.aZ', b'-!$') sublen = len(SUBSTR) repeats = size // sublen + 2 s = SUBSTR * repeats |