summaryrefslogtreecommitdiff
path: root/coverage/misc.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/misc.py')
-rw-r--r--coverage/misc.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/coverage/misc.py b/coverage/misc.py
index d87a7b89..ad7b834f 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -281,6 +281,45 @@ def substitute_variables(text, variables=os.environ):
return text
+# Map chars to numbers for arcz_to_arcs
+_arcz_map = {'.': -1}
+_arcz_map.update(dict((c, ord(c) - ord('0')) for c in '123456789'))
+_arcz_map.update(dict(
+ (c, 10 + ord(c) - ord('A')) for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+))
+
+def arcz_to_arcs(arcz):
+ """Convert a compact textual representation of arcs to a list of pairs.
+
+ The text has space-separated pairs of letters. Period is -1, 1-9 are
+ 1-9, A-Z are 10 through 36. The resulting list is sorted regardless of
+ the order of the input pairs.
+
+ ".1 12 2." --> [(-1,1), (1,2), (2,-1)]
+
+ Minus signs can be included in the pairs:
+
+ "-11, 12, 2-5" --> [(-1,1), (1,2), (2,-5)]
+
+ """
+ arcs = []
+ for pair in arcz.split():
+ asgn = bsgn = 1
+ if len(pair) == 2:
+ a, b = pair
+ else:
+ assert len(pair) == 3
+ if pair[0] == '-':
+ _, a, b = pair
+ asgn = -1
+ else:
+ assert pair[1] == '-'
+ a, _, b = pair
+ bsgn = -1
+ arcs.append((asgn * _arcz_map[a], bsgn * _arcz_map[b]))
+ return sorted(arcs)
+
+
class BaseCoverageException(Exception):
"""The base of all Coverage exceptions."""
pass