51 # XXX: ugly hack |
51 # XXX: ugly hack |
52 timestamp_fmt = '%Y-%m-%d ' + self.timestamp_fmt |
52 timestamp_fmt = '%Y-%m-%d ' + self.timestamp_fmt |
53 |
53 |
54 else : |
54 else : |
55 timestamp_fmt = self.timestamp_fmt |
55 timestamp_fmt = self.timestamp_fmt |
56 |
56 |
57 # build timestamp |
57 # breakdown source |
58 timestamp = dtz.strftime(timestamp_fmt) |
58 source_nickname, source_username, source_hostname, source_chanflag = line.source |
|
59 target_nickname = line.target |
59 |
60 |
60 # format with dict |
61 # format with dict |
61 return template % dict( |
62 return template % dict( |
62 timestamp = timestamp, |
63 channel_name = line.channel.name, |
63 source = line.source, |
64 datetime = dtz.strftime('%a %b %d %H:%M:%S %Y'), |
64 data = line.data, |
65 timestamp = dtz.strftime(timestamp_fmt), |
|
66 source_nickname = source_nickname, |
|
67 source_username = source_username, |
|
68 source_hostname = source_hostname, |
|
69 source_chanflag = source_chanflag, |
|
70 target_nickname = target_nickname, |
|
71 message = line.data, |
65 ) |
72 ) |
66 |
73 |
67 def format_txt (self, lines, full_timestamps=False) : |
74 def format_txt (self, lines, full_timestamps=False) : |
68 """ |
75 """ |
69 Format given lines as plaintext. |
76 Format given lines as plaintext. |
118 url_link = xml.sax.saxutils.unescape(url_html) |
129 url_link = xml.sax.saxutils.unescape(url_html) |
119 |
130 |
120 return '<a href="%(url_link)s">%(url_html)s</a>' % dict(url_link=url_link, url_html=url_html) |
131 return '<a href="%(url_link)s">%(url_html)s</a>' % dict(url_link=url_link, url_html=url_html) |
121 |
132 |
122 return self.URL_REGEXP.sub(_encode_url, line) |
133 return self.URL_REGEXP.sub(_encode_url, line) |
123 |
134 |
|
135 def format_html (self, lines, **kwargs) : |
|
136 """ |
|
137 Just uses format_txt, but processes links, etc |
|
138 """ |
|
139 |
|
140 # format using IrssiTextFormatter |
|
141 for line, txt in self.format_txt(lines, **kwargs) : |
|
142 # escape HTML |
|
143 html = xml.sax.saxutils.escape(txt) |
|
144 |
|
145 # process links |
|
146 html = self._process_links(html) |
|
147 |
|
148 # yield |
|
149 yield line, html |
|
150 |
|
151 |
124 class IrssiTextFormatter (RSSFormatter, PILImageFormatter, LogFormatter) : |
152 class IrssiTextFormatter (RSSFormatter, PILImageFormatter, LogFormatter) : |
125 """ |
153 """ |
126 Implements format_txt for irssi-style output |
154 Implements format_txt for irssi-style output |
127 """ |
155 """ |
128 |
156 |
129 # format definitions by type |
157 # format definitions by type |
130 __FMT = { |
158 __FMT = { |
131 LogTypes.RAW : "%(timestamp)s %(data)s", |
159 LogTypes.RAW : "%(timestamp)s %(data)s", |
|
160 LogTypes.LOG_OPEN : "--- Log opened %(datetime)s", |
|
161 LogTypes.LOG_CLOSE : "--- Log closed %(datetime)s", |
|
162 |
|
163 LogTypes.MSG : "%(timestamp)s <%(source_chanflag)s%(source_nickname)s> %(message)s", |
|
164 LogTypes.NOTICE : "%(timestamp)s -%(source_nickname)s- %(message)s", |
|
165 LogTypes.ACTION : "%(timestamp)s * %(source_nickname)s %(message)s", |
|
166 |
|
167 LogTypes.JOIN : "%(timestamp)s -!- %(source_nickname)s [%(source_username)s@%(source_hostname)s] has joined %(channel_name)s", |
|
168 LogTypes.PART : "%(timestamp)s -!- %(source_nickname)s [%(source_username)s@%(source_hostname)s] has left %(channel_name)s [%(message)s]", |
|
169 LogTypes.KICK : "%(timestamp)s -!- %(target_nickname)s was kicked from %(channel_name)s by %(source_nickname)s [%(message)s]", |
|
170 LogTypes.MODE : "%(timestamp)s -!- mode/%(channel_name)s [%(message)s] by %(source_nickname)s", |
|
171 |
|
172 LogTypes.NICK : "%(timestamp)s -!- %(source_nickname)s is now known as %(target_nickname)s", |
|
173 LogTypes.QUIT : "%(timestamp)s -!- %(source_nickname)s [%(source_username)s@%(source_hostname)s] has quit [%(message)s]", |
|
174 |
|
175 LogTypes.TOPIC : "%(timestamp)s -!- %(source_nickname)s changed the topic of %(channel_name)s to: %(message)s", |
|
176 |
|
177 LogTypes.SELF_NOTICE: "%(timestamp)s -%(source_nickname)s- %(message)s", |
|
178 LogTypes.SELF_NICK : "%(timestamp)s -!- %(source_nickname)s is now known as %(target_nickname)s", |
132 } |
179 } |
133 |
180 |
134 def format_txt (self, lines, full_timestamps=False) : |
181 def format_txt (self, lines, full_timestamps=False) : |
135 # ...handle each line |
182 # ...handle each line |
136 for line in lines : |
183 for line in lines : |
137 # using __TYPES |
184 # using __TYPES |
138 yield line, self._format_line_text(line, self.__FMT, full_timestamps) |
185 yield line, self._format_line_text(line, self.__FMT, full_timestamps) |
139 |
186 |
140 class IrssiFormatter (IrssiTextFormatter, BaseHTMLFormatter) : |
187 class IrssiFormatter (BaseHTMLFormatter, IrssiTextFormatter) : |
141 """ |
188 """ |
142 Implements plain black-and-white irssi-style formatting |
189 Implements plain black-and-white irssi-style formatting |
143 """ |
190 """ |
144 |
191 |
145 # name |
192 # name |
146 name = 'irssi' |
193 name = 'irssi' |
147 title = "Irssi (plain)" |
194 title = "Irssi (plain)" |
148 |
195 |
149 # parameters |
196 class DebugFormatter (BaseHTMLFormatter) : |
150 html_fixedwidth = True |
197 """ |
151 |
198 Implements a raw debug-style formatting of LogLines |
152 def format_html (self, lines, **kwargs) : |
199 """ |
153 """ |
200 |
154 Just uses format_txt, but processes links, etc |
201 # name |
155 """ |
202 name = 'debug' |
156 |
203 title = "Raw debugging format" |
157 # format using IrssiTextFormatter |
204 |
158 for line, txt in self.format_txt(lines, **kwargs) : |
205 def format_txt (self, lines, full_timestamps=False) : |
159 # escape HTML |
206 # iterate |
160 html = xml.sax.saxutils.escape(txt) |
207 for line in lines : |
161 |
208 # just dump |
162 # process links |
209 yield line, repr(line) |
163 html = self._process_links(html) |
|
164 |
|
165 # yield |
|
166 yield line, html |
|
167 |
210 |
168 def by_name (name) : |
211 def by_name (name) : |
169 """ |
212 """ |
170 Lookup and return a class LogFormatter by name |
213 Lookup and return a class LogFormatter by name |
171 """ |
214 """ |