"""HTTP server replying with the given responses to the expected
requests."""
def url(port, path):
- return 'http://%s:%s%s' % (socket.gethostname(), port, path)
+ return 'http://%s:%s%s' % (socket.gethostname().lower(), port, path)
responses = list(reversed(resp))
with start_server(
Response(link, 301, {"Location": redirected}),
Response(redirected, 301, {"Location": filtered})) as url:
- hosts = [socket.gethostname()]
+ hosts = [socket.gethostname().lower()]
assert filtered == follow_redirects(url(link), hosts)
def test_follow_redirects_filtered_by_site_allowed():
with start_server(
Response(link, 301, {"Location": redirected}),
Response(redirected, 200, {})) as url:
- hosts = [socket.gethostname()]
+ hosts = [socket.gethostname().lower()]
assert url(redirected) == follow_redirects(url(link), hosts)
def test_expand_line():
if self.e.headers.get('Content-Encoding') == 'gzip':
buf = StringIO(data)
f = gzip.GzipFile(fileobj=buf)
- self.response_data = f.read()
+ data = f.read()
+ if len(data) == 0:
+ data = {}
+ elif "json" == self.format:
+ data = json.loads(data.decode('utf8'))
else:
- self.response_data = data
+ data = data.decode('utf8')
+ self.response_data = data
super(TwitterHTTPError, self).__init__(str(self))
def __str__(self):
import urllib as urllib_parse
from base64 import encodestring as encodebytes
+
class Auth(object):
"""
ABC for Authenticator objects.
by the authentication scheme in use."""
raise NotImplementedError()
+
class UserPassAuth(Auth):
"""
Basic auth authentication using email/username and
.encode('utf8')).strip(b'\n')
}
+
class NoAuth(Auth):
"""
No authentication authenticator.
def generate_headers(self):
return {}
+
+
+class MissingCredentialsError(Exception):
+ pass
import hmac
import base64
-from .auth import Auth
+from .auth import Auth, MissingCredentialsError
def write_token_file(filename, oauth_token, oauth_token_secret):
self.consumer_key = consumer_key
self.consumer_secret = consumer_secret
+ if token_secret is None or consumer_secret is None:
+ raise MissingCredentialsError(
+ 'You must supply strings for token_secret and consumer_secret, not None.')
+
def encode_params(self, base_url, method, params):
params = params.copy()
from urllib import quote, urlencode
from base64 import b64encode
-from .auth import Auth
+from .auth import Auth, MissingCredentialsError
def write_bearer_token_file(filename, oauth2_bearer_token):
"""
).encode('utf8')
}
return headers
-
-
-class MissingCredentialsError(Exception):
- pass