49 |
49 |
50 # subexpression parts |
50 # subexpression parts |
51 _TS = r'(?P<timestamp>\S+)' |
51 _TS = r'(?P<timestamp>\S+)' |
52 _NICK = r'(?P<nickname>.+?)' |
52 _NICK = r'(?P<nickname>.+?)' |
53 _NICK2 = r'(?P<nickname2>.+?)' |
53 _NICK2 = r'(?P<nickname2>.+?)' |
|
54 _TARGET = r'(?P<target>.+?)' |
54 _CHAN = r'(?P<channel>.+?)' |
55 _CHAN = r'(?P<channel>.+?)' |
|
56 _CHAN2 = r'(?P<channel2>.+?)' |
55 _USERHOST = r'(?P<username>.*?)@(?P<hostname>.*?)' |
57 _USERHOST = r'(?P<username>.*?)@(?P<hostname>.*?)' |
56 _MSG = r'(?P<message>.*)' |
58 _MSG = r'(?P<message>.*)' |
57 |
59 |
58 # regular expressions for matching lines, by type |
60 # regular expressions for matching lines, by type |
59 TYPE_EXPRS = ( |
61 TYPE_EXPRS = ( |
62 ( LogTypes.MSG, _TS + r' <(?P<flags>.)' + _NICK + '> ' + _MSG ), |
64 ( LogTypes.MSG, _TS + r' <(?P<flags>.)' + _NICK + '> ' + _MSG ), |
63 ( LogTypes.NOTICE, _TS + r' -' + _NICK + ':' + _CHAN + '- ' + _MSG ), |
65 ( LogTypes.NOTICE, _TS + r' -' + _NICK + ':' + _CHAN + '- ' + _MSG ), |
64 ( LogTypes.ACTION, _TS + r' \* ' + _NICK + ' ' + _MSG ), |
66 ( LogTypes.ACTION, _TS + r' \* ' + _NICK + ' ' + _MSG ), |
65 ( LogTypes.JOIN, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has joined ' + _CHAN ), |
67 ( LogTypes.JOIN, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has joined ' + _CHAN ), |
66 ( LogTypes.PART, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has left ' + _CHAN + ' \[(?P<message>.*?)\]' ), |
68 ( LogTypes.PART, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has left ' + _CHAN + ' \[(?P<message>.*?)\]' ), |
67 ( LogTypes.KICK, _TS + r' -!- ' + _NICK2 + ' was kicked from ' + _CHAN + ' by ' + _NICK + ' \[(?P<message>.*?)\]' ), |
69 ( LogTypes.KICK, _TS + r' -!- ' + _TARGET + ' was kicked from ' + _CHAN + ' by ' + _NICK + ' \[(?P<message>.*?)\]' ), |
68 ( LogTypes.MODE, _TS + r' -!- mode/' + _CHAN + ' \[(?P<mode>.+?)\] by (?P<nickname>\S+)' ), |
70 ( LogTypes.MODE, _TS + r' -!- mode/' + _CHAN + ' \[(?P<mode>.+?)\] by (?P<nickname>\S+)' ), |
69 ( LogTypes.NICK, _TS + r' -!- ' + _NICK + ' is now known as (?P<nickname2>\S+)' ), |
71 ( LogTypes.NICK, _TS + r' -!- ' + _NICK + ' is now known as (?P<target>\S+)' ), |
70 ( LogTypes.QUIT, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has quit \[(?P<message>.*?)\]' ), |
72 ( LogTypes.QUIT, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has quit \[(?P<message>.*?)\]' ), |
71 ( LogTypes.TOPIC, _TS + r' -!- ' + _NICK + ' changed the topic of ' + _CHAN + ' to: (?P<topic>.*)' ), |
73 ( LogTypes.TOPIC, _TS + r' -!- (' + _NICK + ' changed the topic of ' + _CHAN + ' to: (?P<topic>.*)|Topic unset by ' + _NICK2 + ' on ' + _CHAN2 + ')' ), |
72 |
74 |
73 ( LogTypes.SELF_NOTICE, _TS + r' \[notice\(' + _CHAN + '\)\] ' + _MSG ), |
75 ( LogTypes.SELF_NOTICE, _TS + r' \[notice\(' + _CHAN + '\)\] ' + _MSG ), |
74 ( LogTypes.SELF_NICK, _TS + r' -!- You\'re now known as (?P<nickname2>\S+)' ), |
76 ( LogTypes.SELF_NICK, _TS + r' -!- You\'re now known as (?P<target>\S+)' ), |
75 ) |
77 ) |
76 |
78 |
77 # precompile |
79 # precompile |
78 TYPE_REGEXES = [(type, re.compile(expr)) for type, expr in TYPE_EXPRS] |
80 TYPE_REGEXES = [(type, re.compile(expr)) for type, expr in TYPE_EXPRS] |
79 |
81 |
125 raise LogParseError(offset, line, "No timestamp") |
127 raise LogParseError(offset, line, "No timestamp") |
126 |
128 |
127 # now localize with timezone |
129 # now localize with timezone |
128 dtz = self.tz.localize(dt) |
130 dtz = self.tz.localize(dt) |
129 |
131 |
|
132 # channel, currently unused |
|
133 channel_name = (groups.get('channel') or groups.get('channel2')) |
|
134 |
130 # source |
135 # source |
131 source = (groups.get('nickname'), groups.get('username'), groups.get('hostname'), groups.get('flags')) |
136 source = (groups.get('nickname') or groups.get('nickname2'), groups.get('username'), groups.get('hostname'), groups.get('flags')) |
132 |
137 |
133 # target |
138 # target |
134 target = groups.get('nickname2') |
139 target = groups.get('target') |
135 |
140 |
136 # data |
141 # data |
137 if 'message' in groups : |
142 if 'message' in groups : |
138 data = groups['message'] |
143 data = groups['message'] |
139 |
144 |