2c0af7
From 4a0a86d84ff11337c363e0540947da136b296b70 Mon Sep 17 00:00:00 2001
2c0af7
From: Evan Hunt <each@isc.org>
2c0af7
Date: Fri, 29 Apr 2016 14:17:21 -0700
2c0af7
Subject: [PATCH] [master] more python2/3 compatibility fixes; use setup.py to
2c0af7
 install
2c0af7
2c0af7
---
2c0af7
 bin/python/Makefile.in     |  2 ++
2c0af7
 bin/python/isc/Makefile.in | 28 +++-------------------------
2c0af7
 bin/python/isc/__init__.py |  6 ++++--
2c0af7
 bin/python/isc/checkds.py  |  5 +++--
2c0af7
 bin/python/isc/coverage.py |  7 +++----
2c0af7
 bin/python/isc/dnskey.py   |  4 ++--
2c0af7
 bin/python/isc/keymgr.py   |  7 +++----
2c0af7
 bin/python/isc/policy.py   |  6 +++++-
2c0af7
 bin/python/setup.py        |  8 ++++++++
2c0af7
 9 files changed, 33 insertions(+), 40 deletions(-)
2c0af7
 create mode 100644 bin/python/setup.py
2c0af7
2c0af7
diff --git a/bin/python/Makefile.in b/bin/python/Makefile.in
2c0af7
index 1e4af9c2e2..7ef32cc59b 100644
2c0af7
--- a/bin/python/Makefile.in
2c0af7
+++ b/bin/python/Makefile.in
2c0af7
@@ -55,9 +55,11 @@ install:: ${TARGETS} installdirs
2c0af7
 	${INSTALL_DATA} ${srcdir}/dnssec-checkds.8 ${DESTDIR}${mandir}/man8
2c0af7
 	${INSTALL_DATA} ${srcdir}/dnssec-coverage.8 ${DESTDIR}${mandir}/man8
2c0af7
 	${INSTALL_DATA} ${srcdir}/dnssec-keymgr.8 ${DESTDIR}${mandir}/man8
2c0af7
+	test -z "${PYTHON}" || ${PYTHON} setup.py install --prefix=${DESTDIR}${prefix}
2c0af7
 
2c0af7
 clean distclean::
2c0af7
 	rm -f ${TARGETS}
2c0af7
+	rm -rf build
2c0af7
 
2c0af7
 distclean::
2c0af7
 	rm -f dnssec-checkds.py dnssec-coverage.py dnssec-keymgr.py
2c0af7
diff --git a/bin/python/isc/Makefile.in b/bin/python/isc/Makefile.in
2c0af7
index 425d054cce..a72f6e4054 100644
2c0af7
--- a/bin/python/isc/Makefile.in
2c0af7
+++ b/bin/python/isc/Makefile.in
2c0af7
@@ -24,44 +24,22 @@ PYTHON	=	@PYTHON@
2c0af7
 
2c0af7
 PYSRCS =	__init__.py dnskey.py eventlist.py keydict.py \
2c0af7
 		keyevent.py keyzone.py policy.py
2c0af7
-TARGETS =	parsetab.py parsetab.pyc \
2c0af7
-		__init__.pyc dnskey.pyc eventlist.py keydict.py \
2c0af7
-		keyevent.pyc keyzone.pyc policy.pyc
2c0af7
+TARGETS =	parsetab.py
2c0af7
 
2c0af7
 @BIND9_MAKE_RULES@
2c0af7
 
2c0af7
 %.pyc: %.py
2c0af7
 	$(PYTHON) -m compileall .
2c0af7
 
2c0af7
-parsetab.py parsetab.pyc: policy.py
2c0af7
+parsetab.py: policy.py
2c0af7
 	$(PYTHON) policy.py parse /dev/null > /dev/null
2c0af7
 	$(PYTHON) -m parsetab
2c0af7
 
2c0af7
-installdirs:
2c0af7
-	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}/isc
2c0af7
-
2c0af7
-install:: ${PYSRCS} installdirs
2c0af7
-	${INSTALL_SCRIPT} __init__.py ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} __init__.pyc ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} dnskey.py ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} dnskey.pyc ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} eventlist.py ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} eventlist.pyc ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} keydict.py ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} keydict.pyc ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} keyevent.py ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} keyevent.pyc ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} keyzone.py ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} keyzone.pyc ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} policy.py ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} policy.pyc ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} parsetab.py ${DESTDIR}${libdir}
2c0af7
-	${INSTALL_SCRIPT} parsetab.pyc ${DESTDIR}${libdir}
2c0af7
-
2c0af7
 check test: subdirs
