[Git][NTPsec/ntpsec][master] Added function to replace UTF-8 units with ASCII-safe versions

Ian Bruene gitlab at mg.gitlab.com
Fri Sep 29 02:30:30 UTC 2017


Ian Bruene pushed to branch master at NTPsec / ntpsec


Commits:
65036b5f by Ian Bruene at 2017-09-28T21:28:52-05:00
Added function to replace UTF-8 units with ASCII-safe versions

- - - - -


1 changed file:

- pylib/util.py


Changes:

=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -48,15 +48,30 @@ UNIT_US = u"µs"      # micro second
 UNIT_MS = "ms"       # milli second
 UNIT_S = "s"         # second
 UNIT_KS = "ks"       # kilo seconds
-UNITS_SEC = (UNIT_NS, UNIT_US, UNIT_MS, UNIT_S, UNIT_KS)
+UNITS_SEC = [UNIT_NS, UNIT_US, UNIT_MS, UNIT_S, UNIT_KS]
 UNIT_PPT = "ppt"     # parts per trillion
 UNIT_PPB = "ppb"     # parts per billion
 UNIT_PPM = "ppm"     # parts per million
 UNIT_PPK = u"‰"      # parts per thousand
-UNITS_PPX = (UNIT_PPT, UNIT_PPB, UNIT_PPM, UNIT_PPK)
+UNITS_PPX = [UNIT_PPT, UNIT_PPB, UNIT_PPM, UNIT_PPK]
 unitgroups = (UNITS_SEC, UNITS_PPX)
 
 
+def deunicode_units():
+    "Under certain conditions it is not possible to force unicode output, "
+    "this overwrites units that contain unicode with safe versions"
+    global UNIT_US
+    global UNIT_PPK
+    # Replacement units
+    new_us = "us"
+    new_ppk = "ppk"
+    # Replace units in unit group
+    UNITS_SEC[UNITS_SEC.index(UNIT_US)] = new_us
+    UNITS_PPX[UNITS_PPX.index(UNIT_PPK)] = new_ppk
+    # Replace the units themselves
+    UNIT_US = new_us
+    UNIT_PPK = new_ppk
+
 # Variables that have units
 S_VARS = ("tai", "poll")
 MS_VARS = ("rootdelay", "rootdisp", "offset", "sys_jitter", "clk_jitter",



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/65036b5f466e164d078e663408f1910ae82155bc

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/65036b5f466e164d078e663408f1910ae82155bc
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/20170929/465d156d/attachment.html>


More information about the vc mailing list