Skip to content

Commit

Permalink
Drop irc library as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwildor committed Oct 18, 2014
1 parent 2265225 commit 4a69122
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
34 changes: 30 additions & 4 deletions pyromancer/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import socket
import time

from irc.buffer import DecodingLineBuffer

from pyromancer import utils


Expand Down Expand Up @@ -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'):
Expand All @@ -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('')

Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
author='Gwildor Sok',
author_email='[email protected]',
url='https://github.com/Gwildor/Pyromancer',
install_requires=[
'irc'
],
install_requires=[],
classifiers=[
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
Expand Down

0 comments on commit 4a69122

Please sign in to comment.