Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jaraco/irc
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 29, 2019
2 parents 7b5755c + c4924cf commit 571c1f4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
16 changes: 16 additions & 0 deletions CHANGES.rst
Expand Up @@ -9,6 +9,22 @@
* #158: The AsyncIO server now accepts a connection factory to
enable features like SSL and IPv6 support.

* #155: ``SimpleIRCClient`` now has a ``dcc`` method for initiating
and associating a DCCConnection object with the client.
``DCCConnection.listen`` now accepts a ``address`` parameter.
Deprecated ``SimpleIRCClient.dcc_listen`` and
``SimpleIRCClient.dcc_connect`` in favor of the better separation
of concerns. Clients should replace::

client.dcc_connect(addr, port, type)
client.dcc_listen(type)

with::

client.dcc(type).connect(addr, port)
client.dcc(type).listen()


17.0
====

Expand Down
28 changes: 18 additions & 10 deletions irc/client.py
Expand Up @@ -60,6 +60,7 @@
import functools
import itertools
import contextlib
import warnings

import jaraco.functools
from jaraco.itertools import always_iterable, infinite_call
Expand Down Expand Up @@ -977,7 +978,7 @@ def connect(self, address, port):
self.reactor._on_connect(self.socket)
return self

def listen(self):
def listen(self, addr=None):
"""Wait for a connection/reconnection from a DCC peer.
Returns the DCCConnection object.
Expand All @@ -991,8 +992,9 @@ def listen(self):
self.handlers = {}
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.passive = True
default_addr = socket.gethostbyname(socket.gethostname()), 0
try:
self.socket.bind((socket.gethostbyname(socket.gethostname()), 0))
self.socket.bind(addr or default_addr)
self.localaddress, self.localport = self.socket.getsockname()
self.socket.listen(10)
except socket.error as x:
Expand Down Expand Up @@ -1157,6 +1159,16 @@ def connect(self, *args, **kwargs):
"""Connect using the underlying connection"""
self.connection.connect(*args, **kwargs)

def dcc(self, *args, **kwargs):
"""Create and associate a new DCCConnection object.
Use the returned object to listen for or connect to
a DCC peer.
"""
dcc = self.reactor.dcc(*args, **kwargs)
self.dcc_connections.append(dcc)
return dcc

def dcc_connect(self, address, port, dcctype="chat"):
"""Connect to a DCC peer.
Expand All @@ -1168,20 +1180,16 @@ def dcc_connect(self, address, port, dcctype="chat"):
Returns a DCCConnection instance.
"""
dcc = self.reactor.dcc(dcctype)
self.dcc_connections.append(dcc)
dcc.connect(address, port)
return dcc
warnings.warn("Use self.dcc(type).connect()", DeprecationWarning)
return self.dcc(dcctype).connect(address, port)

def dcc_listen(self, dcctype="chat"):
"""Listen for connections from a DCC peer.
Returns a DCCConnection instance.
"""
dcc = self.reactor.dcc(dcctype)
self.dcc_connections.append(dcc)
dcc.listen()
return dcc
warnings.warn("Use self.dcc(type).listen()", DeprecationWarning)
return self.dcc(dcctype).listen()

def start(self):
"""Start the IRC client."""
Expand Down

0 comments on commit 571c1f4

Please sign in to comment.