replace utils.randombytes with os.urandom
authorShivaram Lingamneni <slingamn@cs.stanford.edu>
Wed, 2 May 2012 01:20:44 +0000 (18:20 -0700)
committerShivaram Lingamneni <slingamn@cs.stanford.edu>
Tue, 15 May 2012 22:42:03 +0000 (15:42 -0700)
requests/auth.py
requests/utils.py

index e636b72402ef8749d96ccf8d224c762b65b8582c..cb851d2cde9305df18d131146aa1bea4d9ccc792 100644 (file)
@@ -7,13 +7,14 @@ requests.auth
 This module contains the authentication handlers for Requests.
 """
 
+import os
 import time
 import hashlib
 
 from base64 import b64encode
 
 from .compat import urlparse, str
-from .utils import randombytes, parse_dict_header
+from .utils import parse_dict_header
 
 try:
     from oauthlib.oauth1.rfc5849 import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER)
@@ -192,7 +193,7 @@ class HTTPDigestAuth(AuthBase):
                 s = str(nonce_count).encode('utf-8')
                 s += nonce.encode('utf-8')
                 s += time.ctime().encode('utf-8')
-                s += randombytes(8)
+                s += os.urandom(8)
 
                 cnonce = (hashlib.sha1(s).hexdigest()[:16])
                 noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, hash_utf8(A2))
index 8365cc36999b0037e3d818ffa3ae1ac86765f3e8..e60b9c48e2dd851901c935ad4cfb9d9627bd597a 100644 (file)
@@ -12,14 +12,12 @@ that are also useful for external consumption.
 import cgi
 import codecs
 import os
-import random
 import re
 import zlib
 from netrc import netrc, NetrcParseError
 
 from .compat import parse_http_list as _parse_list_header
-from .compat import quote, is_py2, urlparse
-from .compat import basestring, bytes, str
+from .compat import quote, urlparse, basestring, bytes, str
 from .cookies import RequestsCookieJar, cookiejar_from_dict
 
 _hush_pyflakes = (RequestsCookieJar,)
@@ -248,15 +246,6 @@ def header_expand(headers):
     return ''.join(collector)
 
 
-def randombytes(n):
-    """Return n random bytes."""
-    if is_py2:
-        L = [chr(random.randrange(0, 256)) for i in range(n)]
-    else:
-        L = [chr(random.randrange(0, 256)).encode('utf-8') for i in range(n)]
-    return b"".join(L)
-
-
 def dict_from_cookiejar(cj):
     """Returns a key/value dictionary from a CookieJar.