2c0af7
 
2c0af7
 clean distclean::
2c0af7
 	rm -f *.pyc parser.out parsetab.py
2c0af7
+	rm -rf __pycache__ build
2c0af7
 
2c0af7
 distclean::
2c0af7
 	rm -Rf utils.py
2c0af7
\ No newline at end of file
2c0af7
diff --git a/bin/python/isc/__init__.py b/bin/python/isc/__init__.py
2c0af7
index 0d79f356fd..10b3c45cf1 100644
2c0af7
--- a/bin/python/isc/__init__.py
2c0af7
+++ b/bin/python/isc/__init__.py
2c0af7
@@ -13,8 +13,10 @@
2c0af7
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
2c0af7
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2c0af7
 
2c0af7
-__all__ = ['dnskey', 'eventlist', 'keydict', 'keyevent', 'keyseries',
2c0af7
-           'keyzone', 'policy', 'parsetab', 'utils']
2c0af7
+__all__ = ['checkds', 'coverage', 'keymgr', 'dnskey', 'eventlist',
2c0af7
+           'keydict', 'keyevent', 'keyseries', 'keyzone', 'policy',
2c0af7
+           'parsetab', 'utils']
2c0af7
+
2c0af7
 from isc.dnskey import *
2c0af7
 from isc.eventlist import *
2c0af7
 from isc.keydict import *
2c0af7
diff --git a/bin/python/isc/checkds.py b/bin/python/isc/checkds.py
2c0af7
index 64ca12ebc6..2b7da39fc9 100644
2c0af7
--- a/bin/python/isc/checkds.py
2c0af7
+++ b/bin/python/isc/checkds.py
2c0af7
@@ -42,7 +42,7 @@ class SECRR:
2c0af7
         if not rrtext:
2c0af7
             raise Exception
2c0af7
 
2c0af7
-        fields = rrtext.split()
2c0af7
+        fields = rrtext.decode('ascii').split()
2c0af7
         if len(fields) < 7:
2c0af7
             raise Exception
2c0af7
 
2c0af7
@@ -75,7 +75,8 @@ class SECRR:
2c0af7
             fields = fields[2:]
2c0af7
 
2c0af7
         if fields[0].upper() != self.rrtype:
2c0af7
-            raise Exception
2c0af7
+            raise Exception('%s does not match %s' %
2c0af7
+                            (fields[0].upper(), self.rrtype))
2c0af7
 
2c0af7
         self.keyid, self.keyalg, self.hashalg = map(int, fields[1:4])
2c0af7
         self.digest = ''.join(fields[4:]).upper()
2c0af7
diff --git a/bin/python/isc/coverage.py b/bin/python/isc/coverage.py
2c0af7
index c9e89596f7..bfe811bee8 100644
2c0af7
--- a/bin/python/isc/coverage.py
2c0af7
+++ b/bin/python/isc/coverage.py
2c0af7
@@ -27,9 +27,7 @@ from collections import defaultdict
2c0af7
 
2c0af7
 prog = 'dnssec-coverage'
2c0af7
 
2c0af7
-from isc import *
2c0af7
-from isc.utils import prefix
2c0af7
-
2c0af7
+from isc import dnskey, eventlist, keydict, keyevent, keyzone, utils
2c0af7
 
2c0af7
 ############################################################################
2c0af7
 # print a fatal error and exit
2c0af7
@@ -139,7 +137,8 @@ def set_path(command, default=None):
2c0af7
 def parse_args():
2c0af7
     """Read command line arguments, set global 'args' structure"""
2c0af7
     compilezone = set_path('named-compilezone',
2c0af7
-                           os.path.join(prefix('sbin'), 'named-compilezone'))
2c0af7
+                           os.path.join(utils.prefix('sbin'),
2c0af7
+                           'named-compilezone'))
2c0af7
 
2c0af7
     parser = argparse.ArgumentParser(description=prog + ': checks future ' +
2c0af7
                                      'DNSKEY coverage for a zone')
