Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04ab357

Browse files
miss-islingtoncsanders-gitcorona10
authored
gh-98415: Fix uuid.getnode() ifconfig implementation (GH-98423)
The uuid.getnode() function has multiple implementations, tested sequentially. The ifconfig implementation was incorrect and always failed: fix it. In practice, functions of libuuid library are preferred, if available: uuid_generate_time_safe(), uuid_create() or uuid_generate_time(). (cherry picked from commit e3ec272) Co-authored-by: Chaim Sanders <[email protected]> Co-authored-by: Dong-hee Na <[email protected]>
1 parent 46ccb35 commit 04ab357

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Lib/uuid.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,12 @@ def _get_command_stdout(command, *args):
371371
# for are actually localized, but in theory some system could do so.)
372372
env = dict(os.environ)
373373
env['LC_ALL'] = 'C'
374-
proc = subprocess.Popen((executable,) + args,
374+
# Empty strings will be quoted by popen so we should just ommit it
375+
if args != ('',):
376+
command = (executable, *args)
377+
else:
378+
command = (executable,)
379+
proc = subprocess.Popen(command,
375380
stdout=subprocess.PIPE,
376381
stderr=subprocess.DEVNULL,
377382
env=env)
@@ -511,7 +516,7 @@ def _ifconfig_getnode():
511516
mac = _find_mac_near_keyword('ifconfig', args, keywords, lambda i: i+1)
512517
if mac:
513518
return mac
514-
return None
519+
return None
515520

516521
def _ip_getnode():
517522
"""Get the hardware address on Unix by running ip."""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix detection of MAC addresses for :mod:`uuid` on certain OSs. Patch by Chaim Sanders

0 commit comments

Comments
 (0)