|
1 | 1 | # Roundup Issue Tracker configuration support |
2 | 2 | # |
3 | | -# $Id: configuration.py,v 1.41 2007-03-26 04:04:42 richard Exp $ |
| 3 | +# $Id: configuration.py,v 1.42 2007-04-03 06:36:08 a1s Exp $ |
4 | 4 | # |
5 | 5 | __docformat__ = "restructuredtext" |
6 | 6 |
|
| 7 | +import ConfigParser |
7 | 8 | import getopt |
8 | 9 | import imp |
9 | | -import os |
10 | | -import time |
11 | | -import ConfigParser |
12 | 10 | import logging, logging.config |
| 11 | +import os |
| 12 | +import re |
13 | 13 | import sys |
| 14 | +import time |
14 | 15 |
|
15 | 16 | import roundup.date |
16 | 17 |
|
@@ -423,6 +424,37 @@ def str2value(self, value): |
423 | 424 | "Timezone name or numeric hour offset required") |
424 | 425 | return value |
425 | 426 |
|
| 427 | +class RegExpOption(Option): |
| 428 | + |
| 429 | + """Regular Expression option (value is Regular Expression Object)""" |
| 430 | + |
| 431 | + class_description = "Value is Python Regular Expression (UTF8-encoded)." |
| 432 | + |
| 433 | + RE_TYPE = type(re.compile("")) |
| 434 | + |
| 435 | + def __init__(self, config, section, setting, |
| 436 | + default=NODEFAULT, description=None, aliases=None, |
| 437 | + flags=0, |
| 438 | + ): |
| 439 | + self.flags = flags |
| 440 | + Option.__init__(self, config, section, setting, default, |
| 441 | + description, aliases) |
| 442 | + |
| 443 | + def _value2str(self, value): |
| 444 | + assert isinstance(value, self.RE_TYPE) |
| 445 | + return value.pattern |
| 446 | + |
| 447 | + def str2value(self, value): |
| 448 | + if not isinstance(value, unicode): |
| 449 | + value = str(value) |
| 450 | + # if it is 7-bit ascii, use it as string, |
| 451 | + # otherwise convert to unicode. |
| 452 | + try: |
| 453 | + value.decode("ascii") |
| 454 | + except UnicodeError: |
| 455 | + value = value.decode("utf-8") |
| 456 | + return re.compile(value, self.flags) |
| 457 | + |
426 | 458 | ### Main configuration layout. |
427 | 459 | # Config is described as a sequence of sections, |
428 | 460 | # where each section name is followed by a sequence |
@@ -653,19 +685,20 @@ def str2value(self, value): |
653 | 685 | "will match an issue for the interval after the issue's\n" |
654 | 686 | "creation or last activity. The interval is a standard\n" |
655 | 687 | "Roundup interval."), |
656 | | - (Option, "refwd_re", "\s*\W?\s*(fw|fwd|re|aw|sv|ang)\W\s*", |
| 688 | + (RegExpOption, "refwd_re", "\s*\W?\s*(fw|fwd|re|aw|sv|ang)\W\s*", |
657 | 689 | "Regular expression matching a single reply or forward\n" |
658 | 690 | "prefix prepended by the mailer. This is explicitly\n" |
659 | 691 | "stripped from the subject during parsing."), |
660 | | - (Option, "origmsg_re", "^[>|\s]*-----\s?Original Message\s?-----$", |
| 692 | + (RegExpOption, "origmsg_re", |
| 693 | + "^[>|\s]*-----\s?Original Message\s?-----$", |
661 | 694 | "Regular expression matching start of an original message\n" |
662 | 695 | "if quoted the in body."), |
663 | | - (Option, "sign_re", "^[>|\s]*-- ?$", |
| 696 | + (RegExpOption, "sign_re", "^[>|\s]*-- ?$", |
664 | 697 | "Regular expression matching the start of a signature\n" |
665 | 698 | "in the message body."), |
666 | | - (Option, "eol_re", r"[\r\n]+", |
| 699 | + (RegExpOption, "eol_re", r"[\r\n]+", |
667 | 700 | "Regular expression matching end of line."), |
668 | | - (Option, "blankline_re", r"[\r\n]+\s*[\r\n]+", |
| 701 | + (RegExpOption, "blankline_re", r"[\r\n]+\s*[\r\n]+", |
669 | 702 | "Regular expression matching a blank line."), |
670 | 703 | ), "Roundup Mail Gateway options"), |
671 | 704 | ("nosy", ( |
|
0 commit comments