diff --git a/.travis.yml b/.travis.yml index 2a9002a..f2f6dee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ python: - "3.3" - "3.4" # command to install dependencies -install: "pip install irc pytest-cov coveralls" +install: "pip install pytest-cov coveralls" # command to run tests script: "py.test --cov-config .coveragerc --cov-report term-missing --cov pyromancer pyromancer/test" after_success: diff --git a/README.md b/README.md index d12667e..517057d 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,9 @@ You can also return a `Timer` instance, or specify a callable as the second item ### Using a database +Using a database requires [SQLAlchemy][2]. + + [2]: http://www.sqlalchemy.org [3]: http://docs.sqlalchemy.org/en/latest/core/engines.html?highlight=create_engine#sqlalchemy.create_engine [4]: http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative.html#sqlalchemy.ext.declarative.declarative_base [5]: http://docs.sqlalchemy.org/en/latest/orm/session.html @@ -236,15 +239,6 @@ def timers(match): return 'Timer count: {}', session.query(Test).count() ``` -### Dependencies - -* [irc][1] -* [SQLAlchemy][2], if you want to enable the use of a database. - - - [1]: https://pypi.python.org/pypi/irc - [2]: http://www.sqlalchemy.org - ### Support Python 2.7 and 3.0 - 3.4 are supported. Note that development occurs on Python 3. @@ -261,7 +255,9 @@ Python 2.7 and 3.0 - 3.4 are supported. Note that development occurs on Python 3 * Add integrated database support. * Add command module which tracks channels and users. * Change color code parameter in message formatting to `c` (was `k` by mistake). +* Dropped [irc][1] as a dependency. * Switch to MIT license. +[1]: https://pypi.python.org/pypi/irc ##### Yet to do for 1.0: * Clean up code and raise test coverage. diff --git a/pyromancer/objects.py b/pyromancer/objects.py index 90f5aa2..3b03eca 100644 --- a/pyromancer/objects.py +++ b/pyromancer/objects.py @@ -4,8 +4,6 @@ import socket import time -from irc.buffer import DecodingLineBuffer - from pyromancer import utils @@ -136,6 +134,35 @@ def __getattr__(self, item): 'installed packages'.format(item)) +class LineBuffer(object): + """Line buffer based on irc library's DecodingLineBuffer. + + See https://bitbucket.org/jaraco/irc + """ + line_sep_exp = re.compile(b'\r?\n') + + def __init__(self, encoding='utf-8'): + self.buffer = b'' + self.encoding = encoding + + def feed(self, bytes): + self.buffer += bytes + + def lines(self): + lines = self.line_sep_exp.split(self.buffer) + # save the last, unfinished, possibly empty line + self.buffer = lines.pop() + + for line in lines: + yield line.decode(self.encoding, 'strict') + + def __iter__(self): + return self.lines() + + def __len__(self): + return len(self.buffer) + + class Connection(object): def __init__(self, host, port, encoding='utf8'): @@ -144,8 +171,7 @@ def __init__(self, host, port, encoding='utf8'): self.socket.setblocking(False) self.encoding = encoding - self.buffer = DecodingLineBuffer() - self.buffer.encoding = self.encoding + self.buffer = LineBuffer(self.encoding) self.me = User('') diff --git a/setup.py b/setup.py index b3c37e0..1d8d7f9 100644 --- a/setup.py +++ b/setup.py @@ -16,9 +16,7 @@ author='Gwildor Sok', author_email='gwildorsok@gmail.com', url='https://github.com/Gwildor/Pyromancer', - install_requires=[ - 'irc' - ], + install_requires=[], classifiers=[ 'Intended Audience :: Developers', 'Intended Audience :: Information Technology',