Permalink
Browse files

merged from ircutils3

  • Loading branch information...
2 parents 256f8aa + 48ceae0 commit a8c9525427af7c15737947a2052c37f4ce98d9e5 @Kopachris committed Jul 17, 2015
View
0 ircutils/__init__.py → ircutils3/__init__.py 100755 → 100644
File renamed without changes.
View
10 ircutils/bot.py → ircutils3/bot.py
@@ -2,8 +2,8 @@
level of abstraction of the IRC protocol available in ``ircutils``.
"""
-import client
-import events
+from . import client
+from . import events
class SimpleBot(client.SimpleClient):
@@ -14,8 +14,8 @@ class SimpleBot(client.SimpleClient):
to check that documentation to see more of what is available.
"""
- def __init__(self, nick):
- client.SimpleClient.__init__(self, nick)
+ def __init__(self, nick, mode="+B", auto_handle=True):
+ client.SimpleClient.__init__(self, nick, mode, auto_handle)
self._autobind_handlers()
def _autobind_handlers(self):
@@ -58,4 +58,4 @@ def print_line(self, client, event):
"params": event.params
}
if self.verbose:
- print "[{cmd}] s={src!r} t={tgt!r} p={params}".format(**kwds)
+ print("[{cmd}] s={src!r} t={tgt!r} p={params}".format(**kwds))
View
14 ircutils/client.py → ircutils3/client.py 100755 → 100644
@@ -5,11 +5,11 @@
"""
import collections
-import connection
-import ctcp
-import events
-import format
-import protocol
+from . import connection
+from . import ctcp
+from . import events
+from . import format
+from . import protocol
class SimpleClient(object):
@@ -140,7 +140,7 @@ def connect(self, host, port=None, channel=None, use_ssl=False,
if channel is not None:
# Builds a handler on-the-fly for joining init channels
- if isinstance(channel, basestring):
+ if isinstance(channel, str):
channels = [channel]
else:
channels = channel
@@ -361,7 +361,7 @@ def _remove_channel_user_on_part(client, event):
def _remove_channel_user_on_quit(client, event):
# TODO: This solution is slow. There might be a better one.
- for channel in client.channels.values():
+ for channel in list(client.channels.values()):
channel.user_list.remove(event.source)
View
23 ircutils/connection.py → ircutils3/connection.py
@@ -14,8 +14,8 @@
ssl_available = True
import errno
-import protocol
-import responses
+from . import protocol
+from . import responses
class Connection(asynchat.async_chat):
@@ -28,7 +28,7 @@ class Connection(asynchat.async_chat):
def __init__(self, ipv6=False):
asynchat.async_chat.__init__(self)
self.ping_auto_respond = True
- self.set_terminator("\r\n")
+ self.set_terminator(b"\r\n")
self.collect_incoming_data = self._collect_incoming_data
if ipv6:
self.create_socket(socket.AF_INET6, socket.SOCK_STREAM)
@@ -57,10 +57,14 @@ def connect(self, hostname, port=None, use_ssl=False, password=None):
if password is not None:
self.execute("PASS", password)
+ def send(self, data):
+ if isinstance(data, str):
+ data = data.encode('UTF-8', errors='ignore')
+ return asynchat.async_chat.send(self, data)
def found_terminator(self):
""" Activated when ``\\r\\n`` is encountered. Do not call directly. """
- data = "".join(self.incoming)
+ data = b"".join(self.incoming).decode('UTF-8', errors='ignore')
self.incoming = []
prefix, command, params = protocol.parse_line(data)
if command == "PING" and self.ping_auto_respond:
@@ -77,12 +81,13 @@ def execute(self, command, *params, **kwargs):
>>> self.execute("PRIVMSG", "#channel", trailing="Hello!")
"""
- params = filter(lambda x:x is not None, params)
+ params = [x for x in params if x is not None]
if "trailing" in kwargs:
params = list(params)
if kwargs["trailing"] is not None:
params.append(":%s" % kwargs["trailing"])
- self.push("%s %s\r\n" % (command.upper(), " ".join(params)))
+ cmd_line = "%s %s\r\n" % (command.upper(), " ".join(params))
+ self.push(bytes(cmd_line, 'UTF-8', errors='ignore'))
def handle_error(self):
@@ -122,11 +127,11 @@ def _ssl_send(self, data):
try:
result = self.write(data)
return result
- except ssl.SSLError, why:
+ except ssl.SSLError as why:
if why[0] == asyncore.EWOULDBLOCK:
return 0
else:
- raise ssl.SSLError, why
+ raise ssl.SSLError(why)
return 0
@@ -138,7 +143,7 @@ def _ssl_recv(self, buffer_size):
self.handle_close()
return ''
return data
- except ssl.SSLError, why:
+ except ssl.SSLError as why:
if why[0] in [asyncore.ECONNRESET, asyncore.ENOTCONN,
asyncore.ESHUTDOWN]:
self.handle_close()
View
0 ircutils/ctcp.py → ircutils3/ctcp.py
File renamed without changes.
View
36 ircutils/events.py → ircutils3/events.py
@@ -11,7 +11,7 @@
import collections
import traceback
-import protocol
+from . import protocol
class EventDispatcher(object):
@@ -34,15 +34,15 @@ def __getitem__(self, name):
return self._listeners[name]
def __iter__(self):
- return iter(self._listeners.keys())
+ return iter(list(self._listeners.keys()))
def dispatch(self, client, event):
""" Notifies all of the listeners that an event is available.
Any listener which analyses the event and finds it to have what
the listener is looking for will then activate its event handlers.
"""
- for name, listener in self._listeners.items():
+ for name, listener in list(self._listeners.items()):
if listener.handlers != []:
listener.notify(client, event)
@@ -143,7 +143,12 @@ def my_handler(client, event):
use this method as handlers are automatically added.
"""
- bisect.insort(self.handlers, (priority, handler))
+ if len(self.handlers) == 0:
+ self.handlers.append((priority, handler))
+ else:
+ handler_priorities = list(zip(*self.handlers))[0]
+ ins_loc = bisect.bisect(handler_priorities, priority)
+ self.handlers.insert(ins_loc, (priority, handler))
def remove_handler(self, handler):
""" This removes all handlers that are equal to the ``handler`` which
@@ -162,11 +167,12 @@ def activate_handlers(self, *args):
and the event.
"""
for p, handler in self.handlers:
- try:
- handler(*args)
- except StandardError, ex:
- traceback.print_exc(ex)
- self.handlers.remove((p, handler))
+ handler(*args)
+ # try:
+ # handler(*args)
+ # except Exception as ex:
+ # #traceback.print_exc(ex)
+ # self.handlers.remove((p, handler))
def notify(self, client, event):
""" This is to be overridden when subclassed. It gets called after each
@@ -283,6 +289,11 @@ def notify(self, client, event):
if event.command == "ERROR":
self.activate_handlers(client, event)
+class ModeListener(EventListener):
+ def notify(self, client, event):
+ if event.command == "MODE":
+ self.activate_handlers(client, event)
+
standard = {
@@ -295,7 +306,8 @@ def notify(self, client, event):
"quit": QuitListener,
"part": PartListener,
"nick_change": NickChangeListener,
- "error": ErrorListener
+ "error": ErrorListener,
+ "mode": ModeListener,
}
@@ -434,7 +446,7 @@ def notify(self, client, event):
channel = event.params[1].lower()
names = event.params[2].strip().split(" ")
# TODO: This line below is wrong. It doesn't use name symbols.
- names = map(protocol.strip_name_symbol, names)
+ names = list(map(protocol.strip_name_symbol, names))
self._name_lists[channel].name_list.extend(names)
elif event.command == "RPL_ENDOFNAMES":
# <channel> :End of NAMES list
@@ -498,7 +510,7 @@ def notify(self, client, event):
elif event.command == "RPL_WHOISCHANNELS":
# <nick> :*( ( "@" / "+" ) <channel> " " )
channels = event.params[1].strip().split()
- channels = map(protocol.strip_name_symbol, channels)
+ channels = list(map(protocol.strip_name_symbol, channels))
self._whois_replies[event.params[0]].channels.extend(channels)
elif event.command == "RPL_WHOISSERVER":
# <nick> <server> :<server info>
View
0 ircutils/format.py → ircutils3/format.py
File renamed without changes.
View
0 ircutils/ident.py → ircutils3/ident.py
File renamed without changes.
View
4 ircutils/protocol.py → ircutils3/protocol.py
@@ -138,7 +138,7 @@ def is_nick(nick):
def filter_nick(nick):
""" Removes all of the invalid characters from a nick. """
- nick = filter(lambda ch:ch.isalnum() or ch in _special_chars, iter(nick))
+ nick = [ch for ch in iter(nick) if ch.isalnum() or ch in _special_chars]
if len(nick) == 0:
return None
return nick
@@ -167,7 +167,7 @@ def ip_to_ascii(ip_address):
def ascii_to_ip(ascii_ip_value):
""" Converts the integer value to a quad IP format. """
- ascii_ip_value = long(ascii_ip_value)
+ ascii_ip_value = int(ascii_ip_value)
return str(socket.inet_ntoa(struct.pack('!L', ascii_ip_value)))
View
0 ircutils/responses.py → ircutils3/responses.py
File renamed without changes.
View
47 setup.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
## ----------------------------------------------------------------------------#
## IRCUtils setup file.
## To install, type the following in console in this directory:
@@ -8,29 +8,30 @@
## To ensure that installation was a success, you may want to open up a Python
## console and try to import the package.
## ----------------------------------------------------------------------------#
-from distutils.core import setup
+from setuptools import setup
import os
readme_file = os.path.join(os.path.dirname(__file__), 'README')
-setup(name='ircutils',
- version='0.1.3',
- description='IRC framework and utilities. Great for bot creation.',
- long_description=open(readme_file).read(),
- author='Evan Fosmark',
- author_email='evan.fosmark@gmail.com',
- url='http://dev.guardedcode.com/projects/ircutils/',
- license="MIT/X11",
- platforms="Any",
- packages=['ircutils'],
- classifiers=[
- "Development Status :: 3 - Alpha",
- "Intended Audience :: Developers",
- "License :: OSI Approved :: MIT License",
- "Operating System :: OS Independent",
- "Programming Language :: Python",
- "Topic :: Communications :: Chat :: Internet Relay Chat",
- "Topic :: Software Development :: Libraries :: Application Frameworks",
- "Topic :: Software Development :: Libraries :: Python Modules"
- ]
- )
+setup(name='ircutils3',
+ version='0.2.2',
+ description='IRC framework and utilities. Great for bot creation.',
+ long_description=open(readme_file).read(),
+ author=['Christopher Koch', 'Evan Fosmark'],
+ author_email=['ch_koch@outlook.com', 'evan.fosmark@gmail.com'],
+ url='http://dev.guardedcode.com/projects/ircutils/',
+ license="MIT/X11",
+ platforms="Any",
+ packages=['ircutils3'],
+ classifiers=[
+ "Development Status :: 3 - Alpha",
+ "Intended Audience :: Developers",
+ "License :: OSI Approved :: MIT License",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python",
+ "Programming Language :: Python :: 3",
+ "Topic :: Communications :: Chat :: Internet Relay Chat",
+ "Topic :: Software Development :: Libraries :: Application Frameworks",
+ "Topic :: Software Development :: Libraries :: Python Modules"
+ ]
+ )

0 comments on commit a8c9525

Please sign in to comment.