From 6b92bab0a436b0de28afdfc50d20e87066646666 Mon Sep 17 00:00:00 2001 From: Joe Stump Date: Wed, 29 Jul 2015 09:13:56 -0700 Subject: [PATCH 1/4] Lowercase scheme and authority per specification. Closes #29. --- oauth2/__init__.py | 3 ++- tests/test_oauth.py | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/oauth2/__init__.py b/oauth2/__init__.py index 6c66de1f..3b9c7417 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -368,7 +368,8 @@ def url(self, value): raise ValueError("Unsupported URL %s (%s)." % (value, scheme)) # Normalized URL excludes params, query, and fragment. - self.normalized_url = urlparse.urlunsplit((scheme, netloc, path, None, None)) + self.normalized_url = urlparse.urlunsplit((scheme.lower(), + netloc.lower(), path, None, None)) else: self.normalized_url = None self.__dict__['url'] = None diff --git a/tests/test_oauth.py b/tests/test_oauth.py index 1399c291..5e96e586 100644 --- a/tests/test_oauth.py +++ b/tests/test_oauth.py @@ -224,7 +224,7 @@ def _compare_tokens(self, new): # TODO: What about copying the verifier to the new token? # self.assertEqual(self.token.verifier, new.verifier) - def test_to_string(self): + def test_to_string_magic_method(self): tok = oauth.Token('tooken', 'seecret') self.assertEqual(str(tok), 'oauth_token_secret=seecret&oauth_token=tooken') @@ -303,6 +303,14 @@ def test_url(self): self.assertEquals(req.normalized_url, exp2) self.assertEquals(req.url, url2) + def test_url_lowercases_scheme_and_authority(self): + """Lowercase scheme and authority in URL normalization.""" + # http://oauth.net/core/1.0a/#rfc.section.9.1.2 + # https://github.com/joestump/python-oauth2/issues/29 + url = 'HTTP://Example.com/resource' + req = oauth.Request("GET", url) + self.assertEquals(req.normalized_url, "http://example.com/resource") + def test_bad_url(self): request = oauth.Request() try: From 930505a10f1340b4818a3a4c2cf0eeffd0fc3495 Mon Sep 17 00:00:00 2001 From: Joe Stump Date: Sun, 2 Aug 2015 13:55:57 -0700 Subject: [PATCH 2/4] Fixed syntax error for PT3K. --- tests/test_oauth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_oauth.py b/tests/test_oauth.py index 2adcac04..271349b7 100644 --- a/tests/test_oauth.py +++ b/tests/test_oauth.py @@ -48,7 +48,7 @@ class TestError(unittest.TestCase): def test_message(self): try: raise oauth.Error - except oauth.Error, e: + except oauth.Error as e: self.assertEqual(e.message, 'OAuth error occurred.') msg = 'OMG THINGS BROKE!!!!' From 958813bd624cf3964e1b86566a95cf63905e9d05 Mon Sep 17 00:00:00 2001 From: Joe Stump Date: Sun, 2 Aug 2015 13:58:19 -0700 Subject: [PATCH 3/4] More PT3K exception parse errors fixed. --- tests/test_oauth.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_oauth.py b/tests/test_oauth.py index 271349b7..88dd1b6f 100644 --- a/tests/test_oauth.py +++ b/tests/test_oauth.py @@ -54,13 +54,13 @@ def test_message(self): msg = 'OMG THINGS BROKE!!!!' try: raise oauth.Error(msg) - except oauth.Error, e: + except oauth.Error as e: self.assertEqual(e.message, msg) def test_str(self): try: raise oauth.Error - except oauth.Error, e: + except oauth.Error as e: self.assertEquals(str(e), 'OAuth error occurred.') class TestGenerateFunctions(unittest.TestCase): @@ -285,7 +285,7 @@ def test_deleter(self): self.fail("AttributeError should have been raised on empty url.") except AttributeError: pass - except Exception, e: + except Exception as e: self.fail(str(e)) def test_url(self): From fefce141fe610fc1721541a6d7cb07a55805e80e Mon Sep 17 00:00:00 2001 From: Joe Stump Date: Sun, 2 Aug 2015 14:03:19 -0700 Subject: [PATCH 4/4] How did PT3K support pass tests? --- oauth2/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/oauth2/__init__.py b/oauth2/__init__.py index 6a5e6877..7809e115 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -102,7 +102,7 @@ def to_unicode(s): raise TypeError('You are required to pass either unicode or string here, not: %r (%s)' % (type(s), s)) try: s = s.decode('utf-8') - except UnicodeDecodeError, le: + except UnicodeDecodeError as le: raise TypeError('You are required to pass either a unicode object or a utf-8 string here. You passed a Python string object which contained non-utf-8: %r. The UnicodeDecodeError that resulted from attempting to interpret it as utf-8 was: %s' % (s, le,)) return s @@ -131,7 +131,7 @@ def to_unicode_optional_iterator(x): try: l = list(x) - except TypeError, e: + except TypeError as e: assert 'is not iterable' in str(e) return x else: @@ -147,7 +147,7 @@ def to_utf8_optional_iterator(x): try: l = list(x) - except TypeError, e: + except TypeError as e: assert 'is not iterable' in str(e) return x else: @@ -461,7 +461,7 @@ def get_normalized_parameters(self): else: try: value = list(value) - except TypeError, e: + except TypeError as e: assert 'is not iterable' in str(e) items.append((to_utf8_if_string(key), to_utf8_if_string(value))) else: