mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
remove string.maketrans
This commit is contained in:
parent
41a5750656
commit
5a6deb4cae
2 changed files with 2 additions and 22 deletions
|
@ -40,28 +40,6 @@ def capwords(s, sep=None):
|
||||||
return (sep or ' ').join([x.capitalize() for x in s.split(sep)])
|
return (sep or ' ').join([x.capitalize() for x in s.split(sep)])
|
||||||
|
|
||||||
|
|
||||||
# Construct a translation map for bytes.translate
|
|
||||||
def maketrans(frm: bytes, to: bytes) -> bytes:
|
|
||||||
"""maketrans(frm, to) -> bytes
|
|
||||||
|
|
||||||
Return a translation table (a bytes object of length 256)
|
|
||||||
suitable for use in bytes.translate where each byte in frm is
|
|
||||||
mapped to the byte at the same position in to.
|
|
||||||
The strings frm and to must be of the same length.
|
|
||||||
"""
|
|
||||||
import warnings
|
|
||||||
warnings.warn("string.maketrans is deprecated, use bytes.maketrans instead",
|
|
||||||
DeprecationWarning, 2)
|
|
||||||
if len(frm) != len(to):
|
|
||||||
raise ValueError("maketrans arguments must have same length")
|
|
||||||
if not (isinstance(frm, bytes) and isinstance(to, bytes)):
|
|
||||||
raise TypeError("maketrans arguments must be bytes objects")
|
|
||||||
L = bytearray(range(256))
|
|
||||||
for i, c in enumerate(frm):
|
|
||||||
L[c] = to[i]
|
|
||||||
return bytes(L)
|
|
||||||
|
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
import re as _re
|
import re as _re
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- The deprecated function string.maketrans has been removed.
|
||||||
|
|
||||||
Build
|
Build
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue