Fix error in README.md, strip some not-needed comments and fixed a ternary
This commit is contained in:
parent
8ea61af4fc
commit
2155ae0c23
2 changed files with 14 additions and 31 deletions
|
|
@ -11,7 +11,7 @@ Features
|
||||||
- Twitter lists
|
- Twitter lists
|
||||||
- Timelines
|
- Timelines
|
||||||
- User avatar URL
|
- User avatar URL
|
||||||
- and anything found in `the docs <https://dev.twitter.com/docs/api>`_
|
- and anything found in [the docs](https://dev.twitter.com/docs/api)
|
||||||
* Image Uploading!
|
* Image Uploading!
|
||||||
- **Update user status with an image**
|
- **Update user status with an image**
|
||||||
- Change user avatar
|
- Change user avatar
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,7 @@ except ImportError:
|
||||||
# table is a file with a dictionary of every API endpoint that Twython supports.
|
# table is a file with a dictionary of every API endpoint that Twython supports.
|
||||||
from twitter_endpoints import base_url, api_table, twitter_http_status_codes
|
from twitter_endpoints import base_url, api_table, twitter_http_status_codes
|
||||||
|
|
||||||
|
|
||||||
# There are some special setups (like, oh, a Django application) where
|
|
||||||
# simplejson exists behind the scenes anyway. Past Python 2.6, this should
|
|
||||||
# never really cause any problems to begin with.
|
|
||||||
try:
|
try:
|
||||||
# If they have the library, chances are they're gonna want to use that.
|
|
||||||
import simplejson
|
import simplejson
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
|
|
@ -40,7 +35,6 @@ except ImportError:
|
||||||
import json as simplejson
|
import json as simplejson
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
# This case gets rarer by the day, but if we need to, we can pull it from Django provided it's there.
|
|
||||||
from django.utils import simplejson
|
from django.utils import simplejson
|
||||||
except:
|
except:
|
||||||
# Seriously wtf is wrong with you if you get this Exception.
|
# Seriously wtf is wrong with you if you get this Exception.
|
||||||
|
|
@ -110,21 +104,11 @@ class Twython(object):
|
||||||
self.authenticate_url = self.api_url % 'oauth/authenticate'
|
self.authenticate_url = self.api_url % 'oauth/authenticate'
|
||||||
|
|
||||||
# Enforce unicode on keys and secrets
|
# Enforce unicode on keys and secrets
|
||||||
self.app_key = None
|
self.app_key = app_key and unicode(app_key) or twitter_token and unicode(twitter_token)
|
||||||
if app_key is not None or twitter_token is not None:
|
self.app_secret = app_key and unicode(app_secret) or twitter_secret and unicode(twitter_secret)
|
||||||
self.app_key = u'%s' % (app_key or twitter_token)
|
|
||||||
|
|
||||||
self.app_secret = None
|
self.oauth_token = oauth_token and u'%s' % oauth_token
|
||||||
if app_secret is not None or twitter_secret is not None:
|
self.oauth_token_secret = oauth_token_secret and u'%s' % oauth_token_secret
|
||||||
self.app_secret = u'%s' % (app_secret or twitter_secret)
|
|
||||||
|
|
||||||
self.oauth_token = None
|
|
||||||
if oauth_token is not None:
|
|
||||||
self.oauth_token = u'%s' % oauth_token
|
|
||||||
|
|
||||||
self.oauth_token_secret = None
|
|
||||||
if oauth_token_secret is not None:
|
|
||||||
self.oauth_token_secret = u'%s' % oauth_token_secret
|
|
||||||
|
|
||||||
self.callback_url = callback_url
|
self.callback_url = callback_url
|
||||||
|
|
||||||
|
|
@ -146,8 +130,7 @@ class Twython(object):
|
||||||
signature_type='auth_header')
|
signature_type='auth_header')
|
||||||
|
|
||||||
if self.client is None:
|
if self.client is None:
|
||||||
# If they don't do authentication, but still want to request
|
# Allow unauthenticated requests to be made.
|
||||||
# unprotected resources, we need an opener.
|
|
||||||
self.client = requests.session(proxies=proxies)
|
self.client = requests.session(proxies=proxies)
|
||||||
|
|
||||||
# register available funcs to allow listing name when debugging.
|
# register available funcs to allow listing name when debugging.
|
||||||
|
|
@ -181,11 +164,16 @@ class Twython(object):
|
||||||
'''Internal response generator, no sense in repeating the same
|
'''Internal response generator, no sense in repeating the same
|
||||||
code twice, right? ;)
|
code twice, right? ;)
|
||||||
'''
|
'''
|
||||||
myargs = {}
|
|
||||||
method = method.lower()
|
method = method.lower()
|
||||||
|
if not method in ('get', 'post'):
|
||||||
|
raise TwythonError('Method must be of GET or POST')
|
||||||
|
|
||||||
params = params or {}
|
params = params or {}
|
||||||
|
|
||||||
|
# In the next release of requests after 0.13.1, we can get rid of this
|
||||||
|
# myargs variable and line 184, urlencoding the params and just
|
||||||
|
# pass params=params in the func()
|
||||||
|
myargs = {}
|
||||||
if method == 'get':
|
if method == 'get':
|
||||||
url = '%s?%s' % (url, urllib.urlencode(params))
|
url = '%s?%s' % (url, urllib.urlencode(params))
|
||||||
else:
|
else:
|
||||||
|
|
@ -207,10 +195,6 @@ class Twython(object):
|
||||||
'content': content,
|
'content': content,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Python 2.6 `json` will throw a ValueError if it
|
|
||||||
# can't load the string as valid JSON,
|
|
||||||
# `simplejson` will throw simplejson.decoder.JSONDecodeError
|
|
||||||
# But excepting just ValueError will work with both. o.O
|
|
||||||
try:
|
try:
|
||||||
content = simplejson.loads(content)
|
content = simplejson.loads(content)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
@ -458,7 +442,6 @@ class Twython(object):
|
||||||
return self._media_update(url,
|
return self._media_update(url,
|
||||||
{'image': (file_, open(file_, 'rb'))})
|
{'image': (file_, open(file_, 'rb'))})
|
||||||
|
|
||||||
# statuses/update_with_media
|
|
||||||
def updateStatusWithMedia(self, file_, version=1, **params):
|
def updateStatusWithMedia(self, file_, version=1, **params):
|
||||||
"""Updates the users status with media
|
"""Updates the users status with media
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue