paul@0 | 1 | # -*- coding: iso-8859-1 -*- |
paul@0 | 2 | """ |
paul@0 | 3 | MoinMoin - MoinShare library |
paul@0 | 4 | |
paul@17 | 5 | @copyright: 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk> |
paul@34 | 6 | @copyright: 2003-2006 Edgewall Software |
paul@34 | 7 | @copyright: 2006 MoinMoin:AlexanderSchremmer |
paul@0 | 8 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@0 | 9 | """ |
paul@0 | 10 | |
paul@17 | 11 | from ContentTypeSupport import getContentPreferences |
paul@33 | 12 | from DateSupport import getCurrentTime, getDateTimeFromRFC2822 |
paul@0 | 13 | from MoinSupport import * |
paul@37 | 14 | from MoinMoin.support.htmlmarkup import HTMLParseError, HTMLSanitizer, Markup |
paul@15 | 15 | from MoinMoin import wikiutil |
paul@33 | 16 | from email.parser import Parser |
paul@37 | 17 | from codecs import getwriter |
paul@0 | 18 | |
paul@25 | 19 | try: |
paul@25 | 20 | from cStringIO import StringIO |
paul@25 | 21 | except ImportError: |
paul@25 | 22 | from StringIO import StringIO |
paul@25 | 23 | |
paul@16 | 24 | _getFragments = getFragments |
paul@0 | 25 | |
paul@0 | 26 | __version__ = "0.1" |
paul@0 | 27 | |
paul@0 | 28 | # More Moin 1.9 compatibility functions. |
paul@0 | 29 | |
paul@0 | 30 | def has_member(request, groupname, username): |
paul@0 | 31 | if hasattr(request.dicts, "has_member"): |
paul@0 | 32 | return request.dicts.has_member(groupname, username) |
paul@0 | 33 | else: |
paul@0 | 34 | return username in request.dicts.get(groupname, []) |
paul@0 | 35 | |
paul@3 | 36 | # Fragments employ a "moinshare" attribute. |
paul@3 | 37 | |
paul@3 | 38 | fragment_attribute = "moinshare" |
paul@2 | 39 | |
paul@16 | 40 | def getFragments(s): |
paul@25 | 41 | |
paul@25 | 42 | "Return all fragments in 's' having the MoinShare fragment attribute." |
paul@25 | 43 | |
paul@2 | 44 | fragments = [] |
paul@16 | 45 | for format, attributes, body in _getFragments(s): |
paul@16 | 46 | if attributes.has_key(fragment_attribute): |
paul@16 | 47 | fragments.append((format, attributes, body)) |
paul@2 | 48 | return fragments |
paul@2 | 49 | |
paul@9 | 50 | def getPreferredOutputTypes(request, mimetypes): |
paul@9 | 51 | |
paul@9 | 52 | """ |
paul@9 | 53 | Using the 'request', perform content negotiation, obtaining mimetypes common |
paul@9 | 54 | to the fragment (given by 'mimetypes') and the client (found in the Accept |
paul@9 | 55 | header). |
paul@9 | 56 | """ |
paul@9 | 57 | |
paul@9 | 58 | accept = getHeader(request, "Accept", "HTTP") |
paul@12 | 59 | if accept: |
paul@12 | 60 | prefs = getContentPreferences(accept) |
paul@12 | 61 | return prefs.get_preferred_types(mimetypes) |
paul@12 | 62 | else: |
paul@12 | 63 | return mimetypes |
paul@9 | 64 | |
paul@9 | 65 | def getUpdatedTime(metadata): |
paul@9 | 66 | |
paul@9 | 67 | """ |
paul@9 | 68 | Return the last updated time based on the given 'metadata', using the |
paul@9 | 69 | current time if no explicit last modified time is specified. |
paul@9 | 70 | """ |
paul@9 | 71 | |
paul@9 | 72 | # NOTE: We could attempt to get the last edit time of a fragment. |
paul@9 | 73 | |
paul@9 | 74 | latest_timestamp = metadata.get("last-modified") |
paul@9 | 75 | if latest_timestamp: |
paul@33 | 76 | return latest_timestamp |
paul@9 | 77 | else: |
paul@33 | 78 | return getCurrentTime() |
paul@9 | 79 | |
paul@30 | 80 | # Entry/update classes. |
paul@30 | 81 | |
paul@30 | 82 | class Update: |
paul@30 | 83 | |
paul@30 | 84 | "A feed update entry." |
paul@30 | 85 | |
paul@30 | 86 | def __init__(self): |
paul@30 | 87 | self.title = None |
paul@30 | 88 | self.link = None |
paul@30 | 89 | self.content = None |
paul@30 | 90 | self.content_type = None |
paul@30 | 91 | self.updated = None |
paul@30 | 92 | |
paul@30 | 93 | # Page-related attributes. |
paul@30 | 94 | |
paul@30 | 95 | self.fragment = None |
paul@30 | 96 | self.preferred = None |
paul@30 | 97 | |
paul@33 | 98 | # Message-related attributes. |
paul@33 | 99 | |
paul@34 | 100 | self.message_number = None |
paul@33 | 101 | self.parts = None |
paul@33 | 102 | |
paul@34 | 103 | # Message- and page-related attributes. |
paul@34 | 104 | |
paul@34 | 105 | self.page = None |
paul@34 | 106 | |
paul@40 | 107 | # Identification. |
paul@40 | 108 | |
paul@40 | 109 | self.path = [] |
paul@40 | 110 | |
paul@40 | 111 | def unique_id(self): |
paul@40 | 112 | return "moinshare-tab-%s-%s" % (self.message_number, "-".join(map(str, self.path))) |
paul@40 | 113 | |
paul@30 | 114 | def __cmp__(self, other): |
paul@30 | 115 | if self.updated is None and other.updated is not None: |
paul@30 | 116 | return 1 |
paul@30 | 117 | elif self.updated is not None and other.updated is None: |
paul@30 | 118 | return -1 |
paul@30 | 119 | else: |
paul@30 | 120 | return cmp(self.updated, other.updated) |
paul@30 | 121 | |
paul@40 | 122 | def copy(self, part_number=None): |
paul@40 | 123 | update = Update() |
paul@40 | 124 | update.title = self.title |
paul@40 | 125 | update.link = self.link |
paul@40 | 126 | update.updated = self.updated |
paul@40 | 127 | update.fragment = self.fragment |
paul@40 | 128 | update.preferred = self.preferred |
paul@40 | 129 | update.message_number = self.message_number |
paul@40 | 130 | update.page = self.page |
paul@40 | 131 | update.path = self.path[:] |
paul@40 | 132 | if part_number is not None: |
paul@40 | 133 | update.path.append(part_number) |
paul@40 | 134 | return update |
paul@40 | 135 | |
paul@30 | 136 | # Update retrieval from pages. |
paul@30 | 137 | |
paul@30 | 138 | def getUpdatesFromPage(page, request): |
paul@25 | 139 | |
paul@25 | 140 | """ |
paul@30 | 141 | Get updates from the given 'page' using the 'request'. A list of update |
paul@30 | 142 | objects is returned. |
paul@25 | 143 | """ |
paul@25 | 144 | |
paul@25 | 145 | updates = [] |
paul@25 | 146 | |
paul@25 | 147 | # NOTE: Use the updated datetime from the page for updates. |
paul@25 | 148 | # NOTE: The published and updated details would need to be deduced from |
paul@25 | 149 | # NOTE: the page history instead of being taken from the page as a whole. |
paul@25 | 150 | |
paul@25 | 151 | metadata = getMetadata(page) |
paul@25 | 152 | updated = getUpdatedTime(metadata) |
paul@25 | 153 | |
paul@25 | 154 | # Get the fragment regions for the page. |
paul@25 | 155 | |
paul@25 | 156 | for n, (format, attributes, body) in enumerate(getFragments(page.get_raw_body())): |
paul@25 | 157 | |
paul@33 | 158 | update = Update() |
paul@33 | 159 | |
paul@25 | 160 | # Produce a fragment identifier. |
paul@25 | 161 | # NOTE: Choose a more robust identifier where none is explicitly given. |
paul@25 | 162 | |
paul@30 | 163 | update.fragment = attributes.get("fragment", str(n)) |
paul@30 | 164 | update.title = attributes.get("summary", "Update #%d" % n) |
paul@25 | 165 | |
paul@25 | 166 | # Get the preferred content types available for the fragment. |
paul@25 | 167 | |
paul@30 | 168 | update.preferred = getPreferredOutputTypes(request, getOutputTypes(request, format)) |
paul@25 | 169 | |
paul@25 | 170 | # Try and obtain some suitable content for the entry. |
paul@25 | 171 | # NOTE: Could potentially get a summary for the fragment. |
paul@25 | 172 | |
paul@30 | 173 | update.content = None |
paul@25 | 174 | |
paul@30 | 175 | if "text/html" in update.preferred: |
paul@25 | 176 | parser_cls = getParserClass(request, format) |
paul@25 | 177 | |
paul@25 | 178 | if format == "html": |
paul@30 | 179 | update.content = body |
paul@39 | 180 | elif hasattr(parser_cls, "formatForOutputType"): |
paul@39 | 181 | update.content = formatTextForOutputType(body, request, parser_cls, "text/html") |
paul@25 | 182 | else: |
paul@25 | 183 | fmt = request.html_formatter |
paul@25 | 184 | fmt.setPage(page) |
paul@30 | 185 | update.content = formatText(body, request, fmt, parser_cls) |
paul@30 | 186 | |
paul@32 | 187 | update.content_type = "text/html" |
paul@25 | 188 | |
paul@34 | 189 | update.page = page |
paul@37 | 190 | |
paul@37 | 191 | # NOTE: The anchor would be supported in the page, but this requires |
paul@37 | 192 | # NOTE: formatter modifications for the regions providing updates. |
paul@37 | 193 | |
paul@37 | 194 | update.link = page.url(request, anchor=update.fragment) |
paul@30 | 195 | update.updated = updated |
paul@30 | 196 | |
paul@30 | 197 | updates.append(update) |
paul@25 | 198 | |
paul@25 | 199 | return updates |
paul@25 | 200 | |
paul@33 | 201 | # Update retrieval from message stores. |
paul@33 | 202 | |
paul@33 | 203 | def getUpdatesFromStore(page, request): |
paul@33 | 204 | |
paul@33 | 205 | """ |
paul@33 | 206 | Get updates from the message store associated with the given 'page' using |
paul@33 | 207 | the 'request'. A list of update objects is returned. |
paul@33 | 208 | """ |
paul@33 | 209 | |
paul@33 | 210 | updates = [] |
paul@33 | 211 | |
paul@33 | 212 | metadata = getMetadata(page) |
paul@33 | 213 | updated = getUpdatedTime(metadata) |
paul@33 | 214 | |
paul@33 | 215 | store = ItemStore(page, "messages", "message-locks") |
paul@33 | 216 | |
paul@33 | 217 | for n, message_text in enumerate(iter(store)): |
paul@46 | 218 | update = getUpdateFromMessageText(message_text, n) |
paul@34 | 219 | update.page = page |
paul@33 | 220 | updates.append(update) |
paul@33 | 221 | |
paul@33 | 222 | return updates |
paul@33 | 223 | |
paul@46 | 224 | def getUpdateFromMessageText(message_text, message_number): |
paul@46 | 225 | |
paul@46 | 226 | "Return an update for the given 'message_text' and 'message_number'." |
paul@46 | 227 | |
paul@46 | 228 | update = Update() |
paul@46 | 229 | message = Parser().parse(StringIO(message_text)) |
paul@46 | 230 | |
paul@46 | 231 | # Produce a fragment identifier. |
paul@46 | 232 | |
paul@46 | 233 | update.fragment = update.updated = getDateTimeFromRFC2822(message.get("date")) |
paul@46 | 234 | update.title = message.get("subject", "Update #%d" % message_number) |
paul@46 | 235 | |
paul@46 | 236 | update.message_number = message_number |
paul@46 | 237 | |
paul@46 | 238 | update.content, update.content_type, update.parts = getUpdateContentFromPart(message) |
paul@46 | 239 | return update |
paul@46 | 240 | |
paul@40 | 241 | def getUpdateContentFromPart(part): |
paul@40 | 242 | |
paul@40 | 243 | """ |
paul@40 | 244 | Return decoded content, the content type and any subparts in a tuple for a |
paul@40 | 245 | given 'part'. |
paul@40 | 246 | """ |
paul@40 | 247 | |
paul@40 | 248 | # Determine whether the part has several representations. |
paul@40 | 249 | |
paul@40 | 250 | # For a single part, use it as the update content. |
paul@40 | 251 | |
paul@40 | 252 | if not part.is_multipart(): |
paul@40 | 253 | content, content_type = getPartContent(part) |
paul@40 | 254 | return content, content_type, None |
paul@40 | 255 | |
paul@40 | 256 | # For a collection of related parts, use the first as the update content |
paul@40 | 257 | # and assume that the formatter will reference the other parts. |
paul@40 | 258 | |
paul@40 | 259 | elif part.get_content_subtype() == "related": |
paul@40 | 260 | main_part = part.get_payload()[0] |
paul@40 | 261 | content, content_type = getPartContent(main_part) |
paul@40 | 262 | return content, content_type, [main_part] |
paul@40 | 263 | |
paul@46 | 264 | # Encrypted content cannot be meaningfully separated. |
paul@46 | 265 | |
paul@46 | 266 | elif part.get_content_subtype() == "encrypted": |
paul@46 | 267 | return part.as_string(), part.get_content_type(), None |
paul@46 | 268 | |
paul@40 | 269 | # Otherwise, just obtain the parts for separate display. |
paul@40 | 270 | |
paul@40 | 271 | else: |
paul@40 | 272 | return None, part.get_content_type(), part.get_payload() |
paul@40 | 273 | |
paul@40 | 274 | def getPartContent(part): |
paul@40 | 275 | |
paul@40 | 276 | "Decode the 'part', returning the decoded payload and the content type." |
paul@40 | 277 | |
paul@40 | 278 | charset = part.get_content_charset() |
paul@40 | 279 | payload = part.get_payload(decode=True) |
paul@40 | 280 | return (charset and unicode(payload, charset) or payload), part.get_content_type() |
paul@40 | 281 | |
paul@40 | 282 | def getUpdateFromPart(parent, part, part_number): |
paul@40 | 283 | |
paul@40 | 284 | "Using the 'parent' update, return an update object for the given 'part'." |
paul@40 | 285 | |
paul@40 | 286 | update = parent.copy(part_number) |
paul@40 | 287 | update.content, update.content_type, update.parts = getUpdateContentFromPart(part) |
paul@40 | 288 | return update |
paul@40 | 289 | |
paul@46 | 290 | def getUpdatesForFormatting(update): |
paul@46 | 291 | |
paul@46 | 292 | "Get a list of updates for formatting given 'update'." |
paul@46 | 293 | |
paul@46 | 294 | updates = [] |
paul@46 | 295 | |
paul@46 | 296 | # Handle multipart/alternative and other non-related multiparts. |
paul@46 | 297 | |
paul@46 | 298 | if update.parts: |
paul@46 | 299 | for n, part in enumerate(update.parts): |
paul@46 | 300 | update_part = getUpdateFromPart(update, part, n) |
paul@46 | 301 | updates += getUpdatesForFormatting(update_part) |
paul@46 | 302 | else: |
paul@46 | 303 | updates.append(update) |
paul@46 | 304 | |
paul@46 | 305 | return updates |
paul@46 | 306 | |
paul@46 | 307 | # Update formatting. |
paul@46 | 308 | |
paul@46 | 309 | def getFormattedUpdate(update, request, fmt): |
paul@46 | 310 | |
paul@46 | 311 | """ |
paul@46 | 312 | Return the formatted form of the given 'update' using the given 'request' |
paul@46 | 313 | and 'fmt'. |
paul@46 | 314 | """ |
paul@46 | 315 | |
paul@46 | 316 | # NOTE: Some control over the HTML and XHTML should be exercised. |
paul@46 | 317 | |
paul@46 | 318 | if update.content: |
paul@46 | 319 | if update.content_type == "text/html" and update.message_number is not None: |
paul@46 | 320 | parsers = [get_make_parser(update.page, update.message_number)] |
paul@46 | 321 | else: |
paul@46 | 322 | parsers = getParsersForContentType(request.cfg, update.content_type) |
paul@46 | 323 | |
paul@46 | 324 | if parsers: |
paul@46 | 325 | for parser_cls in parsers: |
paul@46 | 326 | if hasattr(parser_cls, "formatForOutputType"): |
paul@46 | 327 | return formatTextForOutputType(update.content, request, parser_cls, "text/html") |
paul@46 | 328 | else: |
paul@46 | 329 | return formatText(update.content, request, fmt, parser_cls=parser_cls) |
paul@46 | 330 | break |
paul@46 | 331 | else: |
paul@46 | 332 | return None |
paul@46 | 333 | else: |
paul@46 | 334 | return None |
paul@46 | 335 | |
paul@46 | 336 | def formatUpdate(update, request, fmt): |
paul@46 | 337 | |
paul@46 | 338 | "Format the given 'update' using the given 'request' and 'fmt'." |
paul@46 | 339 | |
paul@46 | 340 | result = [] |
paul@46 | 341 | append = result.append |
paul@46 | 342 | |
paul@46 | 343 | updates = getUpdatesForFormatting(update) |
paul@46 | 344 | single = len(updates) == 1 |
paul@46 | 345 | |
paul@46 | 346 | # Format some navigation tabs. |
paul@46 | 347 | |
paul@46 | 348 | if not single: |
paul@46 | 349 | append(fmt.div(on=1, css_class="moinshare-alternatives")) |
paul@46 | 350 | |
paul@46 | 351 | first = True |
paul@46 | 352 | |
paul@46 | 353 | for update_part in updates: |
paul@46 | 354 | append(fmt.url(1, "#%s" % update_part.unique_id())) |
paul@46 | 355 | append(fmt.text(update_part.content_type)) |
paul@46 | 356 | append(fmt.url(0)) |
paul@46 | 357 | |
paul@46 | 358 | first = False |
paul@46 | 359 | |
paul@46 | 360 | append(fmt.div(on=0)) |
paul@46 | 361 | |
paul@46 | 362 | # Format the content. |
paul@46 | 363 | |
paul@46 | 364 | first = True |
paul@46 | 365 | |
paul@46 | 366 | for update_part in updates: |
paul@46 | 367 | |
paul@46 | 368 | # Encapsulate each alternative if many exist. |
paul@46 | 369 | |
paul@46 | 370 | if not single: |
paul@46 | 371 | css_class = first and "moinshare-default" or "moinshare-other" |
paul@46 | 372 | append(fmt.div(on=1, css_class="moinshare-alternative %s" % css_class, id=update_part.unique_id())) |
paul@46 | 373 | |
paul@46 | 374 | # Include the content. |
paul@46 | 375 | |
paul@46 | 376 | append(formatUpdatePart(update_part, request, fmt)) |
paul@46 | 377 | |
paul@46 | 378 | if not single: |
paul@46 | 379 | append(fmt.div(on=0)) |
paul@46 | 380 | |
paul@46 | 381 | first = False |
paul@46 | 382 | |
paul@46 | 383 | return "".join(result) |
paul@46 | 384 | |
paul@46 | 385 | def formatUpdatePart(update, request, fmt): |
paul@46 | 386 | |
paul@46 | 387 | "Format the given 'update' using the given 'request' and 'fmt'." |
paul@46 | 388 | |
paul@46 | 389 | _ = request.getText |
paul@46 | 390 | |
paul@46 | 391 | result = [] |
paul@46 | 392 | append = result.append |
paul@46 | 393 | |
paul@46 | 394 | # Encapsulate the content. |
paul@46 | 395 | |
paul@46 | 396 | append(fmt.div(on=1, css_class="moinshare-content")) |
paul@46 | 397 | text = getFormattedUpdate(update, request, fmt) |
paul@46 | 398 | if text: |
paul@46 | 399 | append(text) |
paul@46 | 400 | else: |
paul@46 | 401 | append(fmt.text(_("Update cannot be shown for content of type %s.") % update.content_type)) |
paul@46 | 402 | append(fmt.div(on=0)) |
paul@46 | 403 | |
paul@46 | 404 | return "".join(result) |
paul@46 | 405 | |
paul@31 | 406 | # Source management. |
paul@31 | 407 | |
paul@31 | 408 | def getUpdateSources(pagename, request): |
paul@31 | 409 | |
paul@31 | 410 | "Return the update sources from the given 'pagename' using the 'request'." |
paul@31 | 411 | |
paul@31 | 412 | sources = {} |
paul@31 | 413 | |
paul@31 | 414 | source_definitions = getWikiDict(pagename, request) |
paul@31 | 415 | |
paul@31 | 416 | if source_definitions: |
paul@31 | 417 | for name, value in source_definitions.items(): |
paul@31 | 418 | sources[name] = getSourceParameters(value) |
paul@31 | 419 | |
paul@31 | 420 | return sources |
paul@31 | 421 | |
paul@31 | 422 | def getSourceParameters(source_definition): |
paul@31 | 423 | |
paul@31 | 424 | "Return the parameters from the given 'source_definition' string." |
paul@31 | 425 | |
paul@43 | 426 | return parseDictEntry(source_definition, ("type", "location")) |
paul@31 | 427 | |
paul@34 | 428 | # HTML parsing support. |
paul@34 | 429 | |
paul@34 | 430 | class IncomingHTMLSanitizer(HTMLSanitizer): |
paul@34 | 431 | |
paul@34 | 432 | "An HTML parser that rewrites references to attachments." |
paul@34 | 433 | |
paul@34 | 434 | def __init__(self, out, request, page, message_number): |
paul@34 | 435 | HTMLSanitizer.__init__(self, out) |
paul@34 | 436 | self.request = request |
paul@34 | 437 | self.message_number = message_number |
paul@34 | 438 | self.page = page |
paul@34 | 439 | |
paul@34 | 440 | def rewrite_reference(self, ref): |
paul@34 | 441 | if ref.startswith("cid:"): |
paul@34 | 442 | part = ref[len("cid:"):] |
paul@34 | 443 | action_link = self.page.url(self.request, { |
paul@34 | 444 | "action" : "ReadMessage", "doit" : "1", |
paul@34 | 445 | "message" : self.message_number, "part" : part |
paul@34 | 446 | }) |
paul@34 | 447 | return action_link |
paul@34 | 448 | else: |
paul@34 | 449 | return ref |
paul@34 | 450 | |
paul@34 | 451 | def handle_starttag(self, tag, attrs): |
paul@34 | 452 | new_attrs = [] |
paul@34 | 453 | for attrname, attrvalue in attrs: |
paul@34 | 454 | if attrname in self.uri_attrs: |
paul@34 | 455 | new_attrs.append((attrname, self.rewrite_reference(attrvalue))) |
paul@34 | 456 | else: |
paul@34 | 457 | new_attrs.append((attrname, attrvalue)) |
paul@34 | 458 | HTMLSanitizer.handle_starttag(self, tag, new_attrs) |
paul@34 | 459 | |
paul@34 | 460 | class IncomingMarkup(Markup): |
paul@34 | 461 | |
paul@34 | 462 | "A special markup processor for incoming HTML." |
paul@34 | 463 | |
paul@34 | 464 | def sanitize(self, request, page, message_number): |
paul@37 | 465 | out = getwriter("utf-8")(StringIO()) |
paul@34 | 466 | sanitizer = IncomingHTMLSanitizer(out, request, page, message_number) |
paul@34 | 467 | sanitizer.feed(self.stripentities(keepxmlentities=True)) |
paul@37 | 468 | return IncomingMarkup(unicode(out.getvalue(), "utf-8")) |
paul@34 | 469 | |
paul@34 | 470 | class IncomingHTMLParser: |
paul@34 | 471 | |
paul@34 | 472 | "Filters and rewrites incoming HTML content." |
paul@34 | 473 | |
paul@34 | 474 | def __init__(self, raw, request, **kw): |
paul@34 | 475 | self.raw = raw |
paul@34 | 476 | self.request = request |
paul@34 | 477 | self.message_number = None |
paul@34 | 478 | self.page = None |
paul@34 | 479 | |
paul@34 | 480 | def format(self, formatter, **kw): |
paul@34 | 481 | |
paul@34 | 482 | "Send the text." |
paul@34 | 483 | |
paul@34 | 484 | try: |
paul@34 | 485 | self.request.write(formatter.rawHTML(IncomingMarkup(self.raw).sanitize(self.request, self.page, self.message_number))) |
paul@34 | 486 | except HTMLParseError, e: |
paul@34 | 487 | self.request.write(formatter.sysmsg(1) + |
paul@34 | 488 | formatter.text(u'HTML parsing error: %s in "%s"' % (e.msg, |
paul@34 | 489 | self.raw.splitlines()[e.lineno - 1].strip())) + |
paul@34 | 490 | formatter.sysmsg(0)) |
paul@34 | 491 | |
paul@34 | 492 | class MakeIncomingHTMLParser: |
paul@34 | 493 | |
paul@34 | 494 | "A class that makes parsers configured for messages." |
paul@34 | 495 | |
paul@34 | 496 | def __init__(self, page, message_number): |
paul@34 | 497 | |
paul@34 | 498 | "Initialise with state that is used to configure instantiated parsers." |
paul@34 | 499 | |
paul@34 | 500 | self.message_number = message_number |
paul@34 | 501 | self.page = page |
paul@34 | 502 | |
paul@34 | 503 | def __call__(self, *args, **kw): |
paul@34 | 504 | parser = IncomingHTMLParser(*args, **kw) |
paul@34 | 505 | parser.message_number = self.message_number |
paul@34 | 506 | parser.page = self.page |
paul@34 | 507 | return parser |
paul@34 | 508 | |
paul@34 | 509 | def get_make_parser(page, message_number): |
paul@34 | 510 | |
paul@34 | 511 | """ |
paul@34 | 512 | Return a callable that will return a parser configured for the message from |
paul@34 | 513 | the given 'page' with the given 'message_number'. |
paul@34 | 514 | """ |
paul@34 | 515 | |
paul@34 | 516 | return MakeIncomingHTMLParser(page, message_number) |
paul@34 | 517 | |
paul@0 | 518 | # vim: tabstop=4 expandtab shiftwidth=4 |