Permalink
Browse files

PEP8 / pyflakes cleanup.

  • Loading branch information...
1 parent b4cd605 commit 5f037e8e9e38aff11c4e71d056e61ef6441b8c24 @garnaat garnaat committed Mar 27, 2012
Showing with 59 additions and 38 deletions.
  1. +1 −1 boto/compat.py
  2. +58 −37 boto/connection.py
View
@@ -92,7 +92,7 @@
raw_input = input
else:
raw_input = raw_input
-
+
try:
# Python 3.x
from email.mime.multipart import MIMEMultipart
View
@@ -54,15 +54,14 @@
import xml.sax
from . import auth
-from . import auth_handler
from . import compat
import boto
import boto.utils
import boto.handler
import boto.cacerts
from boto import config, UserAgent
-from boto.exception import AWSConnectionError, BotoClientError, BotoServerError
+from boto.exception import BotoClientError, BotoServerError
from boto.provider import Provider
from boto.resultset import ResultSet
@@ -81,10 +80,12 @@
except ImportError:
import dummy_threading as threading
-PORTS_BY_SECURITY = { True: 443, False: 80 }
+PORTS_BY_SECURITY = {True: 443, False: 80}
DEFAULT_CA_CERTS_FILE = os.path.join(
- os.path.dirname(os.path.abspath(boto.cacerts.__file__ )), "cacerts.txt")
+ os.path.dirname(os.path.abspath(boto.cacerts.__file__ )),
+ "cacerts.txt")
+
class HostConnectionPool(object):
@@ -122,7 +123,7 @@ def size(self):
ready to be returned by get().
"""
return len(self.queue)
-
+
def put(self, conn):
"""
Adds a connection to the pool, along with the time it was
@@ -164,10 +165,11 @@ def _conn_ready(self, conn):
state we care about isn't available in any public methods.
"""
if compat.on_appengine():
- # Google App Engine implementation of HTTPConnection doesn't contain
- # _HTTPConnection__response attribute. Moreover, it's not possible
- # to determine if given connection is ready. Reusing connections
- # simply doesn't make sense with App Engine urlfetch service.
+ # The Google App Engine implementation of HTTPConnection
+ # doesn't contain _HTTPConnection__response attribute.
+ # Moreover, it's not possible to determine if given connection
+ # is ready. Reusing connections simply doesn't make sense
+ # with App Engine urlfetch service.
return False
else:
response = getattr(conn, '_HTTPConnection__response', None)
@@ -191,6 +193,7 @@ def _pair_stale(self, pair):
now = time.time()
return return_time + ConnectionPool.STALE_DURATION < now
+
class ConnectionPool(object):
"""
@@ -204,7 +207,7 @@ class ConnectionPool(object):
#
# The amout of time between calls to clean.
#
-
+
CLEAN_INTERVAL = 5.0
#
@@ -265,7 +268,7 @@ def clean(self):
get rid of empty pools. Pools clean themselves every time a
connection is fetched; this cleaning takes care of pools that
aren't being used any more, so nothing is being gotten from
- them.
+ them.
"""
with self.mutex:
now = time.time()
@@ -279,6 +282,7 @@ def clean(self):
del self.host_to_pool[host]
self.last_clean_time = now
+
class HTTPRequest(object):
def __init__(self, method, protocol, host, port, path, auth_path,
@@ -296,26 +300,26 @@ def __init__(self, method, protocol, host, port, path, auth_path,
:type port: int
:param port: port on which the request is being sent. Zero means unset,
- in which case default port will be chosen.
+ in which case default port will be chosen.
:type path: string
:param path: URL path that is being accessed.
:type auth_path: string
:param path: The part of the URL path used when creating the
- authentication string.
+ authentication string.
:type params: dict
- :param params: HTTP url query parameters, with key as name of the param,
- and value as value of param.
+ :param params: HTTP url query parameters, with key as name of
+ the param, and value as value of param.
:type headers: dict
:param headers: HTTP headers, with key as name of the header and value
- as value of header.
+ as value of header.
:type body: string
:param body: Body of the HTTP request. If not present, will be None or
- empty string ('').
+ empty string ('').
"""
self.method = method
self.protocol = protocol
@@ -359,8 +363,11 @@ def authorize(self, connection, **kwargs):
self.headers['Transfer-Encoding'] != 'chunked':
self.headers['Content-Length'] = str(len(self.body))
+
class AWSAuthConnection(object):
- def __init__(self, host, aws_access_key_id=None, aws_secret_access_key=None,
+
+ def __init__(self, host, aws_access_key_id=None,
+ aws_secret_access_key=None,
is_secure=True, port=None, proxy=None, proxy_port=None,
proxy_user=None, proxy_pass=None, debug=0,
https_connection_factory=None, path='/',
@@ -382,9 +389,8 @@ def __init__(self, host, aws_access_key_id=None, aws_secret_access_key=None,
:type https_connection_factory: list or tuple
:param https_connection_factory: A pair of an HTTP connection
- factory and the exceptions to catch.
- The factory should have a similar
- interface to L{httplib.HTTPSConnection}.
+ factory and the exceptions to catch. The factory should
+ have a similar interface to L{httplib.HTTPSConnection}.
:param str proxy: Address/hostname for a proxy server
@@ -504,10 +510,14 @@ def aws_secret_access_key(self):
secret_key = aws_secret_access_key
def get_path(self, path='/'):
- # The default behavior is to suppress consecutive slashes for reasons
- # discussed at
- # https://groups.google.com/forum/#!topic/boto-dev/-ft0XPUy0y8
- # You can override that behavior with the suppress_consec_slashes param.
+ """
+ The default behavior is to suppress consecutive slashes for reasons
+ discussed at:
+
+ https://groups.google.com/forum/#!topic/boto-dev/-ft0XPUy0y8
+
+ You can override that behavior with the suppress_consec_slashes param.
+ """
if not self.suppress_consec_slashes:
return self.path + re.sub('^/*', "", path)
pos = path.find('?')
@@ -640,15 +650,17 @@ def proxy_ssl(self):
for k, v in self.get_proxy_auth_header().items():
sock.sendall("%s: %s\r\n" % (k, v))
sock.sendall("\r\n")
- resp = compat.httplib.HTTPResponse(sock, strict=True, debuglevel=self.debug)
+ resp = compat.httplib.HTTPResponse(sock, strict=True,
+ debuglevel=self.debug)
resp.begin()
if resp.status != 200:
# Fake a socket error, use a code that make it obvious it hasn't
# been generated by the socket library
raise socket.error(-71,
"Error talking to HTTP proxy %s:%s: %s (%s)" %
- (self.proxy, self.proxy_port, resp.status, resp.reason))
+ (self.proxy, self.proxy_port,
+ resp.status, resp.reason))
# We can safely close the response, it duped the original socket
resp.close()
@@ -710,7 +722,8 @@ def _mexe(self, request, sender=None, override_num_retries=None,
body = None
e = None
if override_num_retries is None:
- num_retries = config.getint('Boto', 'num_retries', self.num_retries)
+ num_retries = config.getint('Boto', 'num_retries',
+ self.num_retries)
else:
num_retries = override_num_retries
i = 0
@@ -755,8 +768,11 @@ def _mexe(self, request, sender=None, override_num_retries=None,
connection)
return response
else:
- scheme, request.host, request.path, \
- params, query, fragment = compat.urlparse.urlparse(location)
+ t = compat.urlparse.urlparse(location)
+ scheme = t[0]
+ request.host = t[1]
+ request.path = t[2]
+ query = t[4]
if query:
request.path += '?' + query
msg = 'Redirecting: %s' % scheme + '://'
@@ -768,9 +784,10 @@ def _mexe(self, request, sender=None, override_num_retries=None,
except self.http_exceptions as e:
for unretryable in self.http_unretryable_exceptions:
if isinstance(e, unretryable):
- boto.log.debug(
- 'encountered unretryable %s exception, re-raising' %
- e.__class__.__name__)
+ msg = 'encountered unretryable'
+ msg += '%s exception, ' % e.__class__.__name__
+ msg += 're-raising'
+ boto.log.debug(msg)
raise e
boto.log.debug('encountered %s exception, reconnecting' % \
e.__class__.__name__)
@@ -817,18 +834,22 @@ def build_base_http_request(self, method, path, auth_path,
def make_request(self, method, path, headers=None, data='', host=None,
auth_path=None, sender=None, override_num_retries=None):
- """Makes a request to the server, with stock multiple-retry logic."""
+ """
+ Makes a request to the server, with stock multiple-retry logic.
+ """
http_request = self.build_base_http_request(method, path, auth_path,
{}, headers, data, host)
return self._mexe(http_request, sender, override_num_retries)
def close(self):
- """(Optional) Close any open HTTP connections. This is non-destructive,
- and making a new request will open a connection again."""
-
+ """
+ (Optional) Close any open HTTP connections. This is non-destructive,
+ and making a new request will open a connection again.
+ """
boto.log.debug('closing all HTTP connections')
self._connection = None # compat field
+
class AWSQueryConnection(AWSAuthConnection):
APIVersion = ''

0 comments on commit 5f037e8

Please sign in to comment.