diff options
Diffstat (limited to 'oauthlib/oauth1/rfc5849/utils.py')
-rw-r--r-- | oauthlib/oauth1/rfc5849/utils.py | 44 |
1 files changed, 1 insertions, 43 deletions
diff --git a/oauthlib/oauth1/rfc5849/utils.py b/oauthlib/oauth1/rfc5849/utils.py index 6db446f..8fb0e77 100644 --- a/oauthlib/oauth1/rfc5849/utils.py +++ b/oauthlib/oauth1/rfc5849/utils.py @@ -9,9 +9,7 @@ spec. """ import string -import time import urllib2 -from random import getrandbits, choice from oauthlib.common import quote, unquote @@ -42,45 +40,6 @@ def filter_oauth_params(params): return filter(is_oauth, params) -def generate_timestamp(): - """Get seconds since epoch (UTC). - - Per `section 3.3`_ of the spec. - - .. _`section 3.3`: http://tools.ietf.org/html/rfc5849#section-3.3 - """ - return unicode(int(time.time())) - - -def generate_nonce(): - """Generate pseudorandom nonce that is unlikely to repeat. - - Per `section 3.3`_ of the spec. - - A random 64-bit number is appended to the epoch timestamp for both - randomness and to decrease the likelihood of collisions. - - .. _`section 3.3`: http://tools.ietf.org/html/rfc5849#section-3.3 - """ - return unicode(getrandbits(64)) + generate_timestamp() - - -def generate_token(length=20, chars=UNICODE_ASCII_CHARACTER_SET): - """Generates a generic OAuth token - - According to `section 2`_ of the spec, the method of token - construction is undefined. This implementation is simply a random selection - of `length` choices from `chars`. - - Credit to Ignacio Vazquez-Abrams for his excellent `Stackoverflow answer`_ - - .. _`Stackoverflow answer` : http://stackoverflow.com/questions/2257441/ - python-random-string-generation-with-upper-case-letters-and-digits - - """ - return u''.join(choice(chars) for x in range(length)) - - def escape(u): """Escape a unicode string in an OAuth-compatible fashion. @@ -118,7 +77,7 @@ def parse_keqv_list(l): encoded_list = [u.encode('utf-8') for u in l] encoded_parsed = urllib2.parse_keqv_list(encoded_list) return dict((k.decode('utf-8'), - v.decode('utf-8')) for k,v in encoded_parsed.items()) + v.decode('utf-8')) for k, v in encoded_parsed.items()) def parse_http_list(u): @@ -138,4 +97,3 @@ def parse_authorization_header(authorization_header): return parse_keqv_list(items).items() except ValueError: raise ValueError('Malformed authorization header') - |