Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Parse the variables of the template.
This returns all of the variable names in the URI Template.
:returns: Set of variable names
:rtype: set
Example::
variables('https://api.github.com{/end})
# => {'end'}
variables('https://api.github.com/repos{/username}{/repository}')
# => {'username', 'repository'}
"""
return OrderedSet(URITemplate(uri).variable_names)
def __eq__(self, other):
if isinstance(other, OrderedSet):
return len(self) == len(other) and list(self) == list(other)
return not self.isdisjoint(other)
def __init__(self, uri):
#: The original URI to be parsed.
self.uri = uri
#: A list of the variables in the URI. They are stored as
#: :class:`URIVariable`\ s
self.variables = [
URIVariable(m.groups()[0]) for m in template_re.finditer(self.uri)
]
#: A set of variable names in the URI.
self.variable_names = OrderedSet()
for variable in self.variables:
for name in variable.variable_names:
self.variable_names.add(name)