Skip to content

Commit

Permalink
Critical bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhelmick committed May 14, 2012
1 parent 30c6159 commit a4e3af1
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions twython/twython.py
Expand Up @@ -125,11 +125,11 @@ def __init__(self, app_key=None, app_secret=None, oauth_token=None, oauth_token_
# Enforce unicode on keys and secrets # Enforce unicode on keys and secrets
self.app_key = None self.app_key = None
if app_key is not None or twitter_token is not None: if app_key is not None or twitter_token is not None:
self.app_key = u'%s' % app_key or twitter_token self.app_key = u'%s' % (app_key or twitter_token)


self.app_secret = None self.app_secret = None
if app_secret is not None or twitter_secret is not None: if app_secret is not None or twitter_secret is not None:
self.app_secret = u'%s' % app_secret or twitter_secret self.app_secret = u'%s' % (app_secret or twitter_secret)


self.oauth_token = None self.oauth_token = None
if oauth_token is not None: if oauth_token is not None:
Expand All @@ -139,8 +139,6 @@ def __init__(self, app_key=None, app_secret=None, oauth_token=None, oauth_token_
if oauth_token_secret is not None: if oauth_token_secret is not None:
self.oauth_secret = u'%s' % oauth_token_secret self.oauth_secret = u'%s' % oauth_token_secret


print type(self.app_key), type(self.app_secret), type(self.oauth_token), type(self.oauth_secret)

self.callback_url = callback_url self.callback_url = callback_url


# If there's headers, set them, otherwise be an embarassing parent for their own good. # If there's headers, set them, otherwise be an embarassing parent for their own good.
Expand Down Expand Up @@ -191,7 +189,7 @@ def _constructFunc(self, api_call, **kwargs):


return content return content


def _request(self, url, method='GET', params=None, files=None, api_call=None): def _request(self, url, method='GET', params=None, api_call=None):
'''Internal response generator, no sense in repeating the same '''Internal response generator, no sense in repeating the same
code twice, right? ;) code twice, right? ;)
''' '''
Expand All @@ -204,7 +202,7 @@ def _request(self, url, method='GET', params=None, files=None, api_call=None):
myargs = params myargs = params


func = getattr(self.client, method) func = getattr(self.client, method)
response = func(url, data=myargs, files=files, auth=self.auth) response = func(url, data=myargs, auth=self.auth)
content = response.content.decode('utf-8') content = response.content.decode('utf-8')


# create stash for last function intel # create stash for last function intel
Expand All @@ -224,7 +222,6 @@ def _request(self, url, method='GET', params=None, files=None, api_call=None):
# `simplejson` will throw simplejson.decoder.JSONDecodeError # `simplejson` will throw simplejson.decoder.JSONDecodeError
# But excepting just ValueError will work with both. o.O # But excepting just ValueError will work with both. o.O
try: try:
print content
content = simplejson.loads(content) content = simplejson.loads(content)
except ValueError: except ValueError:
raise TwythonError('Response was not valid JSON, unable to decode.') raise TwythonError('Response was not valid JSON, unable to decode.')
Expand All @@ -250,7 +247,7 @@ def _request(self, url, method='GET', params=None, files=None, api_call=None):
we haven't gotten around to putting it in Twython yet. :) we haven't gotten around to putting it in Twython yet. :)
''' '''


def request(self, endpoint, method='GET', params=None, files=None, version=1): def request(self, endpoint, method='GET', params=None, version=1):
params = params or {} params = params or {}


# In case they want to pass a full Twitter URL # In case they want to pass a full Twitter URL
Expand All @@ -260,17 +257,17 @@ def request(self, endpoint, method='GET', params=None, files=None, version=1):
else: else:
url = '%s/%s.json' % (self.api_url % version, endpoint) url = '%s/%s.json' % (self.api_url % version, endpoint)


content = self._request(url, method=method, params=params, files=files, api_call=url) content = self._request(url, method=method, params=params, api_call=url)


return content return content


def get(self, endpoint, params=None, version=1): def get(self, endpoint, params=None, version=1):
params = params or {} params = params or {}
return self.request(endpoint, params=params, version=version) return self.request(endpoint, params=params, version=version)


def post(self, endpoint, params=None, files=None, version=1): def post(self, endpoint, params=None, version=1):
params = params or {} params = params or {}
return self.request(endpoint, 'POST', params=params, files=files, version=version) return self.request(endpoint, 'POST', params=params, version=version)


def delete(self, endpoint, params=None, version=1): def delete(self, endpoint, params=None, version=1):
params = params or {} params = params or {}
Expand Down Expand Up @@ -643,17 +640,3 @@ def encode(text):
if isinstance(text, (str, unicode)): if isinstance(text, (str, unicode)):
return Twython.unicode2utf8(text) return Twython.unicode2utf8(text)
return str(text) return str(text)

if __name__ == '__main__':
apk = 'hoLZOOxQAdzzmQEH4KoZ2A'
aps = 'IUgE3lIPVoaacV0O2o8GTYHSyoKdFIsERbBBRNEk'
ot = '142832463-Nlu6m5iBWIus8tTSr5ewoxAdf6AWyxfvYcbeTlaO'
ots = '9PVW2xz2xSeHY8VhVvtV9ph9LHgRQva1KAjKNVg2VpQ'

t = Twython(app_key=apk,
app_secret=aps,
oauth_token=ot,
oauth_token_secret=ots)

file_ = '/Users/michaelhelmick/Dropbox/Avatars/avvy1004112.jpg'
print t.updateStatusWithMedia(file_, params={'status':'TESTING STfasdfssfdFF OUTTT !!!'})

0 comments on commit a4e3af1

Please sign in to comment.