Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def state_max_repeat(self, value):
"""Parse repeatable parts."""
min_, max_, value = value
value = [val for val in Traverser(value, self.groups)]
if not min_ and max_:
for val in value:
if isinstance(val, required):
min_ = 1
break
for val in value * min_:
yield val
def state_in(self, value):
"""Parse ranges."""
value = [val for val in Traverser(value, self.groups)]
if not value or not value[0]:
for val in self.literals - set(value):
return (yield val)
yield value[0]
def state_subpattern(self, value):
"""Parse subpatterns."""
num, *_, parsed = value
if num in self.groups:
return (yield required(self.groups[num]))
yield from Traverser(parsed, groups=self.groups)
def url(self, *subgroups, query=None, **groups):
"""Build URL."""
parsed = re.sre_parse.parse(self._pattern.pattern)
subgroups = {n:str(v) for n, v in enumerate(subgroups, 1)}
groups_ = dict(parsed.pattern.groupdict)
subgroups.update({
groups_[k0]: str(v0)
for k0, v0 in groups.items()
if k0 in groups_
})
url = ''.join(str(val) for val in Traverser(parsed, subgroups))
return self._append_query(url, query)