Skip to content

Commit a7f0298

Browse files
authored
Merge pull request #6 from TotallyNotRobots/update-0.3
Merge and release 0.3
2 parents fb0d11a + 9a73658 commit a7f0298

File tree

15 files changed

+645
-96
lines changed

15 files changed

+645
-96
lines changed

.coveragerc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[report]
2+
exclude_lines =
3+
pragma: no cover
4+
def __repr__
5+
raise AssertionError
6+
raise NotImplementedError
7+
if __name__ == .__main__.:
8+
9+
[run]
10+
omit =
11+
tests/data/*
12+
tests/util/*

.travis.yml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
language: python
2+
dist: xenial
3+
sudo: true
24
python:
3-
- '3.4'
45
- '3.5'
56
- '3.6'
6-
- nightly
7+
- '3.7'
78
- pypy3
89
install:
910
- pip install -Ur requirements.txt
1011
script:
11-
- py.test . -v --cov . --cov-report term-missing
12+
- pytest
1213
after_success:
13-
- coveralls
14+
- codecov
1415
deploy:
1516
provider: pypi
1617
user: linuxdaemon
@@ -23,13 +24,3 @@ deploy:
2324
python: '3.6'
2425
env:
2526
- PYTHONPATH=.
26-
matrix:
27-
allow_failures:
28-
- python: "nightly"
29-
include:
30-
- python: '3.7'
31-
dist: xenial
32-
sudo: true
33-
- python: '3.8-dev'
34-
dist: xenial
35-
sudo: true

irclib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__all__ = ('commands', 'errors', 'parser', 'string', 'util')

irclib/commands.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from collections import Mapping
22

3+
__all__ = ('Command', 'client_commands')
4+
35

46
class Command:
57
def __init__(self, name, args=None, min_args=0, max_args=None):

irclib/errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
__all__ = ('ParseError',)
2+
3+
14
class ParseError(ValueError):
25
pass

irclib/parser.py

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
from irclib.errors import ParseError
1111

12+
__all__ = (
13+
'Cap', 'CapList', 'MessageTag', 'TagList', 'Prefix', 'ParamList', 'Message'
14+
)
15+
1216
TAGS_SENTINEL = '@'
1317
TAGS_SEP = ';'
1418
TAG_VALUE_SEP = '='
@@ -155,7 +159,15 @@ def parse(text):
155159
# Some networks (ie: freenode) send a trailing space in a CAP ACK
156160
stripped = text.strip()
157161

158-
return CapList(map(Cap.parse, stripped.split(CAP_SEP)))
162+
if not text:
163+
caps = []
164+
else:
165+
caps = (
166+
Cap.parse(s)
167+
for s in stripped.split(CAP_SEP)
168+
)
169+
170+
return CapList(caps)
159171

160172

161173
class MessageTag(Parseable):
@@ -251,29 +263,44 @@ def parse(text):
251263
class TagList(Parseable, dict):
252264
"""Object representing the list of message tags on a line"""
253265

254-
def __init__(self, tags):
266+
def __init__(self, tags=()):
255267
super().__init__((tag.name, tag) for tag in tags)
256268

257269
def __str__(self):
258270
return TAGS_SEP.join(map(str, self.values()))
259271

260-
def __eq__(self, other):
261-
if isinstance(other, str):
262-
return self == TagList.parse(other)
272+
@staticmethod
273+
def _cmp_type_map(obj):
274+
if isinstance(obj, str):
275+
return TagList.parse(obj)
276+
277+
if isinstance(obj, dict):
278+
sample = next(iter(obj.values()), None)
279+
if obj and (sample is None or isinstance(sample, str)):
280+
# Handle str -> str dict
281+
return TagList.from_dict(obj)
263282

264-
if isinstance(other, dict):
265-
return dict(self) == dict(other)
283+
# Handle str -> MessageTag dict
284+
return dict(obj)
285+
286+
if isinstance(obj, list):
287+
return TagList(obj)
266288

267289
return NotImplemented
268290

269-
def __ne__(self, other):
270-
if isinstance(other, str):
271-
return self != TagList.parse(other)
291+
def __eq__(self, other):
292+
obj = self._cmp_type_map(other)
293+
if obj is NotImplemented:
294+
return NotImplemented
272295

273-
if isinstance(other, dict):
274-
return dict(self) != dict(other)
296+
return dict(self) == dict(obj)
275297

276-
return NotImplemented
298+
def __ne__(self, other):
299+
obj = self._cmp_type_map(other)
300+
if obj is NotImplemented:
301+
return NotImplemented
302+
303+
return dict(self) != dict(obj)
277304

278305
@staticmethod
279306
def parse(text):
@@ -299,7 +326,7 @@ class Prefix(Parseable):
299326
Object representing the prefix of a line
300327
"""
301328

302-
def __init__(self, nick, user=None, host=None):
329+
def __init__(self, nick=None, user=None, host=None):
303330
self._nick = nick or ''
304331
self._user = user or ''
305332
self._host = host or ''
@@ -345,7 +372,7 @@ def __str__(self):
345372
return self.mask
346373

347374
def __bool__(self):
348-
return bool(self.nick)
375+
return any(self)
349376

350377
def __eq__(self, other):
351378
if isinstance(other, str):
@@ -374,10 +401,11 @@ def parse(text):
374401
:return: Parsed Object
375402
"""
376403
if not text:
377-
return Prefix('')
404+
return Prefix()
378405

379406
match = PREFIX_RE.match(text)
380-
if not match:
407+
if not match: # pragma: no cover
408+
# This should never trip, we are pretty lenient with prefixes
381409
raise ParseError("Invalid IRC prefix format")
382410

383411
nick, user, host = match.groups()
@@ -401,7 +429,9 @@ def __str__(self):
401429
if not self:
402430
return ''
403431

404-
if self.has_trail or PARAM_SEP in self[-1]:
432+
needs_trail = PARAM_SEP in self[-1] or self[-1].startswith(TRAIL_SENTINEL) or not self[-1]
433+
434+
if self.has_trail or needs_trail:
405435
return PARAM_SEP.join(self[:-1] + [TRAIL_SENTINEL + self[-1]])
406436

407437
return PARAM_SEP.join(self)

irclib/string.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import operator
66
from functools import wraps
77

8+
__all__ = ('Casemap', 'RFC1459', 'STRICT_RFC1459', 'ASCII', 'String')
9+
810

911
class Casemap(tuple):
1012
__slots__ = ()

irclib/util/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__all__ = ('compare', 'frozendict', 'numerics')

irclib/util/frozendict.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
__all__ = ('FrozenDict',)
2+
3+
14
class FrozenDict(dict):
25
__slots__ = ("__hash",)
36

irclib/util/numerics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from collections import namedtuple, Mapping
22

3+
__all__ = ('Numeric', 'numerics')
4+
35
Numeric = namedtuple('Numeric', 'name numeric')
46

57

0 commit comments

Comments
 (0)