[Git][NTPsec/ntpsec][master] Address GitLab issue #164: dump_hex_printable fails on Python3
Eric S. Raymond
gitlab at mg.gitlab.com
Sun Nov 27 05:05:42 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
07cacd91 by Eric S. Raymond at 2016-11-27T00:05:31-05:00
Address GitLab issue #164: dump_hex_printable fails on Python3
- - - - -
1 changed file:
- pylib/packet.py
Changes:
=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -214,6 +214,7 @@ master_encoding = 'latin-1'
if str is bytes: # Python 2
polystr = str
polybytes = bytes
+ polyord = ord
def string_escape(s):
return s.decode('string_escape')
@@ -240,6 +241,13 @@ else: # Python 3
return bytes(s)
return bytes(s, encoding=master_encoding)
+ def polyord(c):
+ "Polymorphic ord() function"
+ if isinstance(c, str):
+ return ord(c)
+ else:
+ return c
+
def string_escape(s):
"Polymorphic string_escape/unicode_escape"
# This hack is necessary because Unicode strings in Python 3 don't
@@ -625,7 +633,7 @@ def dump_hex_printable(xdata):
i = restart
for idx in range(rowlen):
# Do not use curses.isprint(), netbsd base doesn't install curses
- if ord(xdata[i]) >= 32 and ord(xdata[i]) < 127:
+ if polyord(xdata[i]) >= 32 and polyord(xdata[i]) < 127:
sys.stdout.write(xdata[i])
else:
sys.stdout.write('.')
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/07cacd918501a5539bbea8a9bf3f86b988605faa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161127/77dbcd07/attachment.html>
More information about the vc
mailing list