[Git][NTPsec/ntpsec][master] Refactor unicode fallback handling
Ian Bruene
gitlab at mg.gitlab.com
Tue Jan 2 19:44:01 UTC 2018
Ian Bruene pushed to branch master at NTPsec / ntpsec
Commits:
df5d2a8b by Ian Bruene at 2018-01-02T13:43:03-06:00
Refactor unicode fallback handling
- - - - -
3 changed files:
- ntpclients/ntpmon.py
- ntpclients/ntpq.py
- pylib/util.py
Changes:
=====================================
ntpclients/ntpmon.py
=====================================
--- a/ntpclients/ntpmon.py
+++ b/ntpclients/ntpmon.py
@@ -44,11 +44,9 @@ except ImportError as e:
sys.stderr.write("%s\n" % e)
sys.exit(1)
-disableunicode = False
+
# LANG=C or LANG=POSIX refuse unicode when combined with curses
-if "UTF-8" != sys.stdout.encoding:
- ntp.util.deunicode_units()
- disableunicode = True
+disableunicode = ntp.util.check_unicode()
try:
=====================================
ntpclients/ntpq.py
=====================================
--- a/ntpclients/ntpq.py
+++ b/ntpclients/ntpq.py
@@ -70,8 +70,7 @@ if str is bytes: # Python 2
# This used to force UTF-8 encoding, but that breaks the readline system.
# Unfortunately sometimes sys.stdout.encoding lies about the encoding,
# so expect random false positives.
- if sys.stdout.encoding != "UTF-8":
- ntp.util.deunicode_units()
+ ntp.util.check_unicode()
else: # Python 3
import io
@@ -110,6 +109,7 @@ else: # Python 3
return io.TextIOWrapper(stream.buffer, encoding="utf-8",
newline="\n", line_buffering=True)
+ # This is the one situation where we *can* force unicode.
if "UTF-8" != sys.stdout.encoding:
forced_utf8 = True
sys.stdout = make_std_wrapper(sys.stdout)
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -47,6 +47,12 @@ UNITS_PPX = [UNIT_PPT, UNIT_PPB, UNIT_PPM, UNIT_PPK]
unitgroups = (UNITS_SEC, UNITS_PPX)
+def check_unicode():
+ if "UTF-8" != sys.stdout.encoding:
+ deunicode_units()
+ return True # needed by ntpmon
+ return False
+
def deunicode_units():
"Under certain conditions it is not possible to force unicode output, "
"this overwrites units that contain unicode with safe versions"
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/df5d2a8b47c35d6d43fd5586744c0a6397422a3f
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/df5d2a8b47c35d6d43fd5586744c0a6397422a3f
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/20180102/82bd1d4f/attachment.html>
More information about the vc
mailing list