Skip to content

Commit

Permalink
yapf formatting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gmr committed Apr 29, 2015
1 parent edcb619 commit 161fc0d
Show file tree
Hide file tree
Showing 17 changed files with 632 additions and 412 deletions.
1 change: 1 addition & 0 deletions pika/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# not available in python 2.6
from logging import NullHandler
except ImportError:

class NullHandler(logging.Handler):
def emit(self, record):
pass
Expand Down
1 change: 0 additions & 1 deletion pika/adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@
from pika.adapters.libev_connection import LibevConnection
except ImportError:
LibevConnection = None

13 changes: 8 additions & 5 deletions pika/adapters/asyncore_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def add_timeout(self, deadline, callback_method):
:rtype: str
"""
value = {'deadline': time.time() + deadline,
'callback': callback_method}
value = {
'deadline': time.time() + deadline,
'callback': callback_method
}
timeout_id = hash(frozenset(value.items()))
self._timeouts[timeout_id] = value
return timeout_id
Expand Down Expand Up @@ -110,6 +112,7 @@ class AsyncoreConnection(base_connection.BaseConnection):
:raises: RuntimeError
"""

def __init__(self,
parameters=None,
on_open_callback=None,
Expand All @@ -128,15 +131,16 @@ def __init__(self,
:raises: RuntimeError
"""

class ConnectingIOLoop(object):
def add_timeout(self, duration, callback_method):
time.sleep(duration)
return callback_method()

ioloop = ConnectingIOLoop()
super(AsyncoreConnection, self).__init__(parameters, on_open_callback,
on_open_error_callback,
on_close_callback,
ioloop,
on_close_callback, ioloop,
stop_ioloop_on_close)

def _adapter_connect(self):
Expand All @@ -153,4 +157,3 @@ def _adapter_connect(self):
self.ioloop = self.socket
self._on_connected()
return error

33 changes: 18 additions & 15 deletions pika/adapters/base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def __init__(self,
self.socket = None
self.stop_ioloop_on_close = stop_ioloop_on_close
self.write_buffer = None
super(BaseConnection, self).__init__(parameters,
on_open_callback,
super(BaseConnection, self).__init__(parameters, on_open_callback,
on_open_error_callback,
on_close_callback)

Expand Down Expand Up @@ -114,8 +113,8 @@ def _adapter_connect(self):
try:
addresses = socket.getaddrinfo(self.params.host, self.params.port)
except socket.error as error:
LOGGER.critical('Could not get addresses to use: %s (%s)',
error, self.params.host)
LOGGER.critical('Could not get addresses to use: %s (%s)', error,
self.params.host)
return error

# If the socket is created and connected, continue on
Expand Down Expand Up @@ -152,9 +151,10 @@ def _check_state_on_disconnect(self):
"probable authentication error")
raise exceptions.ProbableAuthenticationError
elif self.connection_state == self.CONNECTION_TUNE:
LOGGER.error("Socket closed while tuning the connection indicating "
"a probable permission error when accessing a virtual "
"host")
LOGGER.error(
"Socket closed while tuning the connection indicating "
"a probable permission error when accessing a virtual "
"host")
raise exceptions.ProbableAccessDeniedError
elif self.is_open:
LOGGER.warning("Socket closed when connection was open")
Expand All @@ -175,20 +175,22 @@ def _create_and_connect_to_socket(self, sock_addr_tuple):
else:
ssl_text = ""

LOGGER.info('Connecting to %s:%s%s',
sock_addr_tuple[4][0], sock_addr_tuple[4][1], ssl_text)
LOGGER.info('Connecting to %s:%s%s', sock_addr_tuple[4][0],
sock_addr_tuple[4][1], ssl_text)

# Connect to the socket
try:
self.socket.connect(sock_addr_tuple[4])
except socket.timeout:
error = 'Connection to %s:%s failed: timeout' % (
sock_addr_tuple[4][0], sock_addr_tuple[4][1])
sock_addr_tuple[4][0], sock_addr_tuple[4][1]
)
LOGGER.error(error)
return error
except socket.error as error:
error = 'Connection to %s:%s failed: %s' % (
sock_addr_tuple[4][0], sock_addr_tuple[4][1], error)
error = 'Connection to %s:%s failed: %s' % (sock_addr_tuple[4][0],
sock_addr_tuple[4][1],
error)
LOGGER.warning(error)
return error

Expand All @@ -198,7 +200,8 @@ def _create_and_connect_to_socket(self, sock_addr_tuple):
self._do_ssl_handshake()
except ssl.SSLError as error:
error = 'SSL connection to %s:%s failed: %s' % (
sock_addr_tuple[4][0], sock_addr_tuple[4][1], error)
sock_addr_tuple[4][0], sock_addr_tuple[4][1], error
)
LOGGER.error(error)
return error
# Made it this far
Expand Down Expand Up @@ -295,8 +298,8 @@ def _handle_error(self, error_value):
LOGGER.error("Socket connection was broken")
else:
# Haven't run into this one yet, log it.
LOGGER.error("Socket Error on fd %d: %s",
self.socket.fileno(), error_code)
LOGGER.error("Socket Error on fd %d: %s", self.socket.fileno(),
error_code)

# Disconnect from our IOLoop and let Connection know what's up
self._handle_disconnect()
Expand Down

0 comments on commit 161fc0d

Please sign in to comment.