Skip to content

Instantly share code, notes, and snippets.

@manasdk
Last active January 19, 2016 03:09
Show Gist options
  • Save manasdk/56d89e29d700f640637c to your computer and use it in GitHub Desktop.
Save manasdk/56d89e29d700f640637c to your computer and use it in GitHub Desktop.
In [42]: format = "acl {{a}} {{b}} {{c}}"
In [43]: format = "acl {{a}} {{b}} {{c}} {{d=1}}"
In [44]: param_stream = 'acl "AntOffice" "175.184.219.3" "10.0.0.9"'
In [45]: p = action_alias_utils.ActionAliasFormatParser(format, param_stream)
In [46]: p.get_extracted_param_value()
^\s*acl\s*["\']?(?P<a}}\s*["\']?(?P<b>(?:(?<=\').+?(?=\')|(?<=").+?(?=")|{.+?}|.+?))["\']?(?:\s*["\']?(?P<c>(?:(?<=\').+?(?=\')|(?<=").+?(?>(?:(?<=\').+?(?=\')|(?<=").+?(?=")|{.+?}|.+?))["\']?\s+)?\s*\s*$
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-46-b3174c03dc30> in <module>()
----> 1 p.get_extracted_param_value()
/mnt/st2repos/st2/st2common/st2common/models/utils/action_alias_utils.py in get_extracted_param_value(self)
80 # 2. Matched parameters
81 # 3. Extra parameters
---> 82 matched_stream = re.match(reg, self._param_stream, re.DOTALL)
83 if matched_stream:
84 values = matched_stream.groupdict()
/mnt/st2repos/st2/virtualenv/lib/python2.7/re.pyc in match(pattern, string, flags)
135 """Try to apply the pattern at the start of the string, returning
136 a match object, or None if no match was found."""
--> 137 return _compile(pattern, flags).match(string)
138
139 def search(pattern, string, flags=0):
/mnt/st2repos/st2/virtualenv/lib/python2.7/re.pyc in _compile(*key)
242 p = sre_compile.compile(pattern, flags)
243 except error, v:
--> 244 raise error, v # invalid expression
245 if not bypass_cache:
246 if len(_cache) >= _MAXCACHE:
error: bad character in group name 'a}}\\s*["\\\']?(?P<b'
In [47]: format = "acl {{a}} {{b}} {{c}}"
In [48]: p = action_alias_utils.ActionAliasFormatParser(format, param_stream)
In [49]: p.get_extracted_param_value()
^\s*acl\s*["\']?(?P<a>(?:(?<=\').+?(?=\')|(?<=").+?(?=")|{.+?}|.+?))["\']? \s*["\']?(?P<b>(?:(?<=\').+?(?=\')|(?<=").+?(?=")|{.+?}|.+?))["\']? \s*["\']?(?P<c>(?:(?<=\').+?(?=\')|(?<=").+?(?=")|{.+?}|.+?))["\']?\s*$
Out[49]: {'a': 'AntOffice', 'b': '175.184.219.3', 'c': '10.0.0.9'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment