Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
merge conflict update
Browse files Browse the repository at this point in the history
  • Loading branch information
bear committed Jul 11, 2014
2 parents 1a28a85 + a3f8ff2 commit 1d792f4
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 101 deletions.
10 changes: 0 additions & 10 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
NOTICE

The simplejson library (http://simplejson.googlecode.com) is used under the terms of the MIT license and is copyright Bob Ippolito.
See http://simplejson.googlecode.com/svn/trunk/LICENSE.txt for details.

The python-oauth2 library (http://github.com/simplegeo/python-oauth2) is used under the terms of the MIT license and is copyright Leah Culver.
See http://github.com/simplegeo/python-oauth2/blob/master/LICENSE.txt for details.

The httplib2 library (http://code.google.com/p/httplib2) is used under the terms of the MIT license and is copyright Joe Gregorio.
See http://code.google.com/p/httplib2/source/browse/python2/httplib2/__init__.py for details.

This code is made available under the Apache License and is copyright the Python-Twitter Developers.

3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ By the Python-Twitter Developers <[email protected]>
Introduction
============

This library provides a pure Python interface for the `Twitter API https://dev.twitter.com/`. It works with Python versions from 2.5 to 2.7. Python 3 support is under development.
This library provides a pure Python interface for the `Twitter API https://dev.twitter.com/`. It works with Python versions from 2.6+. Python 3 support is under development.

`Twitter http://twitter.com` provides a service that allows people to connect via the web, IM, and SMS. Twitter exposes a `web services API http://dev.twitter.com/doc` and this library is intended to make it even easier for Python programmers to use.

Expand Down Expand Up @@ -38,7 +38,6 @@ Check out the latest development version anonymously with::
Dependencies

* [Requests](http://docs.python-requests.org/en/latest/)
* [SimpleJson](http://cheeseshop.python.org/pypi/simplejson)
* [Requests OAuthlib](https://requests-oauthlib.readthedocs.org/en/latest/)

=============
Expand Down
10 changes: 2 additions & 8 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Author: The Python-Twitter Developers <[email protected]>

Introduction
------------
This library provides a pure Python interface for the `Twitter API <https://dev.twitter.com/>`_. It works with Python versions from 2.5 to 2.7. Python 3 support is under development.
This library provides a pure Python interface for the `Twitter API <https://dev.twitter.com/>`_. It works with Python version 2.6+. Python 3 support is under development.

`Twitter <http://twitter.com>`_ provides a service that allows people to connect via the web, IM, and SMS. Twitter exposes a `web services API <http://dev.twitter.com/doc>`_ and this library is intended to make it even easier for Python programmers to use.

Expand All @@ -22,14 +22,8 @@ From source:

Install the dependencies:

- `SimpleJson <http://cheeseshop.python.org/pypi/simplejson>`_
- `Requests OAuthlib <https://requests-oauthlib.readthedocs.org/en/latest/>`_
- `HTTPLib2 <http://code.google.com/p/httplib2/>`_

This branch is currently in development to replace the OAuth and HTTPLib2 libarays with the following:

- `Requests <http://docs.python-requests.org/en/latest/>`_

- `Requests OAuthlib <https://requests-oauthlib.readthedocs.org/en/latest/>`_

Alternatively use `pip`::
Expand Down
2 changes: 1 addition & 1 deletion examples/shorten_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self,
self.password = password

def Shorten(self,
longURL):
longURL):
'''Call TinyURL API and returned shortened URL result
Args:
Expand Down
88 changes: 40 additions & 48 deletions get_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# parse_qsl moved to urlparse module in v2.6
try:
from urlparse import parse_qsl
except:
from cgi import parse_qsl

import webbrowser
import oauth2 as oauth
from requests_oauthlib import OAuth1Session

REQUEST_TOKEN_URL = 'https://api.twitter.com/oauth/request_token'
ACCESS_TOKEN_URL = 'https://api.twitter.com/oauth/access_token'
Expand All @@ -31,50 +25,48 @@

def get_access_token(consumer_key, consumer_secret):

signature_method_hmac_sha1 = oauth.SignatureMethod_HMAC_SHA1()
oauth_consumer = oauth.Consumer(key=consumer_key, secret=consumer_secret)
oauth_client = oauth.Client(oauth_consumer)
oauth_client = OAuth1Session(consumer_key, client_secret=consumer_secret)

print 'Requesting temp token from Twitter'

resp, content = oauth_client.request(REQUEST_TOKEN_URL, 'POST', body="oauth_callback=oob")

if resp['status'] != '200':
print 'Invalid respond from Twitter requesting temp token: %s' % resp['status']
else:
request_token = dict(parse_qsl(content))
url = '%s?oauth_token=%s' % (AUTHORIZATION_URL, request_token['oauth_token'])

print ''
print 'I will try to start a browser to visit the following Twitter page'
print 'if a browser will not start, copy the URL to your browser'
print 'and retrieve the pincode to be used'
print 'in the next step to obtaining an Authentication Token:'
print ''
print url
print ''

webbrowser.open(url)
pincode = raw_input('Pincode? ')

token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
token.set_verifier(pincode)

print ''
print 'Generating and signing request for an access token'
print ''

oauth_client = oauth.Client(oauth_consumer, token)
resp, content = oauth_client.request(ACCESS_TOKEN_URL, method='POST', body='oauth_callback=oob&oauth_verifier=%s' % pincode)
access_token = dict(parse_qsl(content))

if resp['status'] != '200':
print 'The request for a Token did not succeed: %s' % resp['status']
print access_token
else:
print 'Your Twitter Access Token key: %s' % access_token['oauth_token']
print ' Access Token secret: %s' % access_token['oauth_token_secret']
print ''
try:
resp = oauth_client.fetch_request_token(REQUEST_TOKEN_URL)
except ValueError, e:
print 'Invalid respond from Twitter requesting temp token: %s' % e
return
url = oauth_client.authorization_url(AUTHORIZATION_URL)

print ''
print 'I will try to start a browser to visit the following Twitter page'
print 'if a browser will not start, copy the URL to your browser'
print 'and retrieve the pincode to be used'
print 'in the next step to obtaining an Authentication Token:'
print ''
print url
print ''

webbrowser.open(url)
pincode = raw_input('Pincode? ')


print ''
print 'Generating and signing request for an access token'
print ''

oauth_client = OAuth1Session(consumer_key, client_secret=consumer_secret,
resource_owner_key=resp.get('oauth_token'),
resource_owner_secret=resp.get('oauth_token_secret'),
verifier=pincode
)
try:
resp = oauth_client.fetch_access_token(ACCESS_TOKEN_URL)
except ValueError, e:
print 'Invalid respond from Twitter requesting access token: %s' % e
return

print 'Your Twitter Access Token key: %s' % resp.get('oauth_token')
print ' Access Token secret: %s' % resp.get('oauth_token_secret')
print ''


def main():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def read(*paths):
read('AUTHORS.rst') + '\n\n' +
read('CHANGES')),
packages=find_packages(exclude=['tests*']),
install_requires = ['simplejson', 'requests', 'requests-oauthlib'],
install_requires = ['requests', 'requests-oauthlib'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
Expand Down
19 changes: 1 addition & 18 deletions twitter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,7 @@
__author__ = '[email protected]'
__version__ = '2.0'

try:
# Python >= 2.6
import json as simplejson
except ImportError:
try:
# Python < 2.6
import simplejson
except ImportError:
try:
# Google App Engine
from django.utils import simplejson
except ImportError:
raise ImportError, "Unable to load a json library"
# parse_qsl moved to urlparse module in v2.6
try:
from urlparse import parse_qsl, parse_qs
except ImportError:
from cgi import parse_qsl, parse_qs
import json as simplejson

try:
from hashlib import md5
Expand Down
29 changes: 17 additions & 12 deletions twitter/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __init__(self,
stream_url=None,
use_gzip_compression=False,
debugHTTP=False,
requests_timeout=None):
timeout=None):
'''Instantiate a new twitter.Api object.
Args:
Expand Down Expand Up @@ -152,7 +152,7 @@ def __init__(self,
debugHTTP:
Set to True to enable debug output from urllib2 when performing
any HTTP requests. Defaults to False. [Optional]
requests_timeout:
timeout:
Set timeout (in seconds) of the http/https requests. If None the
requests lib default will be used. Defaults to None. [Optional]
'''
Expand All @@ -163,7 +163,7 @@ def __init__(self,
self._use_gzip = use_gzip_compression
self._debugHTTP = debugHTTP
self._shortlink_size = 19
self._requests_timeout = requests_timeout
self._timeout = timeout

self._InitializeRequestHeaders(request_headers)
self._InitializeUserAgent()
Expand Down Expand Up @@ -897,7 +897,8 @@ def PostMedia(self,
status:
the text of your update
media:
location of media(PNG, JPG, GIF)
This can be the location of media(PNG, JPG, GIF) on the local file
system or at an HTTP URL, it can also be a file-like object
possibly_sensitive:
set true if content is "advanced." [Optional]
in_reply_to_status_id:
Expand Down Expand Up @@ -925,10 +926,14 @@ def PostMedia(self,
u_status = unicode(status, self._input_encoding)

data = {'status': status}
if media.startswith('http'):
if not hasattr(media, 'read'):
if media.startswith('http'):
data['media'] = urllib2.urlopen(media).read()
else:
with open(str(media), 'rb') as f:
data['media'] = f.read()
else:
data['media'] = open(str(media), 'rb').read()
data['media'] = media.read()
if possibly_sensitive:
data['possibly_sensitive'] = 'true'
if in_reply_to_status_id:
Expand All @@ -940,7 +945,7 @@ def PostMedia(self,
data['place_id'] = str(place_id)
if display_coordinates:
data['display_coordinates'] = 'true'

json = self._RequestUrl(url, 'POST', data=data)
data = self._ParseAndCheckTwitter(json.content)

Expand Down Expand Up @@ -3460,7 +3465,7 @@ def _RequestUrl(self, url, verb, data=None):
url,
files=data,
auth=self.__auth,
timeout=self._requests_timeout
timeout=self._timeout
)
except requests.RequestException as e:
raise TwitterError(str(e))
Expand All @@ -3470,7 +3475,7 @@ def _RequestUrl(self, url, verb, data=None):
url,
data=data,
auth=self.__auth,
timeout=self._requests_timeout
timeout=self._timeout
)
except requests.RequestException as e:
raise TwitterError(str(e))
Expand All @@ -3480,7 +3485,7 @@ def _RequestUrl(self, url, verb, data=None):
return requests.get(
url,
auth=self.__auth,
timeout=self._requests_timeout
timeout=self._timeout
)
except requests.RequestException as e:
raise TwitterError(str(e))
Expand All @@ -3504,15 +3509,15 @@ def _RequestStream(self, url, verb, data=None):
try:
return requests.post(url, data=data, stream=True,
auth=self.__auth,
timeout=self._requests_timeout
timeout=self._timeout
)
except requests.RequestException as e:
raise TwitterError(str(e))
if verb == 'GET':
url = self._BuildUrl(url, extra_params=data)
try:
return requests.get(url, stream=True, auth=self.__auth,
timeout=self._requests_timeout
timeout=self._timeout
)
except requests.RequestException as e:
raise TwitterError(str(e))
Expand Down
2 changes: 1 addition & 1 deletion twitter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
__author__ = '[email protected]'

import os
import simplejson
import json as simplejson
import time
import calendar
import unittest
Expand Down

0 comments on commit 1d792f4

Please sign in to comment.