diff options
Diffstat (limited to 'Lib/fontTools/misc/py23.py')
-rw-r--r-- | Lib/fontTools/misc/py23.py | 58 |
1 files changed, 3 insertions, 55 deletions
diff --git a/Lib/fontTools/misc/py23.py b/Lib/fontTools/misc/py23.py index 9096e2ef..29f634d6 100644 --- a/Lib/fontTools/misc/py23.py +++ b/Lib/fontTools/misc/py23.py @@ -8,6 +8,8 @@ from io import BytesIO from io import StringIO as UnicodeIO from types import SimpleNamespace +from .textTools import Tag, bytechr, byteord, bytesjoin, strjoin, tobytes, tostr + warnings.warn( "The py23 module has been deprecated and will be removed in a future release. " "Please update your code.", @@ -57,61 +59,7 @@ unichr = chr unicode = str zip = zip - -def bytechr(n): - return bytes([n]) - - -def byteord(c): - return c if isinstance(c, int) else ord(c) - - -def strjoin(iterable, joiner=""): - return tostr(joiner).join(iterable) - - -def tobytes(s, encoding="ascii", errors="strict"): - if not isinstance(s, bytes): - return s.encode(encoding, errors) - else: - return s - - -def tounicode(s, encoding="ascii", errors="strict"): - if not isinstance(s, unicode): - return s.decode(encoding, errors) - else: - return s - - -tostr = tounicode - - -class Tag(str): - @staticmethod - def transcode(blob): - if isinstance(blob, bytes): - blob = blob.decode("latin-1") - return blob - - def __new__(self, content): - return str.__new__(self, self.transcode(content)) - - def __ne__(self, other): - return not self.__eq__(other) - - def __eq__(self, other): - return str.__eq__(self, self.transcode(other)) - - def __hash__(self): - return str.__hash__(self) - - def tobytes(self): - return self.encode("latin-1") - - -def bytesjoin(iterable, joiner=b""): - return tobytes(joiner).join(tobytes(item) for item in iterable) +tounicode = tostr def xrange(*args, **kwargs): |