Mercurial > p > roundup > code
comparison roundup/configuration.py @ 3835:b66615f3007b
added RegExpOption
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Tue, 03 Apr 2007 06:36:08 +0000 |
| parents | 14ec78618bd5 |
| children | f4e8dc583256 |
comparison
equal
deleted
inserted
replaced
| 3834:8068eb6c704e | 3835:b66615f3007b |
|---|---|
| 1 # Roundup Issue Tracker configuration support | 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 __docformat__ = "restructuredtext" | 5 __docformat__ = "restructuredtext" |
| 6 | 6 |
| 7 import ConfigParser | |
| 7 import getopt | 8 import getopt |
| 8 import imp | 9 import imp |
| 10 import logging, logging.config | |
| 9 import os | 11 import os |
| 12 import re | |
| 13 import sys | |
| 10 import time | 14 import time |
| 11 import ConfigParser | |
| 12 import logging, logging.config | |
| 13 import sys | |
| 14 | 15 |
| 15 import roundup.date | 16 import roundup.date |
| 16 | 17 |
| 17 # XXX i don't think this module needs string translation, does it? | 18 # XXX i don't think this module needs string translation, does it? |
| 18 | 19 |
| 420 roundup.date.get_timezone(value) | 421 roundup.date.get_timezone(value) |
| 421 except KeyError: | 422 except KeyError: |
| 422 raise OptionValueError(self, value, | 423 raise OptionValueError(self, value, |
| 423 "Timezone name or numeric hour offset required") | 424 "Timezone name or numeric hour offset required") |
| 424 return value | 425 return value |
| 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) | |
| 425 | 457 |
| 426 ### Main configuration layout. | 458 ### Main configuration layout. |
| 427 # Config is described as a sequence of sections, | 459 # Config is described as a sequence of sections, |
| 428 # where each section name is followed by a sequence | 460 # where each section name is followed by a sequence |
| 429 # of Option definitions. Each Option definition | 461 # of Option definitions. Each Option definition |
| 651 "designator [prefix]. \"never\" turns off matching.\n" | 683 "designator [prefix]. \"never\" turns off matching.\n" |
| 652 "\"creation + interval\" or \"activity + interval\"\n" | 684 "\"creation + interval\" or \"activity + interval\"\n" |
| 653 "will match an issue for the interval after the issue's\n" | 685 "will match an issue for the interval after the issue's\n" |
| 654 "creation or last activity. The interval is a standard\n" | 686 "creation or last activity. The interval is a standard\n" |
| 655 "Roundup interval."), | 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 "Regular expression matching a single reply or forward\n" | 689 "Regular expression matching a single reply or forward\n" |
| 658 "prefix prepended by the mailer. This is explicitly\n" | 690 "prefix prepended by the mailer. This is explicitly\n" |
| 659 "stripped from the subject during parsing."), | 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 "Regular expression matching start of an original message\n" | 694 "Regular expression matching start of an original message\n" |
| 662 "if quoted the in body."), | 695 "if quoted the in body."), |
| 663 (Option, "sign_re", "^[>|\s]*-- ?$", | 696 (RegExpOption, "sign_re", "^[>|\s]*-- ?$", |
| 664 "Regular expression matching the start of a signature\n" | 697 "Regular expression matching the start of a signature\n" |
| 665 "in the message body."), | 698 "in the message body."), |
| 666 (Option, "eol_re", r"[\r\n]+", | 699 (RegExpOption, "eol_re", r"[\r\n]+", |
| 667 "Regular expression matching end of line."), | 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 "Regular expression matching a blank line."), | 702 "Regular expression matching a blank line."), |
| 670 ), "Roundup Mail Gateway options"), | 703 ), "Roundup Mail Gateway options"), |
| 671 ("nosy", ( | 704 ("nosy", ( |
| 672 (RunDetectorOption, "messages_to_author", "no", | 705 (RunDetectorOption, "messages_to_author", "no", |
| 673 "Send nosy messages to the author of the message.", | 706 "Send nosy messages to the author of the message.", |
