Refactor redundant Connection factory methods to base
This commit is contained in:
@@ -239,6 +239,24 @@ class Connection(object):
|
||||
"""
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def factory(cls, *args, **kwargs):
|
||||
"""
|
||||
A factory function which returns connections which have
|
||||
succeeded in connecting and are ready for service (or
|
||||
raises an exception otherwise).
|
||||
"""
|
||||
timeout = kwargs.pop('timeout', 5.0)
|
||||
conn = cls(*args, **kwargs)
|
||||
conn.connected_event.wait(timeout)
|
||||
if conn.last_error:
|
||||
raise conn.last_error
|
||||
elif not conn.connected_event.is_set():
|
||||
conn.close()
|
||||
raise OperationTimedOut("Timed out creating connection")
|
||||
else:
|
||||
return conn
|
||||
|
||||
def close(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
@@ -156,19 +156,6 @@ class AsyncoreConnection(Connection, asyncore.dispatcher):
|
||||
cls._loop._cleanup()
|
||||
cls._loop = None
|
||||
|
||||
@classmethod
|
||||
def factory(cls, *args, **kwargs):
|
||||
timeout = kwargs.pop('timeout', 5.0)
|
||||
conn = cls(*args, **kwargs)
|
||||
conn.connected_event.wait(timeout)
|
||||
if conn.last_error:
|
||||
raise conn.last_error
|
||||
elif not conn.connected_event.is_set():
|
||||
conn.close()
|
||||
raise OperationTimedOut("Timed out creating connection")
|
||||
else:
|
||||
return conn
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Connection.__init__(self, *args, **kwargs)
|
||||
asyncore.dispatcher.__init__(self)
|
||||
|
||||
@@ -57,19 +57,6 @@ class EventletConnection(Connection):
|
||||
def initialize_reactor(cls):
|
||||
eventlet.monkey_patch()
|
||||
|
||||
@classmethod
|
||||
def factory(cls, *args, **kwargs):
|
||||
timeout = kwargs.pop('timeout', 5.0)
|
||||
conn = cls(*args, **kwargs)
|
||||
conn.connected_event.wait(timeout)
|
||||
if conn.last_error:
|
||||
raise conn.last_error
|
||||
elif not conn.connected_event.is_set():
|
||||
conn.close()
|
||||
raise OperationTimedOut("Timed out creating connection")
|
||||
else:
|
||||
return conn
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Connection.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
@@ -50,19 +50,6 @@ class GeventConnection(Connection):
|
||||
_write_watcher = None
|
||||
_socket = None
|
||||
|
||||
@classmethod
|
||||
def factory(cls, *args, **kwargs):
|
||||
timeout = kwargs.pop('timeout', 5.0)
|
||||
conn = cls(*args, **kwargs)
|
||||
conn.connected_event.wait(timeout)
|
||||
if conn.last_error:
|
||||
raise conn.last_error
|
||||
elif not conn.connected_event.is_set():
|
||||
conn.close()
|
||||
raise OperationTimedOut("Timed out creating connection")
|
||||
else:
|
||||
return conn
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Connection.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
@@ -236,19 +236,6 @@ class LibevConnection(Connection):
|
||||
cls._libevloop._cleanup()
|
||||
cls._libevloop = None
|
||||
|
||||
@classmethod
|
||||
def factory(cls, *args, **kwargs):
|
||||
timeout = kwargs.pop('timeout', 5.0)
|
||||
conn = cls(*args, **kwargs)
|
||||
conn.connected_event.wait(timeout)
|
||||
if conn.last_error:
|
||||
raise conn.last_error
|
||||
elif not conn.connected_event.is_set():
|
||||
conn.close()
|
||||
raise OperationTimedOut("Timed out creating new connection")
|
||||
else:
|
||||
return conn
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Connection.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
@@ -148,24 +148,6 @@ class TwistedConnection(Connection):
|
||||
if not cls._loop:
|
||||
cls._loop = TwistedLoop()
|
||||
|
||||
@classmethod
|
||||
def factory(cls, *args, **kwargs):
|
||||
"""
|
||||
A factory function which returns connections which have
|
||||
succeeded in connecting and are ready for service (or
|
||||
raises an exception otherwise).
|
||||
"""
|
||||
timeout = kwargs.pop('timeout', 5.0)
|
||||
conn = cls(*args, **kwargs)
|
||||
conn.connected_event.wait(timeout)
|
||||
if conn.last_error:
|
||||
raise conn.last_error
|
||||
elif not conn.connected_event.is_set():
|
||||
conn.close()
|
||||
raise OperationTimedOut("Timed out creating connection")
|
||||
else:
|
||||
return conn
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
Initialization method.
|
||||
|
||||
Reference in New Issue
Block a user