[Python-checkins] cpython (merge 3.6 -> default): merge

raymond.hettinger python-checkins at python.org
Fri Dec 30 00:55:12 EST 2016


https://hg.python.org/cpython/rev/96b7b865c100
changeset: 105895:96b7b865c100
parent: 105893:4432cba89398
parent: 105894:0509844f38df
user: Raymond Hettinger <python at rcn.com>
date: Thu Dec 29 22:55:03 2016 -0700
summary:
 merge
files:
 Lib/secrets.py | 2 ++
 Lib/test/test_secrets.py | 1 +
 Misc/ACKS | 1 +
 3 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/Lib/secrets.py b/Lib/secrets.py
--- a/Lib/secrets.py
+++ b/Lib/secrets.py
@@ -26,6 +26,8 @@
 
 def randbelow(exclusive_upper_bound):
 """Return a random int in the range [0, n)."""
+ if exclusive_upper_bound <= 0:
+ raise ValueError("Upper bound must be positive.")
 return _sysrand._randbelow(exclusive_upper_bound)
 
 DEFAULT_ENTROPY = 32 # number of bytes to return by default
diff --git a/Lib/test/test_secrets.py b/Lib/test/test_secrets.py
--- a/Lib/test/test_secrets.py
+++ b/Lib/test/test_secrets.py
@@ -70,6 +70,7 @@
 for i in range(2, 10):
 self.assertIn(secrets.randbelow(i), range(i))
 self.assertRaises(ValueError, secrets.randbelow, 0)
+ self.assertRaises(ValueError, secrets.randbelow, -1)
 
 
 class Token_Tests(unittest.TestCase):
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -369,6 +369,7 @@
 Josip Djolonga
 Walter Dörwald
 Jaromir Dolecek
+Brendan Donegan
 Ismail Donmez
 Robert Donohue
 Marcos Donolo
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /