Skip to content

Update support for Python 2.6+ #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

This code was originally forked from [Leah Culver and Andy Smith's oauth.py code](http://github.com/leah/python-oauth/). Some of the tests come from a [fork by Vic Fryzel](http://github.com/shellsage/python-oauth), while a revamped Request class and more tests were merged in from [Mark Paschal's fork](http://github.com/markpasc/python-oauth). A number of notable differences exist between this code and its forefathers:

* Compatible with Python 2.6 and up.
* 100% unit test coverage.
* The <code>DataStore</code> object has been completely ripped out. While creating unit tests for the library I found several substantial bugs with the implementation and confirmed with Andy Smith that it was never fully baked.
* Classes are no longer prefixed with <code>OAuth</code>.
* The <code>Request</code> class now extends from <code>dict</code>.
* The library is likely no longer compatible with Python 2.3.
* The <code>Client</code> class works and extends from <code>httplib2</code>. It's a thin wrapper that handles automatically signing any normal HTTP request you might wish to make.

# Signing a Request
Expand Down
23 changes: 6 additions & 17 deletions oauth2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,8 @@
import binascii
import httplib2

try:
from urlparse import parse_qs
parse_qs # placate pyflakes
except ImportError:
# fall back for Python 2.5
from cgi import parse_qs

try:
from hashlib import sha1
sha = sha1
except ImportError:
# hashlib was added in Python 2.5
import sha
from urlparse import parse_qs
from hashlib import sha1 as sha

import _version

Expand Down Expand Up @@ -102,7 +91,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

Expand Down Expand Up @@ -131,7 +120,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:
Expand All @@ -147,7 +136,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:
Expand Down Expand Up @@ -460,7 +449,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)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • E501 line too long (114 > 79 characters)

else:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ 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!!!!'
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):
Expand Down Expand Up @@ -286,7 +286,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):
Expand Down