[Git][NTPsec/ntpsec][master] Add polychr() function and use it
Eric S. Raymond
gitlab at mg.gitlab.com
Sun Nov 27 17:56:55 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
a975e056 by Matt Selsky at 2016-11-27T12:55:24-05:00
Add polychr() function and use it
Convert an int from a byte-array to an str, as needed.
Fixes GitLab issue #164
- - - - -
1 changed file:
- pylib/packet.py
Changes:
=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -216,6 +216,7 @@ if str is bytes: # Python 2
polystr = str
polybytes = bytes
polyord = ord
+ polychr = str
def string_escape(s):
return s.decode('string_escape')
@@ -249,6 +250,13 @@ else: # Python 3
else:
return c
+ def polychr(c):
+ "Polymorphic chr() function"
+ if not isinstance(c, str):
+ return chr(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
@@ -635,7 +643,7 @@ def dump_hex_printable(xdata):
for idx in range(rowlen):
# Do not use curses.isprint(), netbsd base doesn't install curses
if polyord(xdata[i]) >= 32 and polyord(xdata[i]) < 127:
- sys.stdout.write(xdata[i])
+ sys.stdout.write(polychr(xdata[i]))
else:
sys.stdout.write('.')
i += 1
@@ -1113,7 +1121,7 @@ class ControlSession:
elif instring and c == ',':
response = response + "\xae"
elif polyord(c) > 0 and polyord(c) < 127:
- response = response + c
+ response = response + polychr(c)
response = response.rstrip()
items = []
if response:
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/a975e0560704c3697f2d91c3b1dab2339234c38c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161127/52dbf081/attachment.html>
More information about the vc
mailing list