[Git][NTPsec/ntpsec][master] 2 commits: ntpq: no need to translate input, all input is ascii.

Gary E. Miller gitlab at mg.gitlab.com
Thu Sep 28 17:52:27 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
a4be59c3 by Gary E. Miller at 2017-09-28T10:48:03-07:00
ntpq: no need  to translate input, all input is ascii.

- - - - -
8fc9b771 by Gary E. Miller at 2017-09-28T10:51:32-07:00
ntpwait: remove unused/unneeded UTF-8 stuff.

ntpwait never read stdin.  ntpwait only output ascii.

- - - - -


2 changed files:

- ntpclients/ntpq
- ntpclients/ntpwait


Changes:

=====================================
ntpclients/ntpq
=====================================
--- a/ntpclients/ntpq
+++ b/ntpclients/ntpq
@@ -105,8 +105,6 @@ else:  # Python 3
         return io.TextIOWrapper(stream.buffer, encoding=master_encoding,
                                 newline="\n", line_buffering=True)
 
-    if sys.stdin.encoding == "ascii":
-        sys.stdin = make_std_wrapper(sys.stdin)
     if sys.stdout.encoding == "ascii":
         sys.stdout = make_std_wrapper(sys.stdout)
     if sys.stderr.encoding == "ascii":


=====================================
ntpclients/ntpwait
=====================================
--- a/ntpclients/ntpwait
+++ b/ntpclients/ntpwait
@@ -29,78 +29,6 @@ import ntp.magic
 import ntp.packet
 import ntp.util
 
-# General notes on Python 2/3 compatibility:
-#
-# This code uses the following strategy to allow it to run on both Python 2
-# and Python 3:
-#
-# - Use binary I/O to read/write data from/to files and subprocesses;
-#   where the exact bytes are important (such as in checking for
-#   modified files), use the binary data directly
-#
-# - Use latin-1 encoding to transform binary data to/from Unicode when
-#   necessary for operations where Python 3 expects Unicode; the
-#   polystr and polybytes functions are used to do this so that
-#   when running on Python 2, the byte string data is used unchanged.
-#
-# - Construct custom stdin, stdout, and stderr streams when running
-#   on Python 3 that force latin-1 encoding, and wrap them around the
-#   underlying binary buffers (in Python 2, the streams are binary
-#   and are used unchanged); this ensures that the same transformation
-#   is done on data from/to the standard streams, as is done on binary
-#   data from/to files and subprocesses; the make_std_wrapper function
-#   does this
-
-master_encoding = 'latin-1'
-
-if str is bytes:  # Python 2
-    polystr = str
-    polybytes = bytes
-
-    def string_escape(s):
-        return s.decode('string_escape')
-
-else:  # Python 3
-    import io
-
-    def polystr(o):
-        "Polymorphic string factory function"
-        if isinstance(o, str):
-            return o
-        if not isinstance(o, bytes):
-            return str(o)
-        return str(o, encoding=master_encoding)
-
-    def polybytes(s):
-        "Polymorphic string encoding function"
-        if isinstance(s, bytes):
-            return s
-        if not isinstance(s, str):
-            return bytes(s)
-        return bytes(s, encoding=master_encoding)
-
-    def string_escape(s):
-        "Polymorphic string_escape/unicode_escape"
-        # This hack is necessary because Unicode strings in Python 3 don't
-        # have a decode method, so there's no simple way to ask it for the
-        # equivalent of decode('string_escape') in Python 2. This function
-        # assumes that it will be called with a Python 3 'str' instance
-        return s.encode(master_encoding).decode('unicode_escape')
-
-    def make_std_wrapper(stream):
-        "Standard input/output wrapper factory function"
-        # This ensures that the encoding of standard output and standard
-        # error on Python 3 matches the master encoding we use to turn
-        # bytes to Unicode in polystr above
-        # line_buffering=True ensures that interactive command sessions
-        # work as expected
-        return io.TextIOWrapper(stream.buffer, encoding=master_encoding,
-                                newline="\n", line_buffering=True)
-
-    sys.stdin = make_std_wrapper(sys.stdin)
-    sys.stdout = make_std_wrapper(sys.stdout)
-    sys.stderr = make_std_wrapper(sys.stderr)
-
 
 class Unbuffered(object):
     def __init__(self, stream):



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/f076d070f9501baace6591a22dcfef9c85b8b259...8fc9b771ecb9ab86ed3592e1b6a07f3db6fd3915

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/f076d070f9501baace6591a22dcfef9c85b8b259...8fc9b771ecb9ab86ed3592e1b6a07f3db6fd3915
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170928/0f2c3abc/attachment.html>


More information about the vc mailing list