2c0af7
diff --git a/bin/python/isc/dnskey.py b/bin/python/isc/dnskey.py
2c0af7
index f1559e7239..14079504b6 100644
2c0af7
--- a/bin/python/isc/dnskey.py
2c0af7
+++ b/bin/python/isc/dnskey.py
2c0af7
@@ -205,11 +205,11 @@ class dnskey:
2c0af7
             raise Exception('unable to generate key: ' + str(stderr))
2c0af7
 
2c0af7
         try:
2c0af7
-            keystr = stdout.splitlines()[0]
2c0af7
+            keystr = stdout.splitlines()[0].decode('ascii')
2c0af7
             newkey = dnskey(keystr, keys_dir, ttl)
2c0af7
             return newkey
2c0af7
         except Exception as e:
2c0af7
-            raise Exception('unable to generate key: %s' % str(e))
2c0af7
+            raise Exception('unable to parse generated key: %s' % str(e))
2c0af7
 
2c0af7
     def generate_successor(self, keygen_bin, **kwargs):
2c0af7
         quiet = kwargs.get('quiet', False)
2c0af7
diff --git a/bin/python/isc/keymgr.py b/bin/python/isc/keymgr.py
2c0af7
index a3a9043965..cbe86ab65e 100644
2c0af7
--- a/bin/python/isc/keymgr.py
2c0af7
+++ b/bin/python/isc/keymgr.py
2c0af7
@@ -20,8 +20,7 @@ from collections import defaultdict
2c0af7
 
2c0af7
 prog='dnssec-keymgr'
2c0af7
 
2c0af7
-from isc import *
2c0af7
-from isc.utils import prefix
2c0af7
+from isc import dnskey, keydict, keyseries, policy, parsetab, utils
2c0af7
 
2c0af7
 ############################################################################
2c0af7
 # print a fatal error and exit
2c0af7
@@ -63,9 +62,9 @@ def parse_args():
2c0af7
     """
2c0af7
 
2c0af7
     keygen = set_path('dnssec-keygen',
2c0af7
-                      os.path.join(prefix('sbin'), 'dnssec-keygen'))
2c0af7
+                      os.path.join(utils.prefix('sbin'), 'dnssec-keygen'))
2c0af7
     settime = set_path('dnssec-settime',
2c0af7
-                       os.path.join(prefix('sbin'), 'dnssec-settime'))
2c0af7
+                       os.path.join(utils.prefix('sbin'), 'dnssec-settime'))
2c0af7
 
2c0af7
     parser = argparse.ArgumentParser(description=prog + ': schedule '
2c0af7
                                      'DNSSEC key rollovers according to a '
2c0af7
diff --git a/bin/python/isc/policy.py b/bin/python/isc/policy.py
2c0af7
index ed106c6c92..dbb4abf010 100644
2c0af7
--- a/bin/python/isc/policy.py
2c0af7
+++ b/bin/python/isc/policy.py
2c0af7
@@ -104,8 +104,12 @@ class PolicyLex:
2c0af7
         t.lexer.skip(1)
2c0af7
 
2c0af7
     def __init__(self, **kwargs):
2c0af7
+        if 'maketrans' in dir(str):
2c0af7
+            trans = str.maketrans('_', '-')
2c0af7
+        else:
2c0af7
+            trans = maketrans('_', '-')
2c0af7
         for r in self.reserved:
2c0af7
-            self.reserved_map[r.lower().translate(maketrans('_', '-'))] = r
2c0af7
+            self.reserved_map[r.lower().translate(trans)] = r
2c0af7
         self.lexer = lex.lex(object=self, **kwargs)
2c0af7
 
2c0af7
     def test(self, text):
2c0af7
diff --git a/bin/python/setup.py b/bin/python/setup.py
2c0af7
new file mode 100644
2c0af7
index 0000000000..d7ea4a4d41
2c0af7
--- /dev/null
2c0af7
+++ b/bin/python/setup.py
2c0af7
@@ -0,0 +1,8 @@
2c0af7
+from distutils.core import setup
2c0af7
+setup(name='isc',
2c0af7
+      version='2.0',
2c0af7
+      description='Python functions to support BIND utilities',
2c0af7
+      url='https://www.isc.org/bind',
2c0af7
+      author='Internet Systems Consortium, Inc',
2c0af7
+      license='ISC',
2c0af7
+      packages=['isc'])
2c0af7
-- 
2c0af7
2.14.3
2c0af7