mirror of https://github.com/Shizmob/pydle.git
Allow passing eventloop as an argument to connect().
This commit is contained in:
parent
0472d6020a
commit
06dab44dc2
|
@ -96,14 +96,14 @@ class BasicClient:
|
|||
# Reset any attributes.
|
||||
self._reset_attributes()
|
||||
|
||||
def _connect(self, hostname, port, reconnect=False, channels=[], encoding=protocol.DEFAULT_ENCODING, source_address=None):
|
||||
def _connect(self, hostname, port, reconnect=False, channels=[], encoding=protocol.DEFAULT_ENCODING, source_address=None, eventloop=None):
|
||||
""" Connect to IRC host. """
|
||||
if not reconnect:
|
||||
self._autojoin_channels = channels
|
||||
|
||||
# Create connection if we can't reuse it.
|
||||
if not reconnect or not self.connection:
|
||||
self.connection = connection.Connection(hostname, port or protocol.DEFAULT_PORT, source_adress=source_address)
|
||||
self.connection = connection.Connection(hostname, port or protocol.DEFAULT_PORT, source_adress=source_address, eventloop=eventloop)
|
||||
self.encoding = encoding
|
||||
|
||||
# Connect.
|
||||
|
|
|
@ -32,7 +32,7 @@ class Connection:
|
|||
""" A TCP connection over the IRC protocol. """
|
||||
CONNECT_TIMEOUT = 10
|
||||
|
||||
def __init__(self, hostname, port, tls=False, tls_verify=True, tls_certificate_file=None, tls_certificate_keyfile=None, tls_certificate_password=None, ping_timeout=240, source_address=None):
|
||||
def __init__(self, hostname, port, tls=False, tls_verify=True, tls_certificate_file=None, tls_certificate_keyfile=None, tls_certificate_password=None, ping_timeout=240, source_address=None, eventloop=None):
|
||||
self.hostname = hostname
|
||||
self.port = port
|
||||
self.source_address = source_address
|
||||
|
@ -47,7 +47,7 @@ class Connection:
|
|||
|
||||
self.socket = None
|
||||
self.socket_lock = threading.RLock()
|
||||
self.eventloop = async.EventLoop()
|
||||
self.eventloop = eventloop or async.EventLoop()
|
||||
self.handlers = { 'read': [], 'write': [], 'error': [] }
|
||||
|
||||
self.send_queue = collections.deque()
|
||||
|
@ -226,7 +226,7 @@ class Connection:
|
|||
def setup_handlers(self):
|
||||
if not self.connected:
|
||||
return
|
||||
|
||||
|
||||
self.remove_handlers()
|
||||
with self.socket_lock:
|
||||
self.eventloop.on_read(self.socket.fileno(), self._on_read)
|
||||
|
|
|
@ -30,7 +30,7 @@ class TLSSupport(rfc1459.RFC1459Support):
|
|||
port = rfc1459.protocol.DEFAULT_PORT
|
||||
return super().connect(hostname, port, tls=tls, **kwargs)
|
||||
|
||||
def _connect(self, hostname, port, reconnect=False, password=None, encoding=pydle.protocol.DEFAULT_ENCODING, channels=[], tls=False, tls_verify=False, source_address=None):
|
||||
def _connect(self, hostname, port, reconnect=False, password=None, encoding=pydle.protocol.DEFAULT_ENCODING, channels=[], tls=False, tls_verify=False, source_address=None, eventloop=None):
|
||||
""" Connect to IRC server, optionally over TLS. """
|
||||
self.password = password
|
||||
if not reconnect:
|
||||
|
@ -43,7 +43,8 @@ class TLSSupport(rfc1459.RFC1459Support):
|
|||
tls=tls, tls_verify=tls_verify,
|
||||
tls_certificate_file=self.tls_client_cert,
|
||||
tls_certificate_keyfile=self.tls_client_cert_key,
|
||||
tls_certificate_password=self.tls_client_cert_password)
|
||||
tls_certificate_password=self.tls_client_cert_password,
|
||||
eventloop=eventloop)
|
||||
self.encoding = encoding
|
||||
|
||||
# Connect.
|
||||
|
|
Loading…
Reference in New Issue