26
26
import copy
27
27
import os
28
28
import os .path
29
+ import shlex
29
30
import shutil
30
31
import signal
31
32
import socket
39
40
40
41
from k5test import _utils
41
42
42
- try :
43
- from shlex import quote as shlex_quote
44
- except ImportError :
45
- from pipes import quote as shlex_quote
46
-
47
43
48
44
_LOG = logging .getLogger (__name__ )
49
45
@@ -71,24 +67,22 @@ def _cfg_merge(cfg1, cfg2):
71
67
72
68
73
69
def _discover_path (name , default , paths ):
74
- stderr_out = getattr ( subprocess , 'DEVNULL' , subprocess . PIPE )
70
+ stderr_out = subprocess . DEVNULL
75
71
try :
76
72
path = subprocess .check_output (['which' , name ],
77
73
stderr = stderr_out ).strip ()
78
74
path = path .decode (sys .getfilesystemencoding () or
79
- sys .getdefaultencoding ())
75
+ sys .getdefaultencoding ())
80
76
_LOG .debug ("Using discovered path for {name} ({path})" .format (
81
77
name = name , path = path ))
82
78
return path
83
79
except subprocess .CalledProcessError as e :
84
80
path = paths .get (name , default )
85
- _LOG .debug ("Using default path for {name} ({path}): {err}" .format (
86
- name = name , path = path , err = e ))
81
+ _LOG .debug (f"Using default path for { name } ({ path } ): { e } " )
87
82
return path
88
83
89
84
90
- @six .add_metaclass (abc .ABCMeta )
91
- class K5Realm (object ):
85
+ class K5Realm (metaclass = abc .ABCMeta ):
92
86
"""An object representing a functional krb5 test realm."""
93
87
94
88
def __new__ (cls , * args , ** kwargs ):
@@ -104,13 +98,10 @@ def __new__(cls, *args, **kwargs):
104
98
krb5_version = krb5_version .decode (
105
99
sys .getfilesystemencoding () or sys .getdefaultencoding ())
106
100
107
- if (
108
- 'heimdal' in krb5_version .lower () or
109
- (
110
- # macOS output doesn't contain Heimdal
111
- sys .platform == 'darwin' and
112
- krb5_config == '/usr/bin/krb5-config'
113
- )
101
+ # macOS output doesn't contain Heimdal
102
+ if 'heimdal' in krb5_version .lower () or (
103
+ sys .platform == 'darwin' and
104
+ krb5_config == '/usr/bin/krb5-config'
114
105
):
115
106
provider_cls = HeimdalRealm
116
107
@@ -148,7 +139,6 @@ def __init__(self, realm='KRBTEST.COM', portbase=61000,
148
139
self .client_keytab = os .path .join (self .tmpdir , 'client_keytab' )
149
140
self .ccache = os .path .join (self .tmpdir , 'ccache' )
150
141
self .kadmin_ccache = os .path .join (self .tmpdir , 'kadmin_ccache' )
151
-
152
142
self ._kdc_proc = None
153
143
self ._kadmind_proc = None
154
144
krb5_conf_path = os .path .join (self .tmpdir , 'krb5.conf' )
@@ -159,8 +149,6 @@ def __init__(self, realm='KRBTEST.COM', portbase=61000,
159
149
160
150
self ._init_paths (** paths )
161
151
162
- self ._devnull = open (os .devnull , 'r' )
163
-
164
152
if existing is None :
165
153
self ._create_conf (_cfg_merge (self ._krb5_conf , krb5_conf ),
166
154
krb5_conf_path )
@@ -339,7 +327,7 @@ def run(self, args, env=None, input=None, expected_code=0):
339
327
if input :
340
328
infile = subprocess .PIPE
341
329
else :
342
- infile = self . _devnull
330
+ infile = subprocess . DEVNULL
343
331
344
332
proc = subprocess .Popen (args , stdin = infile , stdout = subprocess .PIPE ,
345
333
stderr = subprocess .STDOUT , env = env )
@@ -361,7 +349,7 @@ def run(self, args, env=None, input=None, expected_code=0):
361
349
return outdata
362
350
363
351
def __del__ (self ):
364
- self . _devnull . close ()
352
+ pass
365
353
366
354
def kprop_port (self ):
367
355
return self .portbase + 3
@@ -373,8 +361,8 @@ def _start_daemon(self, args, env=None, sentinel=None):
373
361
if env is None :
374
362
env = self .env
375
363
376
- stdout = subprocess .PIPE if sentinel else self . _devnull
377
- proc = subprocess .Popen (args , stdin = self . _devnull ,
364
+ stdout = subprocess .PIPE if sentinel else subprocess . DEVNULL
365
+ proc = subprocess .Popen (args , stdin = subprocess . DEVNULL ,
378
366
stdout = stdout ,
379
367
stderr = subprocess .STDOUT , env = env )
380
368
cmd = ' ' .join (args )
@@ -564,7 +552,7 @@ def run_kadmin(self, query, **keywords):
564
552
565
553
def run_kadminl (self , query , ** keywords ):
566
554
if isinstance (query , list ):
567
- query = " " .join ([shlex_quote (q ) for q in query ])
555
+ query = " " .join ([shlex . quote (q ) for q in query ])
568
556
569
557
return self .run ([self .kadmin_local , '-q' , query ], ** keywords )
570
558
@@ -597,15 +585,15 @@ def provider(self):
597
585
598
586
@property
599
587
def _default_paths (self ):
600
- basedir = '/usr/libexec '
601
- if sys .platform = = 'darwin' :
602
- basedir = '/System/Library/PrivateFrameworks/Heimdal.framework/Helpers '
588
+ base = '/System/Library/PrivateFrameworks/Heimdal.framework/Helpers '
589
+ if sys .platform ! = 'darwin' :
590
+ base = '/usr/libexec '
603
591
604
592
return [
605
- ('krb5kdc' , 'kdc' , os .path .join (basedir , 'kdc' )),
593
+ ('krb5kdc' , 'kdc' , os .path .join (base , 'kdc' )),
606
594
('kadmin' , 'kadmin' , '/usr/bin/kadmin' ),
607
595
('kadmin_local' , 'kadmin' , '/usr/bin/kadmin' ),
608
- ('kadmind' , 'kadmind' , os .path .join (basedir , 'kadmind' )),
596
+ ('kadmind' , 'kadmind' , os .path .join (base , 'kadmind' )),
609
597
('_kinit' , 'kinit' , '/usr/bin/kinit' ),
610
598
('_klist' , 'klist' , '/usr/bin/klist' ),
611
599
('_ktutil' , 'ktutil' , '/usr/bin/ktutil' ),
@@ -677,7 +665,6 @@ def extract_keytab(self, princname, keytab):
677
665
678
666
def kinit (self , princname , password = None , flags = None , verbose = True ,
679
667
** keywords ):
680
-
681
668
cmd = [self ._kinit ]
682
669
683
670
input = None
0 commit comments