From 8fa9d4186596388152b0014037ba629866731c58 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Mon, 18 Jun 2018 00:50:47 +0000 Subject: [PATCH 43/54] Python 3 preparation: unichr. --- roundup/anypy/strings.py | 7 +++++++ roundup/cgi/client.py | 4 +++- roundup/dehtml.py | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/roundup/anypy/strings.py b/roundup/anypy/strings.py index 2429b3b..e3b0dd3 100644 --- a/roundup/anypy/strings.py +++ b/roundup/anypy/strings.py @@ -73,3 +73,10 @@ def is_us(s): return isinstance(s, str) else: return isinstance(s, str) or isinstance(s, unicode) + +def uchr(c): + """Return the Unicode string containing the given character.""" + if _py3: + return chr(c) + else: + return unichr(c) diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index 6a443e9..5dadb2c 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -49,6 +49,8 @@ from email.MIMEText import MIMEText from email.MIMEMultipart import MIMEMultipart import roundup.anypy.email_ +from roundup.anypy.strings import uchr + def initialiseSecurity(security): '''Create some Permissions and Roles on the security object @@ -759,7 +761,7 @@ class Client: uc = int(num[1:], 16) else: uc = int(num) - return unichr(uc) + return uchr(uc) for field_name in self.form: field = self.form[field_name] diff --git a/roundup/dehtml.py b/roundup/dehtml.py index 6682300..61eae78 100644 --- a/roundup/dehtml.py +++ b/roundup/dehtml.py @@ -1,6 +1,6 @@ from __future__ import print_function -from roundup.anypy.strings import u2s +from roundup.anypy.strings import u2s, uchr class dehtml: def __init__(self, converter): if converter == "none": @@ -70,7 +70,7 @@ class dehtml: def handle_entityref(self, name): if self._skip_data: return - c = unichr(name2codepoint[name]) + c = uchr(name2codepoint[name]) try: self.text= self.text + c except UnicodeEncodeError: -- 2.7.4