Remove bytesT/unicodeT aliases
Claude Paroz <[email protected]> Fri, 11 Feb 2022 22:09:25 +0100
| Newsgroups | gmane.comp.python.reportlab.user |
|---|---|
| Message-ID | <[email protected]> |
Hello, Here's one more cleaning patch for reportlab. Those aliases are now unnesded on pure Python 3 code. Claude -- www.2xlibre.net
0001-Removed-bytesT-unicodeT-aliases.patch
(text/x-patch, 6.2 KB)
From c1d1a31a1363f9e3ef87e912c0e7f2162ddbab13 Mon Sep 17 00:00:00 2001 From: Claude Paroz <[email protected]> Date: Fri, 4 Feb 2022 16:46:21 +0100 Subject: [PATCH] Removed bytesT/unicodeT aliases --- src/reportlab/lib/utils.py | 2 -- src/reportlab/pdfbase/ttfonts.py | 6 +++--- src/reportlab/platypus/paragraph.py | 28 ++++++++++++++-------------- src/reportlab/platypus/paraparser.py | 2 +- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/reportlab/lib/utils.py b/src/reportlab/lib/utils.py index 00825212..f7452e6e 100644 --- a/src/reportlab/lib/utils.py +++ b/src/reportlab/lib/utils.py @@ -59,8 +59,6 @@ def isNative(v): #isBytes for bytes strings only #isUnicode for proper unicode _rl_NoneType=type(None) -bytesT = bytes -unicodeT = str strTypes = (str,bytes) def _digester(s): return md5(s if isBytes(s) else s.encode('utf8')).hexdigest() diff --git a/src/reportlab/pdfbase/ttfonts.py b/src/reportlab/pdfbase/ttfonts.py index d33c1641..f3d303d9 100644 --- a/src/reportlab/pdfbase/ttfonts.py +++ b/src/reportlab/pdfbase/ttfonts.py @@ -52,7 +52,7 @@ Canvas and TextObject have special support for dynamic fonts. """ from struct import pack, unpack, error as structError -from reportlab.lib.utils import getBytesIO, bytestr, isUnicode, char2int, bytesT, isStr, isBytes +from reportlab.lib.utils import getBytesIO, bytestr, isUnicode, char2int, isStr, isBytes from reportlab.pdfbase import pdfmetrics, pdfdoc from reportlab import rl_config from reportlab.lib.rl_accel import hex32, add32, calcChecksum, instanceStringWidthTTF @@ -394,14 +394,14 @@ class TTFontMaker: #this is used in the cmap encoding fmt==2 case CMapFmt2SubHeader = namedtuple('CMapFmt2SubHeader', 'firstCode entryCount idDelta idRangeOffset') -class TTFNameBytes(bytesT): +class TTFNameBytes(bytes): '''class used to return named strings''' def __new__(cls,b,enc='utf8'): try: ustr = b.decode(enc) except: ustr = b.decode('latin1') - self = bytesT.__new__(cls,ustr.encode('utf8')) + self = bytes.__new__(cls,ustr.encode('utf8')) self.ustr = ustr return self diff --git a/src/reportlab/platypus/paragraph.py b/src/reportlab/platypus/paragraph.py index e5b70933..373f325a 100644 --- a/src/reportlab/platypus/paragraph.py +++ b/src/reportlab/platypus/paragraph.py @@ -24,7 +24,7 @@ from copy import deepcopy from reportlab.lib.abag import ABag from reportlab.rl_config import platypus_link_underline, decimalSymbol, _FUZZ,\ paraFontSizeHeightOffset, hyphenationMinWordLength -from reportlab.lib.utils import _className, isBytes, unicodeT, bytesT, isStr +from reportlab.lib.utils import _className, isBytes, isStr from reportlab.lib.rl_accel import sameFrag import re from types import MethodType @@ -551,7 +551,7 @@ class _SplitFragLL(_SplitFragHS): """a frag that is forced to end in - because of paragraph split""" pass -class _SHYIndexedStr(unicodeT): +class _SHYIndexedStr(str): def __new__(cls, u, X=None): if not X: u = u.split(_shy) @@ -563,7 +563,7 @@ class _SHYIndexedStr(unicodeT): a(x) u = u''.join(u) X = X[:-1] - self = unicodeT.__new__(cls,u) + self = str.__new__(cls,u) self._shyIndices = X return self @@ -1162,7 +1162,7 @@ def _hyphenateFragWord(hyphenator,FW,newWidth,maxWidth,uriWasteReduce,embeddedHy return None -class _SplitWord(unicodeT): +class _SplitWord(str): pass class _SplitWordEnd(_SplitWord): @@ -1175,23 +1175,23 @@ class _SplitWordHY(_SplitWordH): '''head part of a hyphenation word pair''' pass -class _SplitWordLL(unicodeT): +class _SplitWordLL(str): '''a word that's forced to end with - because of paragraph split''' pass -class _SHYStr(unicodeT): +class _SHYStr(str): '''for simple soft hyphenated words''' def __new__(cls,s): S = s.split(_shy) if len(S)>1: - self = unicodeT.__new__(cls, u''.join(S)) + self = str.__new__(cls, u''.join(S)) sp = [0] asp = sp.append for ss in S: asp(sp[-1]+len(ss)) self.__sp__ = sp[1:-1] else: - self = unicodeT.__new__(cls, s) + self = str.__new__(cls, s) self.__sp__ = [] return self @@ -1561,11 +1561,11 @@ def textTransformFrags(frags,style): if tt: tt=tt.lower() if tt=='lowercase': - tt = unicodeT.lower + tt = str.lower elif tt=='uppercase': - tt = unicodeT.upper + tt = str.upper elif tt=='capitalize': - tt = unicodeT.title + tt = str.title elif tt=='none': return else: @@ -1574,7 +1574,7 @@ def textTransformFrags(frags,style): if n==1: #single fragment the easy case frags[0].text = tt(frags[0].text) - elif tt is unicodeT.title: + elif tt is str.title: pb = True for f in frags: u = f.text @@ -1593,10 +1593,10 @@ def textTransformFrags(frags,style): if not u: continue f.text = tt(u) -class cjkU(unicodeT): +class cjkU(str): '''simple class to hold the frag corresponding to a str''' def __new__(cls,value,frag,encoding): - self = unicodeT.__new__(cls,value) + self = str.__new__(cls,value) self._frag = frag if hasattr(frag,'cbDefn'): w = getattr(frag.cbDefn,'width',0) diff --git a/src/reportlab/platypus/paraparser.py b/src/reportlab/platypus/paraparser.py index 127b9183..8da13f56 100644 --- a/src/reportlab/platypus/paraparser.py +++ b/src/reportlab/platypus/paraparser.py @@ -15,7 +15,7 @@ import unicodedata import reportlab.lib.sequencer from reportlab.lib.abag import ABag -from reportlab.lib.utils import ImageReader, annotateException, encode_label, asUnicode, asBytes, isStr, unicodeT +from reportlab.lib.utils import ImageReader, annotateException, encode_label, asUnicode, asBytes, isStr from reportlab.lib.colors import toColor, white, black, red, Color from reportlab.lib.fonts import tt2ps, ps2tt from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY -- 2.30.2