Update requests dependency, add str py2/3 compat, __repr__ definition, removed unicode2utf8 & encode static methods, update HISTORY
@ryanmcgrath Let me know if you're okay with the removal of Twython.unicode2utf8 and Twython.encode. I moved Twython.encode to _encode in helpers.py (only place being used is Twython.construct_api_url) If it's python 2 and unicode then we encode it, otherwise return the original value [ci skip]
This commit is contained in:
parent
3dbef22cee
commit
c7bce9189f
6 changed files with 27 additions and 21 deletions
|
|
@ -9,6 +9,9 @@ History
|
||||||
- Added "transparent" parameters for making requests, meaning users can pass bool values (True, False) to Twython methods and we convert your params in the background to satisfy the Twitter API. Also, file objects can now be passed seamlessly (see examples in README and in /examples dir for details)
|
- Added "transparent" parameters for making requests, meaning users can pass bool values (True, False) to Twython methods and we convert your params in the background to satisfy the Twitter API. Also, file objects can now be passed seamlessly (see examples in README and in /examples dir for details)
|
||||||
- Callback URL is optional in ``get_authentication_tokens`` to accomedate those using OOB authorization (non web clients)
|
- Callback URL is optional in ``get_authentication_tokens`` to accomedate those using OOB authorization (non web clients)
|
||||||
- Not part of the python package, but tests are now available along with Travis CI hooks
|
- Not part of the python package, but tests are now available along with Travis CI hooks
|
||||||
|
- Added ``__repr__`` definition for Twython, when calling only returning <Twython: APP_KEY>
|
||||||
|
- Removed ``Twython.unicode2utf8`` and ``Twython.encode`` methods
|
||||||
|
- Cleaned up ``Twython.construct_api_url``, uses "transparent" parameters (see 4th bullet in this version for explaination)
|
||||||
|
|
||||||
2.9.1 (2013-05-04)
|
2.9.1 (2013-05-04)
|
||||||
++++++++++++++++++
|
++++++++++++++++++
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
coverage==3.6.0
|
coverage==3.6.0
|
||||||
requests==1.2.0
|
requests==1.2.1
|
||||||
requests_oauthlib==0.3.1
|
requests_oauthlib==0.3.1
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -25,7 +25,7 @@ setup(
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
|
|
||||||
# Package dependencies.
|
# Package dependencies.
|
||||||
install_requires=['requests==1.2.0', 'requests_oauthlib==0.3.1'],
|
install_requires=['requests==1.2.1', 'requests_oauthlib==0.3.1'],
|
||||||
|
|
||||||
# Metadata for PyPI.
|
# Metadata for PyPI.
|
||||||
author='Ryan McGrath',
|
author='Ryan McGrath',
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,12 @@ if is_py2:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from cgi import parse_qsl
|
from cgi import parse_qsl
|
||||||
|
|
||||||
|
str = unicode
|
||||||
basestring = basestring
|
basestring = basestring
|
||||||
|
|
||||||
|
|
||||||
elif is_py3:
|
elif is_py3:
|
||||||
from urllib.parse import urlencode, quote_plus, parse_qsl
|
from urllib.parse import urlencode, quote_plus, parse_qsl
|
||||||
|
|
||||||
|
str = str
|
||||||
basestring = (str, bytes)
|
basestring = (str, bytes)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from .compat import basestring
|
from .compat import basestring, is_py2, str
|
||||||
|
|
||||||
|
|
||||||
def _transparent_params(_params):
|
def _transparent_params(_params):
|
||||||
|
|
@ -17,3 +17,9 @@ def _transparent_params(_params):
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
return params, files
|
return params, files
|
||||||
|
|
||||||
|
|
||||||
|
def _encode(value):
|
||||||
|
if is_py2 and isinstance(value, str):
|
||||||
|
value.encode('utf-8')
|
||||||
|
return value
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ from requests_oauthlib import OAuth1
|
||||||
|
|
||||||
from . import __version__
|
from . import __version__
|
||||||
from .advisory import TwythonDeprecationWarning
|
from .advisory import TwythonDeprecationWarning
|
||||||
from .compat import json, urlencode, parse_qsl, quote_plus
|
from .compat import json, urlencode, parse_qsl, quote_plus, str
|
||||||
from .endpoints import api_table
|
from .endpoints import api_table
|
||||||
from .exceptions import TwythonError, TwythonAuthError, TwythonRateLimitError
|
from .exceptions import TwythonError, TwythonAuthError, TwythonRateLimitError
|
||||||
from .helpers import _transparent_params
|
from .helpers import _encode, _transparent_params
|
||||||
|
|
||||||
warnings.simplefilter('always', TwythonDeprecationWarning) # For Python 2.7 >
|
warnings.simplefilter('always', TwythonDeprecationWarning) # For Python 2.7 >
|
||||||
|
|
||||||
|
|
@ -106,6 +106,9 @@ class Twython(object):
|
||||||
# create stash for last call intel
|
# create stash for last call intel
|
||||||
self._last_call = None
|
self._last_call = None
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<Twython: %s>' % (self.app_key)
|
||||||
|
|
||||||
def _constructFunc(self, api_call, deprecated_key, **kwargs):
|
def _constructFunc(self, api_call, deprecated_key, **kwargs):
|
||||||
# Go through and replace any mustaches that are in our API url.
|
# Go through and replace any mustaches that are in our API url.
|
||||||
fn = api_table[api_call]
|
fn = api_table[api_call]
|
||||||
|
|
@ -346,7 +349,14 @@ class Twython(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def construct_api_url(base_url, params):
|
def construct_api_url(base_url, params):
|
||||||
return base_url + '?' + '&'.join(['%s=%s' % (Twython.unicode2utf8(key), quote_plus(Twython.unicode2utf8(value))) for (key, value) in params.iteritems()])
|
querystring = []
|
||||||
|
params, _ = _transparent_params(params)
|
||||||
|
params = requests.utils.to_key_val_list(params)
|
||||||
|
for (k, v) in params:
|
||||||
|
querystring.append(
|
||||||
|
'%s=%s' % (_encode(k), quote_plus(_encode(v)))
|
||||||
|
)
|
||||||
|
return '%s?%s' % (base_url, '&'.join(querystring))
|
||||||
|
|
||||||
def searchGen(self, search_query, **kwargs):
|
def searchGen(self, search_query, **kwargs):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
|
|
@ -383,18 +393,3 @@ class Twython(object):
|
||||||
|
|
||||||
for tweet in self.searchGen(search_query, **kwargs):
|
for tweet in self.searchGen(search_query, **kwargs):
|
||||||
yield tweet
|
yield tweet
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def unicode2utf8(text):
|
|
||||||
try:
|
|
||||||
if isinstance(text, unicode):
|
|
||||||
text = text.encode('utf-8')
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return text
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def encode(text):
|
|
||||||
if isinstance(text, (str, unicode)):
|
|
||||||
return Twython.unicode2utf8(text)
|
|
||||||
return str(text)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue