Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
a2219c88
Commit
a2219c88
authored
Jan 23, 2011
by
Mike
Committed by
Joshua Roesslein
May 14, 2013
Browse files
Add compression support.
Conflicts: tweepy/api.py
parent
c060f7b3
Changes
3
Hide whitespace changes
Inline
Side-by-side
CONTRIBUTORS
View file @
a2219c88
...
...
@@ -28,3 +28,4 @@ Can Duruk
Jan Schaumann (@jschauma)
Stuart Powers
Jeff Hull (@jsh2134)
Mike (mikeandmore)
tweepy/api.py
View file @
a2219c88
...
...
@@ -18,7 +18,7 @@ class API(object):
host
=
'api.twitter.com'
,
search_host
=
'search.twitter.com'
,
cache
=
None
,
secure
=
True
,
api_root
=
'/1.1'
,
search_root
=
''
,
retry_count
=
0
,
retry_delay
=
0
,
retry_errors
=
None
,
timeout
=
60
,
parser
=
None
):
parser
=
None
,
compression
=
False
):
self
.
auth
=
auth_handler
self
.
host
=
host
self
.
search_host
=
search_host
...
...
@@ -26,6 +26,7 @@ class API(object):
self
.
search_root
=
search_root
self
.
cache
=
cache
self
.
secure
=
secure
self
.
compression
=
compression
self
.
retry_count
=
retry_count
self
.
retry_delay
=
retry_delay
self
.
retry_errors
=
retry_errors
...
...
tweepy/binder.py
View file @
a2219c88
...
...
@@ -6,6 +6,8 @@ import httplib
import
urllib
import
time
import
re
from
StringIO
import
StringIO
import
gzip
from
tweepy.error
import
TweepError
from
tweepy.utils
import
convert_to_utf8_str
...
...
@@ -140,6 +142,10 @@ def bind_api(**config):
self
.
method
,
self
.
headers
,
self
.
parameters
)
# Request compression if configured
if
self
.
api
.
compression
:
self
.
headers
[
'Accept-encoding'
]
=
'gzip'
# Execute request
try
:
conn
.
request
(
self
.
method
,
url
,
headers
=
self
.
headers
,
body
=
self
.
post_data
)
...
...
@@ -167,7 +173,14 @@ def bind_api(**config):
raise
TweepError
(
error_msg
,
resp
)
# Parse the response payload
result
=
self
.
api
.
parser
.
parse
(
self
,
resp
.
read
())
body
=
resp
.
read
()
if
resp
.
getheader
(
'Content-Encoding'
,
''
)
==
'gzip'
:
try
:
zipper
=
gzip
.
GzipFile
(
fileobj
=
StringIO
(
body
))
body
=
zipper
.
read
()
except
Exception
,
e
:
raise
TweepError
(
'Failed to decompress data: %s'
%
e
)
result
=
self
.
api
.
parser
.
parse
(
self
,
body
)
conn
.
close
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment