[Git][NTPsec/ntpsec][master] 2 commits: OPen all files with "b" flag. For Python 3 compatibility

Gary E. Miller gitlab at mg.gitlab.com
Sat Sep 10 23:45:10 UTC 2016


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


Commits:
950d1fd9 by Gary E. Miller at 2016-09-10T16:44:54-07:00
OPen all files with "b" flag.  For Python 3 compatibility

Per the "Practical Python Porting"

- - - - -
9206f420 by Gary E. Miller at 2016-09-10T16:44:54-07:00
Run ntpviz past 2to3.  Few changes.

- - - - -


1 changed file:

- ntpstats/ntpviz


Changes:

=====================================
ntpstats/ntpviz
=====================================
--- a/ntpstats/ntpviz
+++ b/ntpstats/ntpviz
@@ -66,7 +66,7 @@ def gnuplot(template, outfile=None):
     if outfile is None:
         out = None
     else:
-        out = open(outfile, "w")
+        out = open(outfile, "wb")
     # shell=True is a security hazard
     proc = subprocess.Popen("gnuplot",
                             shell=False, bufsize=4096,
@@ -210,7 +210,7 @@ plot \\
             unit = "ppb"
             rnd = 0
 
-        percs.update({k: round( v * multiplier, rnd) for k, v in percs.items()})
+        percs.update({k: round( v * multiplier, rnd) for k, v in list(percs.items())})
         ninetynine  = percs[99]
         ninetyfive  = percs[95]
         five        = percs[5]
@@ -274,7 +274,7 @@ plot \
             else:
                 unit = "ns"
 
-        percs.update({k: round( v * multiplier, rnd) for k, v in percs.items()})
+        percs.update({k: round( v * multiplier, rnd) for k, v in list(percs.items())})
         ninetynine  = percs[99]
         ninetyfive  = percs[95]
         five        = percs[5]
@@ -364,7 +364,7 @@ plot \
                 multiplier = 1e9
 
             rnd = 3
-            percs.update({k: round(v*multiplier, rnd) for k, v in percs.items()})
+            percs.update({k: round(v*multiplier, rnd) for k, v in list(percs.items())})
             ninetynine  = percs[99]
             ninetyfive  = percs[95]
             fifty       = percs[50]
@@ -455,7 +455,7 @@ plot \
             rnd1 = 9        # round to 1 ns boxes
             boxwidth = 1e-9
 
-        percs.update({k: round(v*multiplier, rnd) for k, v in percs.items()})
+        percs.update({k: round(v*multiplier, rnd) for k, v in list(percs.items())})
         ninetynine  = percs[99]
         ninetyfive  = percs[95]
         five        = percs[5]
@@ -783,13 +783,13 @@ if __name__ == '__main__':
     # if no ntpsec favicon.ico, write one.
     ico_filename = os.path.join(outdir, "favicon.ico")
     if not os.path.lexists( ico_filename ):
-        with open( ico_filename, "w" ) as wp:
+        with open( ico_filename, "wb" ) as wp:
             wp.write(binascii.a2b_base64(ntpsec_ico))
 
     # if no ntpsec logo, write one.
     logo_filename = os.path.join(outdir, "ntpsec-logo.png")
     if not os.path.lexists( logo_filename ):
-        with open( logo_filename, "w" ) as wp:
+        with open( logo_filename, "wb" ) as wp:
             wp.write(binascii.a2b_base64(ntpsec_logo))
 
     explanations = {
@@ -882,7 +882,7 @@ at 0s. Typical 90% ranges may be: local serial GPS 200 ms; local LAN peer
     title = 'ntpviz'
     if os.path.isfile(title_f):
         try:
-            title_file = open( title_f, 'r')
+            title_file = open( title_f, 'rb')
             title = title_file.read()
         except IOError:
             pass
@@ -1012,7 +1012,7 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/">NTPsec project</a>
     header = os.path.join(outdir, "header")
     if os.path.isfile(header):
         try:
-            header_file = open( header, 'r')
+            header_file = open( header, 'rb')
             header_txt = header_file.read()
             index_buffer += '<br>\n' + header_txt + '\n'
         except IOError:
@@ -1031,7 +1031,7 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/">NTPsec project</a>
             ("peer-offsets", stats.peer_offsets_gnuplot()),
             ]
 
-        peerlist = stats.peersplit().keys()
+        peerlist = list(stats.peersplit().keys())
         # sort for output order stability
         peerlist = sorted( peerlist )
         for key in peerlist:
@@ -1066,7 +1066,7 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/">NTPsec project</a>
     footer = os.path.join(outdir, "footer")
     if os.path.isfile(footer):
         try:
-            footer_file = open( footer, 'r')
+            footer_file = open( footer, 'rb')
             footer_txt = footer_file.read()
             index_buffer += '<br>\n' + footer_txt + '\n'
         except IOError:
@@ -1074,7 +1074,7 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/">NTPsec project</a>
     index_buffer += index_trailer
 
     # and send the file buffer
-    with open(os.path.join(outdir, "index.html"), "w") as ifile:
+    with open(os.path.join(outdir, "index.html"), "wb") as ifile:
         ifile.write(index_buffer)
         ifile.close()
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/7702198c98ae627ae18d683ec3f4b831794747fd...9206f420179d216d6fbfaa6b7cce61193bcf806f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160910/cff10415/attachment.html>


More information about the vc mailing list