Skip to content
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

use the '__iter__' attribute to determine if something is iterable vs a volatile error message #120

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

k0s
Copy link

@k0s k0s commented Sep 19, 2012

oauth2 uses the error string 'is not iterable' after try to cast to a list:

https://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py#L135

This is a fragile way of determining if something is an iterable or not. Instead, the 'iter' attribute can be checked for.

As a case in point, for python 2.4 the error message is:

list(12345)
Traceback (most recent call last):
File "", line 1, in ?
TypeError: iteration over non-sequence

See https://bugzilla.mozilla.org/show_bug.cgi?id=789972#c12 which is the motivation for this pull request

@k0s
Copy link
Author

k0s commented Sep 19, 2012

I've also added a commit that imports the sha function from the sha module for the legacy case:

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

https://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py#L46

Since we call 'sha' in oauth2, this results in

File "C:\Users\cltbld\test\talos\oauth2__init__.py", line 491, in sign_reques
t
digested = sha(self.body).digest()
TypeError: 'module' object is not callable

See https://bugzilla.mozilla.org/show_bug.cgi?id=789972#c16

@joestump
Copy link
Owner

@k0s Thanks for the PR! Can you split out 2.4 fixes from the error fix? Also, needs tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants