Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c6ce8fba
Kaydet (Commit)
c6ce8fba
authored
Eyl 19, 2017
tarafından
Miss Islington (bot)
Kaydeden (comit)
Mariatta
Eyl 19, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[3.6] bpo-31482: Missing bytes support for random.seed() version 1 (GH-3614) (GH-3659)
(cherry picked from commit
132a7d7c
)
üst
72c05e31
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
2 deletions
+31
-2
random.py
Lib/random.py
+3
-2
test_random.py
Lib/test/test_random.py
+27
-0
2017-09-16-01-53-11.bpo-31482.39s5dS.rst
...S.d/next/Library/2017-09-16-01-53-11.bpo-31482.39s5dS.rst
+1
-0
No files found.
Lib/random.py
Dosyayı görüntüle @
c6ce8fba
...
@@ -109,9 +109,10 @@ class Random(_random.Random):
...
@@ -109,9 +109,10 @@ class Random(_random.Random):
"""
"""
if
version
==
1
and
isinstance
(
a
,
(
str
,
bytes
)):
if
version
==
1
and
isinstance
(
a
,
(
str
,
bytes
)):
a
=
a
.
decode
(
'latin-1'
)
if
isinstance
(
a
,
bytes
)
else
a
x
=
ord
(
a
[
0
])
<<
7
if
a
else
0
x
=
ord
(
a
[
0
])
<<
7
if
a
else
0
for
c
in
a
:
for
c
in
map
(
ord
,
a
)
:
x
=
((
1000003
*
x
)
^
ord
(
c
)
)
&
0xFFFFFFFFFFFFFFFF
x
=
((
1000003
*
x
)
^
c
)
&
0xFFFFFFFFFFFFFFFF
x
^=
len
(
a
)
x
^=
len
(
a
)
a
=
-
2
if
x
==
-
1
else
x
a
=
-
2
if
x
==
-
1
else
x
...
...
Lib/test/test_random.py
Dosyayı görüntüle @
c6ce8fba
...
@@ -423,6 +423,33 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase):
...
@@ -423,6 +423,33 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase):
[
'0x1.b0580f98a7dbep-1'
,
'0x1.84129978f9c1ap-1'
,
[
'0x1.b0580f98a7dbep-1'
,
'0x1.84129978f9c1ap-1'
,
'0x1.aeaa51052e978p-2'
,
'0x1.092178fb945a6p-2'
])
'0x1.aeaa51052e978p-2'
,
'0x1.092178fb945a6p-2'
])
def
test_bug_31482
(
self
):
# Verify that version 1 seeds are unaffected by hash randomization
# when the seeds are expressed as bytes rather than strings.
# The hash(b) values listed are the Python2.7 hash() values
# which were used for seeding.
self
.
gen
.
seed
(
b
'nofar'
,
version
=
1
)
# hash('nofar') == 5990528763808513177
self
.
assertEqual
([
self
.
gen
.
random
()
.
hex
()
for
i
in
range
(
4
)],
[
'0x1.8645314505ad7p-1'
,
'0x1.afb1f82e40a40p-5'
,
'0x1.2a59d2285e971p-1'
,
'0x1.56977142a7880p-6'
])
self
.
gen
.
seed
(
b
'rachel'
,
version
=
1
)
# hash('rachel') == -9091735575445484789
self
.
assertEqual
([
self
.
gen
.
random
()
.
hex
()
for
i
in
range
(
4
)],
[
'0x1.0b294cc856fcdp-1'
,
'0x1.2ad22d79e77b8p-3'
,
'0x1.3052b9c072678p-2'
,
'0x1.578f332106574p-3'
])
self
.
gen
.
seed
(
b
''
,
version
=
1
)
# hash('') == 0
self
.
assertEqual
([
self
.
gen
.
random
()
.
hex
()
for
i
in
range
(
4
)],
[
'0x1.b0580f98a7dbep-1'
,
'0x1.84129978f9c1ap-1'
,
'0x1.aeaa51052e978p-2'
,
'0x1.092178fb945a6p-2'
])
b
=
b
'
\x00\x20\x40\x60\x80\xA0\xC0\xE0\xF0
'
self
.
gen
.
seed
(
b
,
version
=
1
)
# hash(b) == 5015594239749365497
self
.
assertEqual
([
self
.
gen
.
random
()
.
hex
()
for
i
in
range
(
4
)],
[
'0x1.52c2fde444d23p-1'
,
'0x1.875174f0daea4p-2'
,
'0x1.9e9b2c50e5cd2p-1'
,
'0x1.fa57768bd321cp-2'
])
def
test_setstate_first_arg
(
self
):
def
test_setstate_first_arg
(
self
):
self
.
assertRaises
(
ValueError
,
self
.
gen
.
setstate
,
(
1
,
None
,
None
))
self
.
assertRaises
(
ValueError
,
self
.
gen
.
setstate
,
(
1
,
None
,
None
))
...
...
Misc/NEWS.d/next/Library/2017-09-16-01-53-11.bpo-31482.39s5dS.rst
0 → 100644
Dosyayı görüntüle @
c6ce8fba
``random.seed()`` now works with bytes in version=1
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