krb5 commit: Fix Python deprecation warnings

Greg Hudson ghudson at mit.edu
Thu Oct 8 14:05:23 EDT 2020


https://github.com/krb5/krb5/commit/ad1c56d9b7dc3ce37b50cb3d72ff98513bf84073
commit ad1c56d9b7dc3ce37b50cb3d72ff98513bf84073
Author: Greg Hudson <ghudson at mit.edu>
Date:   Wed Oct 7 01:25:01 2020 -0400

    Fix Python deprecation warnings
    
    Address all warnings issued by "python -Werror::DeprecationWarning"
    in the test suite and doc build, as of Python 3.8.2.

 doc/tools/doxybuilder_types.py |    6 +++---
 src/tests/gssapi/t_s4u.py      |    2 +-
 src/tests/t_kdb.py             |    4 ++--
 src/tests/t_mkey.py            |   10 +++++-----
 src/tests/t_referral.py        |    4 ++--
 src/tests/t_sesskeynego.py     |    2 +-
 src/util/k5test.py             |   15 +++++----------
 7 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/doc/tools/doxybuilder_types.py b/doc/tools/doxybuilder_types.py
index bdab120..063ee4b 100644
--- a/doc/tools/doxybuilder_types.py
+++ b/doc/tools/doxybuilder_types.py
@@ -111,7 +111,7 @@ class DoxyTypes(object):
         # remove  macros
         t_definition = re.sub('KRB5_CALLCONV_C', '', t_definition)
         t_definition = re.sub('KRB5_CALLCONV', '', t_definition)
-        t_definition = re.sub('\*', '\\*', t_definition)
+        t_definition = re.sub(r'\*', '\\*', t_definition)
         # handle fp
         if t_type[1].find('(') >= 0:
               t_type = (t_type[0],None)
@@ -161,7 +161,7 @@ class DoxyTypes(object):
         # remove  macros
         v_definition = re.sub('KRB5_CALLCONV_C', '', v_definition)
         v_definition = re.sub('KRB5_CALLCONV', '', v_definition)
-        v_definition = re.sub('\*', '\\*', v_definition)
+        v_definition = re.sub(r'\*', '\\*', v_definition)
 
         variable_descr = {'category': 'variable',
                           'definition': v_definition,
@@ -193,7 +193,7 @@ class DoxyTypes(object):
             if prm_list is not None:
                 prm_str = prm_str.join(prm_list)
             d_signature = " %s (%s) " % (d_name , prm_str)
-            d_signature = re.sub(', \)', ')', d_signature).strip()
+            d_signature = re.sub(r', \)', ')', d_signature).strip()
 
         if len(node.xpath('./initializer')) > 0:
             len_ref = len(node.xpath('./initializer/ref'))
diff --git a/src/tests/gssapi/t_s4u.py b/src/tests/gssapi/t_s4u.py
index 67eba44..746c07f 100755
--- a/src/tests/gssapi/t_s4u.py
+++ b/src/tests/gssapi/t_s4u.py
@@ -209,7 +209,7 @@ msgs = ('Getting initial credentials for enterprise\\@abc at SREALM',
         '/Additional pre-authentication required',
         'Identified realm of client principal as UREALM',
         'Getting credentials enterprise\\@abc at UREALM -> user at SREALM',
-        'TGS reply is for enterprise\@abc at UREALM -> user at SREALM')
+        'TGS reply is for enterprise\\@abc at UREALM -> user at SREALM')
 r1.run(['./t_s4u', 'e:enterprise at abc@NOREALM', '-', r1.keytab],
        expected_trace=msgs)
 
diff --git a/src/tests/t_kdb.py b/src/tests/t_kdb.py
index de8ae9c..5211cbc 100755
--- a/src/tests/t_kdb.py
+++ b/src/tests/t_kdb.py
@@ -370,7 +370,7 @@ ldap_modify('dn: krbPrincipalName=canon at KRBTEST.COM,cn=t1,cn=krb5\n'
             'krbCanonicalName: canon at KRBTEST.COM\n')
 realm.run([kadminl, 'getprinc', 'alias'],
           expected_msg='Principal: canon at KRBTEST.COM\n')
-realm.run([kadminl, 'getprinc', 'ent\@abc'],
+realm.run([kadminl, 'getprinc', 'ent\\@abc'],
           expected_msg='Principal: canon at KRBTEST.COM\n')
 realm.run([kadminl, 'getprinc', 'canon'],
           expected_msg='Principal: canon at KRBTEST.COM\n')
@@ -424,7 +424,7 @@ realm.klist('canon at KRBTEST.COM', 'alias at KRBTEST.COM')
 
 realm.kinit('ent at abc', password('canon'), ['-E'])
 realm.run([kvno, 'alias'])
-realm.klist('ent\@abc at KRBTEST.COM', 'alias at KRBTEST.COM')
+realm.klist('ent\\@abc at KRBTEST.COM', 'alias at KRBTEST.COM')
 
 # Test client name canonicalization in non-krbtgt AS reply
 realm.kinit('alias', password('canon'), ['-C', '-S', 'kadmin/changepw'])
diff --git a/src/tests/t_mkey.py b/src/tests/t_mkey.py
index 41831fa..32f4070 100755
--- a/src/tests/t_mkey.py
+++ b/src/tests/t_mkey.py
@@ -23,7 +23,7 @@ nprincs = len(realm.run([kadminl, 'listprincs']).splitlines())
 # have an activation time, and whether the key is expected to be
 # currently active.
 list_mkeys_re = re.compile(r'^KVNO: (\d+), Enctype: (\S+), '
-                           '(Active on: [^\*]+|No activate time set)( \*)?$')
+                           r'(Active on: [^\*]+|No activate time set)( \*)?$')
 def check_mkey_list(*expected):
     # Split the output of kdb5_util list_mkeys into lines and ignore the first.
     outlines = realm.run([kdb5_util, 'list_mkeys']).splitlines()[1:]
