[Pymoul-svn] SF.net SVN: pymoul: [292] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-05-24 17:41:18
|
Revision: 292
http://pymoul.svn.sourceforge.net/pymoul/?rev=292&view=rev
Author: tiran
Date: 2007-05-24 10:41:19 -0700 (Thu, 24 May 2007)
Log Message:
-----------
Enhanced formatter
Modified Paths:
--------------
pymoul/trunk/src/moul/chatrelay/io.py
pymoul/trunk/src/moul/file/chatlog.py
Modified: pymoul/trunk/src/moul/chatrelay/io.py
===================================================================
--- pymoul/trunk/src/moul/chatrelay/io.py 2007-05-24 17:19:06 UTC (rev 291)
+++ pymoul/trunk/src/moul/chatrelay/io.py 2007-05-24 17:41:19 UTC (rev 292)
@@ -24,15 +24,34 @@
import os
from moul.file.chatlog import ChatlogParser
-from moul.file.chatlog import ChatLineError
-from moul.file.chatlog import CHAT_PRIVMSG
+from moul.file.chatlog import *
class NullFormatter(object):
"""A formatter that doesn't change the msg
"""
def format(self, msg):
- return msg
+ return str(msg)
+class MOULLogFormatter(NullFormatter):
+ """Formatter for MOUL
+ """
+
+ def __init__(self, skipprivate=True):
+ self.skipprivate = skipprivate
+
+ def format(self, msg):
+ if self.skipprivate and msg.typ & CHAT_PRIVMSG:
+ result = None
+ elif msg.typ == CHAT_PRIVMSGTO:
+ result = "-> %s" % msg
+ elif msg.typ == CHAT_PRIVMSGFROM:
+ result = "<- %s" % msg
+ elif msg.typ == CHAT_ACTION:
+ result = "* %s" % msg
+ if msg.important:
+ result = "%B%s" msg
+ return str(msg)
+
class LogFileReader(object):
"""Read log file
"""
@@ -67,15 +86,7 @@
lines = data.split(os.linesep)
# XXX - KISS, don't check for imcomplete lines
for line in ChatlogParser(lines):
- if isinstance(ChatLineError):
- self._fifo.append("PARSER ERROR: " + line)
- else:
- if line.typ & CHAT_PRIVMSG:
- continue
- elif line.important:
- self._fifo.append("*** " + line)
- else:
- self._fifo.append(line)
+ self._fifo.append(line)
def __iter__(self):
self._read()
@@ -99,4 +110,6 @@
def log(self, msg):
msg = self._fmt.format(msg)
+ if not msg:
+ return
self._client.say(self._channel, msg)
Modified: pymoul/trunk/src/moul/file/chatlog.py
===================================================================
--- pymoul/trunk/src/moul/file/chatlog.py 2007-05-24 17:19:06 UTC (rev 291)
+++ pymoul/trunk/src/moul/file/chatlog.py 2007-05-24 17:41:19 UTC (rev 292)
@@ -42,6 +42,7 @@
from moul.file.utils import fileModTime
# Chat line types
+CHAT_UNKNOWN = -1
CHAT_START = 1 << 0
CHAT_STOP = 1 << 1
CHAT_ERROR = 1 << 2
@@ -355,12 +356,11 @@
def parse(self, line):
mo = CHAT_RE.match(line)
if mo is None:
- self.error(line)
- return
+ return ChatLine(line, (1970, 1, 1, 0, 0, 0), CHAT_UNKNOWN)
d = mo.groupdict()
date = (self._year, int(d['M']), int(d['D']),
int(d['h']), int(d['m']), int(d['s']))
- typ = None
+ typ = CHAT_UNKNOWN
msg = d['msg']
info = {}
important = False
@@ -368,7 +368,7 @@
typ = CHAT_MSG
mo = MSG_RE.match(msg)
if mo is None:
- return ChatLineError(line)
+ return ChatLine(msg, dte, CHAT_UNKNOWN)
info = mo.groupdict()
else:
if msg == CHATLOG_START:
@@ -394,10 +394,7 @@
if user:
if user in USER_IMPORTANT:
important = True
- if typ is not None:
- return ChatLine(msg, date, typ, important, info)
- else:
- return ChatLineError(line)
+ return ChatLine(msg, date, typ, important, info)
def __iter__(self):
for line in self._iterable:
@@ -416,11 +413,3 @@
def asDatetime(self):
return datetime(*self.date)
-
-class ChatLineError(unicode):
- def __new__(cls, ustr):
- self = unicode.__new__(cls, ustr)
- return self
-
- def __nonzero(self):
- return False
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|