diff options
author | W. Trevor King <wking@drexel.edu> | 2012-03-03 11:19:43 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2012-03-03 11:19:49 -0500 |
commit | 2ba27b00384c55ec7fe29e09ce2d2c3e8eeb0977 (patch) | |
tree | a99b42b49bad0ebce8ce076984533bb552a80522 /libbe | |
parent | 187bface721aec16800e612cc292c1fec4ee966b (diff) | |
download | bugseverywhere-2ba27b00384c55ec7fe29e09ce2d2c3e8eeb0977.tar.gz |
Make ID expansion less strict for comment text.
This avoids errors if the comment text references a repository that
you don't have locally.
Diffstat (limited to 'libbe')
-rw-r--r-- | libbe/util/id.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libbe/util/id.py b/libbe/util/id.py index 8dc6075..9a90af5 100644 --- a/libbe/util/id.py +++ b/libbe/util/id.py @@ -471,17 +471,24 @@ class IDreplacer (object): -------- short_to_long_text, long_to_short_text """ - def __init__(self, bugdirs, replace_fn, wrap=True): + def __init__(self, bugdirs, replace_fn, wrap=True, strict=True): self.bugdirs = bugdirs self.replace_fn = replace_fn self.wrap = wrap + self.strict = strict + def __call__(self, match): ids = [] for m in match.groups(): if m == None: m = '' ids.append(m) - replacement = self.replace_fn(self.bugdirs, ''.join(ids)) + try: + replacement = self.replace_fn(self.bugdirs, ''.join(ids)) + except (MultipleIDMatches, NoIDMatches, InvalidIDStructure): + if self.strict: + raise + replacement = ''.join(ids) if self.wrap == True: return '#%s#' % replacement return replacement @@ -496,7 +503,8 @@ def short_to_long_text(bugdirs, text): short_to_long_user : conversion on a single ID long_to_short_text : inverse """ - return re.sub(REGEXP, IDreplacer(bugdirs, short_to_long_user), text) + return re.sub( + REGEXP, IDreplacer(bugdirs, short_to_long_user, strict=False), text) def long_to_short_text(bugdirs, text): """Convert long user IDs to short user IDs in text (see :class:`ID`). |