blob: edc9baee326da7d9989ccc4d898040e33de71548 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import re
keyword_rx = re.compile('^\$(\w+)\:\s+(\S*)\s*\$$')
# returns tuple (key, value)
# returns None if kwstring is not a keyword expansion
def extract_keyvalue(kwstring):
mo = keyword_rx.match(kwstring)
if mo is None: return None
try:
return mo.group(1,2)
except IndexError:
return None
def keywords(*kwstrings):
keyvalues = [extract_keyvalue(kws) for kws in kwstrings]
compacted_keyvalues = [kv for kv in keyvalues if kv is not None]
return dict(compacted_keyvalues)
|