Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0bcbfa43
Commit
0bcbfa43
authored
Sep 26, 2019
by
Michael Felt
Committed by
Tal Einat
Sep 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-28009: Fix uuid.uuid1() and uuid.get_node() on AIX (GH-8672)
parent
9f77268f
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
177 additions
and
93 deletions
+177
-93
Lib/test/test_uuid.py
Lib/test/test_uuid.py
+50
-21
Lib/uuid.py
Lib/uuid.py
+123
-72
Misc/NEWS.d/next/Library/2018-08-04-12-26-11.bpo-28009.4JcHZb.rst
...S.d/next/Library/2018-08-04-12-26-11.bpo-28009.4JcHZb.rst
+4
-0
No files found.
Lib/test/test_uuid.py
View file @
0bcbfa43
import
unittest
.mock
import
unittest
from
test
import
support
from
test
import
support
import
builtins
import
builtins
import
contextlib
import
contextlib
...
@@ -15,7 +15,6 @@ from unittest import mock
...
@@ -15,7 +15,6 @@ from unittest import mock
py_uuid
=
support
.
import_fresh_module
(
'uuid'
,
blocked
=
[
'_uuid'
])
py_uuid
=
support
.
import_fresh_module
(
'uuid'
,
blocked
=
[
'_uuid'
])
c_uuid
=
support
.
import_fresh_module
(
'uuid'
,
fresh
=
[
'_uuid'
])
c_uuid
=
support
.
import_fresh_module
(
'uuid'
,
fresh
=
[
'_uuid'
])
def
importable
(
name
):
def
importable
(
name
):
try
:
try
:
__import__
(
name
)
__import__
(
name
)
...
@@ -459,7 +458,7 @@ class BaseTestUUID:
...
@@ -459,7 +458,7 @@ class BaseTestUUID:
# uuid.getnode to fall back on uuid._random_getnode, which will
# uuid.getnode to fall back on uuid._random_getnode, which will
# generate a valid value.
# generate a valid value.
too_large_getter
=
lambda
:
1
<<
48
too_large_getter
=
lambda
:
1
<<
48
with
unittest
.
mock
.
patch
.
multiple
(
with
mock
.
patch
.
multiple
(
self
.
uuid
,
self
.
uuid
,
_node
=
None
,
# Ignore any cached node value.
_node
=
None
,
# Ignore any cached node value.
_GETTERS
=
[
too_large_getter
],
_GETTERS
=
[
too_large_getter
],
...
@@ -538,8 +537,8 @@ class BaseTestUUID:
...
@@ -538,8 +537,8 @@ class BaseTestUUID:
f
=
self
.
uuid
.
_generate_time_safe
f
=
self
.
uuid
.
_generate_time_safe
if
f
is
None
:
if
f
is
None
:
self
.
skipTest
(
'need uuid._generate_time_safe'
)
self
.
skipTest
(
'need uuid._generate_time_safe'
)
with
unittest
.
mock
.
patch
.
object
(
self
.
uuid
,
'_generate_time_safe'
,
with
mock
.
patch
.
object
(
self
.
uuid
,
'_generate_time_safe'
,
lambda
:
(
f
()[
0
],
safe_value
)):
lambda
:
(
f
()[
0
],
safe_value
)):
yield
yield
@
unittest
.
skipUnless
(
os
.
name
==
'posix'
,
'POSIX-only test'
)
@
unittest
.
skipUnless
(
os
.
name
==
'posix'
,
'POSIX-only test'
)
...
@@ -674,27 +673,57 @@ class TestUUIDWithExtModule(BaseTestUUID, unittest.TestCase):
...
@@ -674,27 +673,57 @@ class TestUUIDWithExtModule(BaseTestUUID, unittest.TestCase):
class
BaseTestInternals
:
class
BaseTestInternals
:
_uuid
=
py_uuid
_uuid
=
py_uuid
@
unittest
.
skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_find_mac
(
self
):
def
test_find_under_heading
(
self
):
data
=
'''
\
Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll
en0 1500 link#2 fe.ad.c.1.23.4 1714807956 0 711348489 0 0
01:00:5e:00:00:01
en0 1500 192.168.129 x071 1714807956 0 711348489 0 0
224.0.0.1
en0 1500 192.168.90 x071 1714807956 0 711348489 0 0
224.0.0.1
'''
def
mock_get_command_stdout
(
command
,
args
):
return
io
.
BytesIO
(
data
.
encode
())
# The above data is from AIX - with '.' as _MAC_DELIM and strings
# shorter than 17 bytes (no leading 0). (_MAC_OMITS_LEADING_ZEROES=True)
with
mock
.
patch
.
multiple
(
self
.
uuid
,
_MAC_DELIM
=
b'.'
,
_MAC_OMITS_LEADING_ZEROES
=
True
,
_get_command_stdout
=
mock_get_command_stdout
):
mac
=
self
.
uuid
.
_find_mac_under_heading
(
command
=
'netstat'
,
args
=
'-ian'
,
heading
=
b'Address'
,
)
self
.
assertEqual
(
mac
,
0xfead0c012304
)
def
test_find_mac_near_keyword
(
self
):
# key and value are on the same line
data
=
'''
data
=
'''
fake
hwaddr
fake
Link encap:UNSPEC hwaddr 00-00
cscotun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
cscotun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
'''
'''
popen
=
unittest
.
mock
.
MagicMock
()
def
mock_get_command_stdout
(
command
,
args
):
popen
.
stdout
=
io
.
BytesIO
(
data
.
encode
())
return
io
.
BytesIO
(
data
.
encode
())
with
unittest
.
mock
.
patch
.
object
(
shutil
,
'which'
,
# The above data will only be parsed properly on non-AIX unixes.
return_value
=
'/sbin/ifconfig'
):
with
mock
.
patch
.
multiple
(
self
.
uuid
,
with
unittest
.
mock
.
patch
.
object
(
subprocess
,
'Popen'
,
_MAC_DELIM
=
b':'
,
return_value
=
popen
):
_MAC_OMITS_LEADING_ZEROES
=
False
,
mac
=
self
.
uuid
.
_find_mac
(
_get_command_stdout
=
mock_get_command_stdout
):
command
=
'ifconfig'
,
mac
=
self
.
uuid
.
_find_mac_near_keyword
(
args
=
''
,
command
=
'ifconfig'
,
hw_identifiers
=
[
b'hwaddr'
],
args
=
''
,
get_index
=
lambda
x
:
x
+
1
,
keywords
=
[
b'hwaddr'
],
)
get_word_index
=
lambda
x
:
x
+
1
,
)
self
.
assertEqual
(
mac
,
0x1234567890ab
)
self
.
assertEqual
(
mac
,
0x1234567890ab
)
...
...
Lib/uuid.py
View file @
0bcbfa43
This diff is collapsed.
Click to expand it.
Misc/NEWS.d/next/Library/2018-08-04-12-26-11.bpo-28009.4JcHZb.rst
0 → 100644
View file @
0bcbfa43
Fix uuid.getnode() on platforms with '.' as MAC Addr delimiter as well
fix for MAC Addr format that omits a leading 0 in MAC Addr values.
Currently, AIX is the only know platform with these settings.
Patch by Michael Felt.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment