[Git][NTPsec/ntpsec][master] Address GitLab issue #197: ntpq and packet.py require python2.7+

Eric S. Raymond gitlab at mg.gitlab.com
Thu Dec 8 09:56:57 UTC 2016


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


Commits:
22ab65a6 by Eric S. Raymond at 2016-12-08T04:55:45-05:00
Address GitLab issue #197: ntpq and packet.py require python2.7+

- - - - -


3 changed files:

- ntpclients/ntpq
- pylib/packet.py
- pylib/util.py


Changes:

=====================================
ntpclients/ntpq
=====================================
--- a/ntpclients/ntpq
+++ b/ntpclients/ntpq
@@ -12,7 +12,7 @@
 from __future__ import print_function, division
 
 import os, sys, getopt, cmd, re
-import socket, hashlib, collections
+import socket, hashlib
 
 try:
     import ntp.packet
@@ -168,7 +168,7 @@ class Ntpq(cmd.Cmd):
         self.peers = []			# Data from NTP peers.
         self.debug = 0
         self.pktversion = ntp.magic.NTP_OLDVERSION + 1
-        self.uservars = collections.OrderedDict()
+        self.uservars = ntp.util.OrderedDict()
         self.ai_family = socket.AF_UNSPEC
 
     def emptyline(self):


=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -180,7 +180,7 @@ A Mode 6 packet cannot have extension fields.
 """
 # SPDX-License-Identifier: BSD-2-clause
 from __future__ import print_function, division
-import sys, socket, select, struct, collections, string
+import sys, socket, select, struct, string
 import getpass, hashlib, time
 import ntp.control
 import ntp.magic
@@ -1153,7 +1153,7 @@ class ControlSession:
                     # Yes, ntpd really does emit bare tags for empty
                     # string-valued variables.
                     items.append((pair, ""))
-        return collections.OrderedDict(items)
+        return ntp.util.OrderedDict(items)
 
     def readvar(self, associd=0, varlist=None, opcode=ntp.control.CTL_OP_READVAR):
         "Read system vars from the host as a dict, or throw an exception."


=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -412,4 +412,33 @@ class IfstatsSummary:
                 return ''
         return s
 
+try:
+    import collections
+    OrderedDict = collections.OrderedDict
+except ImportError:
+    class OrderedDict(dict):
+        "A stupid simple implementation in order to be back-portable to 2.6"
+        # This can be simple because it doesn't need to be fast.
+        # The programs that use it only have to run at human speed,
+        # and the collections are small.
+        def __init__(self, items=None):
+            dict.__init__(self)
+            self.__keys = []
+            if items:
+                for (k, v) in items:
+                    self[k] = v
+        def __setitem__(self, key, val):
+            dict.__setitem__(self, key, val)
+            self.__keys.append(key)
+        def __delitem__(self, key):
+            dict.__delitem__(self, key)
+            self.__keys.remove(key)
+        def keys(self):
+            return self.__keys
+        def items(self):
+            return tuple([(k, self[k]) for k in self.__keys])
+        def __iter__(self):
+            for key in self.__keys:
+                yield key
+
 # end



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/22ab65a6641df41ffa4e5d82e4817ee29445b999
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161208/7045011b/attachment.html>


More information about the vc mailing list