Skip to content

Commit

Permalink
Add parsing of messages from services (like ChanServ or Nickserv)
Browse files Browse the repository at this point in the history
  • Loading branch information
zertrin committed Nov 13, 2013
1 parent 439dcdc commit c3f9bd1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rezoirclogs/templates/macros.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* <b>{{ line.user | colored}}</b> {{ line.message | urlize}}
{%- elif line.type == 'status' -%}
-!- <b>{{ line.user | colored }}</b> {{ line.message }}
{%- elif line.type == 'service' -%}
-<b>{{ line.user | colored }}</b>- {{ line.message }}
{%- else -%}
{{ line }}
{%- endif -%}
{%- endmacro %}
{%- endmacro %}
19 changes: 19 additions & 0 deletions rezoirclogs/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ def test_status_empty(self):
self.assertEqual(m.type, "status")
self.assertEqual(m.message, "")

def test_service(self):
lines = [("01:53 -ChanServ([email protected])- Informations pour le canal #linux:", "service", "Informations pour le canal #linux:", 'ChanServ([email protected])', '01:53'),
("01:53:09 -ChanServ([email protected])- Informations pour le canal #linux:", "service", "Informations pour le canal #linux:", 'ChanServ([email protected])', '01:53:09')]
for line, expected_type, expected_message, expected_nick, expected_time in lines:
m = self._get_FUT(line)
self.assertEqual(m.type, expected_type)
self.assertEqual(m.message, expected_message)
self.assertEqual(m.user, expected_nick)
self.assertEqual(m.time, expected_time)
self.assertEqual(str(m), line)

def test_service_empty(self):
lines = ["12:11 -ChanServ([email protected])-",
"12:11:10 -ChanServ([email protected])-"]
for line in lines:
m = self._get_FUT(line)
self.assertEqual(m.type, "service")
self.assertEqual(m.message, "")

def test_unrecognized(self):
m = self._get_FUT("Ceci n'est pas une ligne de log")
self.assertEqual(m.type, "unrecognized")
Expand Down
1 change: 1 addition & 0 deletions rezoirclogs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __new__(cls, value):
(re.compile(r"(\d\d:\d\d(?::\d\d)??) <%s> ?(.*)" % _nick_regex), 'normal'),
(re.compile(r"(\d\d:\d\d(?::\d\d)??) *\* %s ?(.*)" % _nick_regex), 'me'),
(re.compile(r"(\d\d:\d\d(?::\d\d)??) -!- %s ?(.*)" % _nick_regex), 'status'),
(re.compile(r"(\d\d:\d\d(?::\d\d)??) -(.+)?- ?(.*)"), 'service'),
]

def populate(self):
Expand Down

0 comments on commit c3f9bd1

Please sign in to comment.