Skip to content

Commit 0476220

Browse files
author
Alexander Smishlajev
committed
added RegExpOption
1 parent a7a33cd commit 0476220

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

roundup/configuration.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Roundup Issue Tracker configuration support
22
#
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 $
44
#
55
__docformat__ = "restructuredtext"
66

7+
import ConfigParser
78
import getopt
89
import imp
9-
import os
10-
import time
11-
import ConfigParser
1210
import logging, logging.config
11+
import os
12+
import re
1313
import sys
14+
import time
1415

1516
import roundup.date
1617

@@ -423,6 +424,37 @@ def str2value(self, value):
423424
"Timezone name or numeric hour offset required")
424425
return value
425426

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+
426458
### Main configuration layout.
427459
# Config is described as a sequence of sections,
428460
# where each section name is followed by a sequence
@@ -653,19 +685,20 @@ def str2value(self, value):
653685
"will match an issue for the interval after the issue's\n"
654686
"creation or last activity. The interval is a standard\n"
655687
"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*",
657689
"Regular expression matching a single reply or forward\n"
658690
"prefix prepended by the mailer. This is explicitly\n"
659691
"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?-----$",
661694
"Regular expression matching start of an original message\n"
662695
"if quoted the in body."),
663-
(Option, "sign_re", "^[>|\s]*-- ?$",
696+
(RegExpOption, "sign_re", "^[>|\s]*-- ?$",
664697
"Regular expression matching the start of a signature\n"
665698
"in the message body."),
666-
(Option, "eol_re", r"[\r\n]+",
699+
(RegExpOption, "eol_re", r"[\r\n]+",
667700
"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]+",
669702
"Regular expression matching a blank line."),
670703
), "Roundup Mail Gateway options"),
671704
("nosy", (

0 commit comments

Comments
 (0)