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
788cb529
Commit
788cb529
authored
Oct 29, 2015
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
always use os.urandom for the uuid4 algorithm (closes #25515)
parent
265cee04
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
20 deletions
+8
-20
Lib/uuid.py
Lib/uuid.py
+6
-20
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/uuid.py
View file @
788cb529
...
...
@@ -44,6 +44,8 @@ Typical usage:
UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
"""
import
os
__author__
=
'Ka-Ping Yee <ping@zesty.ca>'
RESERVED_NCS
,
RFC_4122
,
RESERVED_MICROSOFT
,
RESERVED_FUTURE
=
[
...
...
@@ -456,7 +458,7 @@ def _netbios_getnode():
# If ctypes is available, use it to find system routines for UUID generation.
# XXX This makes the module non-thread-safe!
_uuid_generate_
random
=
_uuid_generate_
time
=
_UuidCreate
=
None
_uuid_generate_time
=
_UuidCreate
=
None
try
:
import
ctypes
,
ctypes
.
util
import
sys
...
...
@@ -471,12 +473,9 @@ try:
lib
=
ctypes
.
CDLL
(
ctypes
.
util
.
find_library
(
libname
))
except
Exception
:
continue
if
hasattr
(
lib
,
'uuid_generate_random'
):
_uuid_generate_random
=
lib
.
uuid_generate_random
if
hasattr
(
lib
,
'uuid_generate_time'
):
_uuid_generate_time
=
lib
.
uuid_generate_time
if
_uuid_generate_random
is
not
None
:
break
# found everything we were looking for
break
del
_libnames
# The uuid_generate_* functions are broken on MacOS X 10.5, as noted
...
...
@@ -489,7 +488,7 @@ try:
if
sys
.
platform
==
'darwin'
:
import
os
if
int
(
os
.
uname
().
release
.
split
(
'.'
)[
0
])
>=
9
:
_uuid_generate_
random
=
_uuid_generate_
time
=
None
_uuid_generate_time
=
None
# On Windows prior to 2000, UuidCreate gives a UUID containing the
# hardware address. On Windows 2000 and later, UuidCreate makes a
...
...
@@ -600,20 +599,7 @@ def uuid3(namespace, name):
def
uuid4
():
"""Generate a random UUID."""
# When the system provides a version-4 UUID generator, use it.
if
_uuid_generate_random
:
_buffer
=
ctypes
.
create_string_buffer
(
16
)
_uuid_generate_random
(
_buffer
)
return
UUID
(
bytes
=
bytes_
(
_buffer
.
raw
))
# Otherwise, get randomness from urandom or the 'random' module.
try
:
import
os
return
UUID
(
bytes
=
os
.
urandom
(
16
),
version
=
4
)
except
Exception
:
import
random
return
UUID
(
int
=
random
.
getrandbits
(
128
),
version
=
4
)
return
UUID
(
bytes
=
os
.
urandom
(
16
),
version
=
4
)
def
uuid5
(
namespace
,
name
):
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
...
...
Misc/NEWS
View file @
788cb529
...
...
@@ -48,6 +48,8 @@ Library
-
Issue
#
25503
:
Fixed
inspect
.
getdoc
()
for
inherited
docstrings
of
properties
.
Original
patch
by
John
Mark
Vandenberg
.
-
Issue
#
25515
:
Always
use
os
.
urandom
as
a
source
of
randomness
in
uuid
.
uuid4
.
-
Issue
#
21827
:
Fixed
textwrap
.
dedent
()
for
the
case
when
largest
common
whitespace
is
a
substring
of
smallest
leading
whitespace
.
Based
on
patch
by
Robert
Li
.
...
...
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