aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2012-03-03 11:19:43 -0500
committerW. Trevor King <wking@drexel.edu>2012-03-03 11:19:49 -0500
commit2ba27b00384c55ec7fe29e09ce2d2c3e8eeb0977 (patch)
treea99b42b49bad0ebce8ce076984533bb552a80522 /libbe
parent187bface721aec16800e612cc292c1fec4ee966b (diff)
downloadbugseverywhere-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.py14
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`).