[Git][NTPsec/ntpsec][master] Clean up pyntpdig for Python 3.

Eric S. Raymond gitlab at mg.gitlab.com
Mon Nov 7 13:15:38 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
13ffd541 by Eric S. Raymond at 2016-11-07T08:15:18-05:00
Clean up pyntpdig for Python 3.

- - - - -


1 changed file:

- ntpdig/pyntpdig


Changes:

=====================================
ntpdig/pyntpdig
=====================================
--- a/ntpdig/pyntpdig
+++ b/ntpdig/pyntpdig
@@ -3,6 +3,7 @@
 ntpdig - simple SNTP client
 
 """
+# This code runs identically under Python 2 and Python 3. Keep it that way!
 from __future__ import print_function, division
 
 # This code is somewhat stripped down from the legacy C version.  It
@@ -39,7 +40,7 @@ class SNTPPacket:
     def rescale(t):
         "Scale from NTP time to POSIX time"
         # Note: assumes we're in the same NTP era as the transmitter...
-        UNIX_EPOCH = 2208988800L
+        UNIX_EPOCH = 2208988800
         return (t * 2**-32) - UNIX_EPOCH 
     def __init__(self, data):
         self.hostname = None
@@ -83,8 +84,8 @@ def queryhost(server, concurrent, timeout=5, port=123):
     try:
         iptuples = socket.getaddrinfo(server, 123,
                                       af, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
-    except socket.gaierror as (errno, msg):
-        log("lookup of %s failed, errno %d = %s" % (server, errno, msg))
+    except socket.gaierror as e:
+        log("lookup of %s failed, errno %d = %s" % (server, e[0], e[1]))
         return []
     sockets = []
     packets = []
@@ -92,7 +93,7 @@ def queryhost(server, concurrent, timeout=5, port=123):
         if debug:
             log("querying %s (%s)" % (sockaddr[0], server))
         s = socket.socket(family, socktype)
-        d = '\xe3' + '\0' * 47
+        d = b'\xe3' + b'\0' * 47
         s.sendto(d, sockaddr)
         def read_append(s, packets):
             d, a = s.recvfrom(1024)



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/13ffd541a17fbd06e44cc45b04f8c897db1a2b76
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161107/4808356d/attachment.html>


More information about the vc mailing list