diff options
author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-08-29 19:12:54 -0500 |
---|---|---|
committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-08-29 19:12:54 -0500 |
commit | 2ac420b331c0ff2eabc8eba2fe3ff6f035a0927e (patch) | |
tree | 874e51ec8b1f1821c9eb8dc4ab9dcde6440b7751 | |
parent | 6c1d9effa0efee0852dbc887622e05a3cc4f7f4b (diff) | |
parent | 8274b1524f0a5467da13d3ee32401aea5083b0e0 (diff) | |
download | uritemplates-2ac420b331c0ff2eabc8eba2fe3ff6f035a0927e.tar.gz |
Merge branch 'merge-with-uritemplate'
-rw-r--r-- | HISTORY.rst | 13 | ||||
-rw-r--r-- | docs/index.rst | 2 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | tests/test_uritemplate.py | 6 | ||||
-rw-r--r-- | uritemplate/__init__.py | 8 | ||||
-rw-r--r-- | uritemplate/api.py | 19 |
6 files changed, 43 insertions, 7 deletions
diff --git a/HISTORY.rst b/HISTORY.rst index 65f7132..6d85cf8 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,5 +1,14 @@ -Changelog -========= +Changelog - uritemplate +======================= + +2.0.0 - 2016-08-29 +------------------ + +- Merge uritemplate.py into uritemplate + + +Changelog - uritemplate.py +========================== 2.0.0 - 2016-08-20 ------------------ diff --git a/docs/index.rst b/docs/index.rst index b846d44..35776f0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -53,6 +53,8 @@ API .. autofunction:: uritemplate.partial +.. autofunction:: uritemplate.variables + .. autoclass:: uritemplate.URITemplate :members: @@ -7,7 +7,7 @@ packages = [ ] setup( - name="uritemplate.py", + name="uritemplate", version=__version__, description='URI templates', long_description="\n\n".join([open("README.rst").read(), diff --git a/tests/test_uritemplate.py b/tests/test_uritemplate.py index 26aeb72..b1abc96 100644 --- a/tests/test_uritemplate.py +++ b/tests/test_uritemplate.py @@ -1,5 +1,5 @@ from unittest import TestCase, main -from uritemplate import URITemplate, expand, partial +from uritemplate import URITemplate, expand, partial, variables from uritemplate import variable @@ -580,6 +580,10 @@ class TestAPI(TestCase): URITemplate('https://api.github.com/users/sigmavirus24{/other}') ) + def test_variables(self): + self.assertEqual(variables(self.uri), + URITemplate(self.uri).variable_names) + if __name__ == '__main__': main() diff --git a/uritemplate/__init__.py b/uritemplate/__init__.py index ad751c1..ab4bf1c 100644 --- a/uritemplate/__init__.py +++ b/uritemplate/__init__.py @@ -17,8 +17,10 @@ __author__ = 'Ian Cordasco' __license__ = 'Modified BSD or Apache License, Version 2.0' __copyright__ = 'Copyright 2013 Ian Cordasco' __version__ = '2.0.0' -__version_info__ = tuple(int(i) for i in __version__.split('.')) +__version_info__ = tuple(int(i) for i in __version__.split('.') if i.isdigit()) -from uritemplate.api import URITemplate, expand, partial # noqa: E402 +from uritemplate.api import ( + URITemplate, expand, partial, variables # noqa: E402 +) -__all__ = ('URITemplate', 'expand', 'partial') +__all__ = ('URITemplate', 'expand', 'partial', 'variables') diff --git a/uritemplate/api.py b/uritemplate/api.py index cbcec09..37c7c45 100644 --- a/uritemplate/api.py +++ b/uritemplate/api.py @@ -50,3 +50,22 @@ def partial(uri, var_dict=None, **kwargs): """ return URITemplate(uri).partial(var_dict, **kwargs) + + +def variables(uri): + """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 set(URITemplate(uri).variable_names) |