@@ -118,13 +118,13 @@ def add_mkey(options):
 # specified) and verify the output against the expected mkvno, number
 # of updated principals, and number of already-current principals.
 mkvno_re = {False: re.compile(r'^Principals whose keys are being re-encrypted '
-                              'to master key vno (\d+) if necessary:$'),
+                              r'to master key vno (\d+) if necessary:$'),
             True: re.compile(r'^Principals whose keys WOULD BE re-encrypted '
-                             'to master key vno (\d+):$')}
+                             r'to master key vno (\d+):$')}
 count_re = {False: re.compile(r'^(\d+) principals processed: (\d+) updated, '
-                              '(\d+) already current$'),
+                              r'(\d+) already current$'),
             True: re.compile(r'^(\d+) principals processed: (\d+) would be '
-                             'updated, (\d+) already current$')}
+                             r'updated, (\d+) already current$')}
 def update_princ_encryption(dry_run, expected_mkvno, expected_updated,
                             expected_current):
     opts = ['-f', '-v']
diff --git a/src/tests/t_referral.py b/src/tests/t_referral.py
index dc56561..f427d5b 100755
--- a/src/tests/t_referral.py
+++ b/src/tests/t_referral.py
@@ -117,14 +117,14 @@ kdcconf = {'realms': {'$realm': {'database_module': 'test'}},
 r1, r2 = cross_realms(2, xtgts=(),
                       args=({'kdc_conf': kdcconf, 'create_kdb': False}, None),
                       create_host=False)
-r2.addprinc('abc\@XYZ', 'pw')
+r2.addprinc('abc\\@XYZ', 'pw')
 r1.start_kdc()
 r1.kinit('user', expected_code=1,
          expected_msg='not found in Kerberos database')
 r1.kinit('user', password('user'), ['-C'])
 r1.klist('user at KRBTEST2.COM', 'krbtgt/KRBTEST2.COM')
 r1.kinit('abc at XYZ', 'pw', ['-E'])
-r1.klist('abc\@XYZ at KRBTEST2.COM', 'krbtgt/KRBTEST2.COM')
+r1.klist('abc\\@XYZ at KRBTEST2.COM', 'krbtgt/KRBTEST2.COM')
 
 # Test that disable_encrypted_timestamp persists across client
 # referrals.  (This test relies on SPAKE not being enabled by default
diff --git a/src/tests/t_sesskeynego.py b/src/tests/t_sesskeynego.py
index 73a5536..9024aee 100755
--- a/src/tests/t_sesskeynego.py
+++ b/src/tests/t_sesskeynego.py
@@ -4,7 +4,7 @@ import re
 # Run "kvno server" with a fresh set of client tickets, then check that the
 # enctypes in the service ticket match the expected values.
 etypes_re = re.compile(r'server@[^\n]+\n\tEtype \(skey, tkt\): '
-                       '([^,]+), ([^\s]+)')
+                       r'([^,]+), ([^\s]+)')
 def test_kvno(realm, expected_skey, expected_tkt):
     realm.kinit(realm.user_princ, password('user'))
     realm.run([kvno, 'server'])
diff --git a/src/util/k5test.py b/src/util/k5test.py
index e58c9fd..10f6b0a 100644
--- a/src/util/k5test.py
+++ b/src/util/k5test.py
@@ -385,7 +385,6 @@ import socket
 import string
 import subprocess
 import sys
-import imp
 
 # Used when most things go wrong (other than programming errors) so
 # that the user sees an error message rather than a Python traceback,
@@ -601,14 +600,6 @@ def _build_env():
     return env
 
 
-def _import_runenv():
-    global buildtop
-    runenv_py = os.path.join(buildtop, 'runenv.py')
-    if not os.path.exists(runenv_py):
-        fail('You must run "make runenv.py" in %s first.' % buildtop)
-    return imp.load_source('runenv', runenv_py)
-
-
 # Merge the nested dictionaries cfg1 and cfg2 into a new dictionary.
 # cfg1 or cfg2 may be None, in which case the other is returned.  If
 # cfg2 contains keys mapped to None, the corresponding keys will be
@@ -1349,10 +1340,14 @@ _last_cmd_output = None
 buildtop = _find_buildtop()
 srctop = _find_srctop()
 plugins = os.path.join(buildtop, 'plugins')
-runenv = _import_runenv()
 hostname = socket.gethostname().lower()
 null_input = open(os.devnull, 'r')
 
+if not os.path.exists(os.path.join(buildtop, 'runenv.py')):
+    fail('You must run "make runenv.py" in %s first.' % buildtop)
+sys.path = [buildtop] + sys.path
+import runenv
+
 # A DB pass is a tuple of: name, kdc_conf.
 _dbpasses = [('db2', None)]
 if runenv.have_lmdb == 'yes':


More information about the cvs-krb5 mailing list