Get rid of uniChr

Claude Paroz <[email protected]> Thu, 30 Dec 2021 12:30:46 +0100
Newsgroups gmane.comp.python.reportlab.user
Message-ID <[email protected]>
Hi all,

Here is a patch (git-formatted, but checked it can be imported by hg 
import) that removes the uniChr alias, now that Python 2 is unsupported.

Claude
-- 
www.2xlibre.net
0001-Removed-unneeded-uniChr-alias.patch (text/x-patch, 5.2 KB)
From 9bde541e321489579da1975b6ace963ae9f7249e Mon Sep 17 00:00:00 2001
From: Claude Paroz <[email protected]>
Date: Mon, 27 Dec 2021 18:25:47 +0100
Subject: [PATCH] Removed unneeded uniChr alias

---
 src/reportlab/lib/utils.py           |  2 --
 src/reportlab/platypus/paraparser.py |  6 +++---
 tests/test_pdfbase_ttfonts.py        | 11 +++++------
 tools/pythonpoint/stdparser.py       |  6 +++---
 4 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/reportlab/lib/utils.py b/src/reportlab/lib/utils.py
index 0cb1b002..96be9ca4 100644
--- a/src/reportlab/lib/utils.py
+++ b/src/reportlab/lib/utils.py
@@ -94,8 +94,6 @@ def asUnicodeEx(v,enc='utf8'):
 def asNative(v,enc='utf8'):
     return asUnicode(v,enc=enc)
 
-uniChr = chr
-
 def int2Byte(i):
     return bytes([i])
 
diff --git a/src/reportlab/platypus/paraparser.py b/src/reportlab/platypus/paraparser.py
index 092591ea..127b9183 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, uniChr, isStr, unicodeT
+from reportlab.lib.utils import ImageReader, annotateException, encode_label, asUnicode, asBytes, isStr, unicodeT
 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
@@ -2489,7 +2489,7 @@ greeks = {
     'zwnj': u'\u200c',                            #ZERO WIDTH NON-JOINER
     }
 
-known_entities = dict([(k,uniChr(v)) for k,v in name2codepoint.items()])
+known_entities = dict([(k,chr(v)) for k,v in name2codepoint.items()])
 for k in greeks:
     if k not in known_entities:
         known_entities[k] = greeks[k]
@@ -2772,7 +2772,7 @@ class ParaParser(HTMLParser):
         except ValueError:
             self.unknown_charref(name)
             return
-        self.handle_data(uniChr(n))   #.encode('utf8'))
+        self.handle_data(chr(n))   #.encode('utf8'))
 
     def syntax_error(self,lineno,message):
         self._syntax_error(message)
diff --git a/tests/test_pdfbase_ttfonts.py b/tests/test_pdfbase_ttfonts.py
index 5594efbb..b2919bcf 100644
--- a/tests/test_pdfbase_ttfonts.py
+++ b/tests/test_pdfbase_ttfonts.py
@@ -17,11 +17,11 @@ from reportlab.pdfbase.ttfonts import TTFont, TTFontFace, TTFontFile, TTFOpenFil
                                       FF_SYMBOLIC, FF_NONSYMBOLIC, \
                                       calcChecksum, add32
 from reportlab import rl_config
-from reportlab.lib.utils import getBytesIO, uniChr, int2Byte
+from reportlab.lib.utils import getBytesIO, int2Byte
 
 def utf8(code):
     "Convert a given UCS character index into UTF-8"
-    return uniChr(code).encode('utf8')
+    return chr(code).encode('utf8')
 
 def _simple_subset_generation(fn,npages,alter=0,fonts=('Vera','VeraBI')):
     c = Canvas(outputfile(fn))
@@ -43,13 +43,12 @@ def show_all_glyphs(fn,fontName='Vera'):
     c.setFont('Helvetica', 20)
     c.drawString(72,c._pagesize[1]-30, 'Unicode TrueType Font Test %s' % fontName)
     from reportlab.pdfbase.pdfmetrics import _fonts
-    from reportlab.lib.utils import uniChr
     font = _fonts[fontName]
     doc = c._doc
     kfunc = font.face.charToGlyph.keys
     for s in sorted(list(kfunc())):
         if s<0x10000:
-            font.splitString(uniChr(s),doc)
+            font.splitString(chr(s),doc)
     state = font.state[doc]
     cn = {}
     #print('len(assignments)=%d'%  len(state.assignments))
@@ -57,7 +56,7 @@ def show_all_glyphs(fn,fontName='Vera'):
     ifunc = state.assignments.items
     for code, n in sorted(list(ifunc())):
         if code==0: nzero += 1
-        cn[n] = uniChr(code)
+        cn[n] = chr(code)
     if nzero>1: print('%s there were %d zero codes' % (fontName,nzero))
 
 
@@ -76,7 +75,7 @@ def show_all_glyphs(fn,fontName='Vera'):
             if i%32 == 0:
                 y -= 12
                 x = 72
-            c.drawString(x,y,uniChr(code))
+            c.drawString(x,y,chr(code))
             x += 13
         y -= 18
 
diff --git a/tools/pythonpoint/stdparser.py b/tools/pythonpoint/stdparser.py
index 65a1fb41..84985a1b 100644
--- a/tools/pythonpoint/stdparser.py
+++ b/tools/pythonpoint/stdparser.py
@@ -8,7 +8,7 @@ pythonpoint.py.
 """
 
 import string, imp, sys, os, copy
-from reportlab.lib.utils import isSeq, uniChr
+from reportlab.lib.utils import isSeq
 from reportlab.lib import colors
 from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
 from reportlab.lib.utils import recursiveImport
@@ -811,7 +811,7 @@ class PPMLParser(HTMLParser):
         except ValueError:
             self.unknown_charref(name)
             return
-        self.handle_data(uniChr(n).encode('utf8'))
+        self.handle_data(chr(n).encode('utf8'))
 
     #HTMLParser interface
     def handle_starttag(self, tag, attrs):
@@ -850,7 +850,7 @@ class PPMLParser(HTMLParser):
     def handle_entityref(self, name):
         "Handles a named entity.  "
         try:
-            v = uniChr(known_entities[name])
+            v = chr(known_entities[name])
         except:
             v = u'&amp;%s;' % name
         self.handle_data(v)
-- 
2.30.2