aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2013-05-19 15:16:11 -0400
committerIan Cordasco <graffatcolmingov@gmail.com>2013-05-19 15:16:11 -0400
commit2179d28af11225242da41435d695fafc56b265cf (patch)
tree257e6d13e3ed8e89c1de4b7325ad3d72023c2767
parent3e10fb4f7946dfd1348a3927d5ece3a7429b112d (diff)
downloaduritemplates-2179d28af11225242da41435d695fafc56b265cf.tar.gz
Make the variable names publicly available.
-rw-r--r--uritemplate/__init__.py6
-rw-r--r--uritemplate/template.py20
2 files changed, 20 insertions, 6 deletions
diff --git a/uritemplate/__init__.py b/uritemplate/__init__.py
index 60559e7..4384367 100644
--- a/uritemplate/__init__.py
+++ b/uritemplate/__init__.py
@@ -3,7 +3,9 @@
uritemplate
===========
-The URI templating library for Humans
+The URI templating library for humans.
+
+See http://uritemplate.rtfd.org/ for documentation
:copyright: (c) 2013 Ian Cordasco
:license: Modified BSD, see LICENSE for more details
@@ -14,7 +16,7 @@ __title__ = 'uritemplate'
__author__ = 'Ian Cordasco'
__license__ = 'Modified BSD'
__copyright__ = 'Copyright 2013 Ian Cordasco'
-__version__ = '0.0.1'
+__version__ = '0.1.1'
__version_info__ = tuple(int(i) for i in __version__.split('.'))
from uritemplate.api import URITemplate, expand
diff --git a/uritemplate/template.py b/uritemplate/template.py
index e01f77a..f40aa3d 100644
--- a/uritemplate/template.py
+++ b/uritemplate/template.py
@@ -57,10 +57,17 @@ class URITemplate(object):
"""
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 = set()
+ for variable in self.variables:
+ self.variable_names.update(variable.variable_names)
def __repr__(self):
return 'URITemplate(%s)' % self
@@ -127,7 +134,8 @@ class URIVariable(object):
self.original = var
self.operator = ''
self.safe = ''
- self.vars = []
+ self.variables = []
+ self.variable_names = []
self.defaults = {}
self.parse()
@@ -192,7 +200,11 @@ class URIVariable(object):
if default_val:
self.defaults[name] = default_val
- self.vars.append((name, {'explode': explode, 'prefix': prefix}))
+ self.variables.append(
+ (name, {'explode': explode, 'prefix': prefix})
+ )
+
+ self.variable_names = [name for (name, _) in self.variables]
def _query_expansion(self, name, value, explode, prefix):
"""Expansion method for the '?' and '&' operators."""
@@ -354,7 +366,7 @@ class URIVariable(object):
"""
return_values = []
- for name, opts in self.vars:
+ for name, opts in self.variables:
value = var_dict.get(name, None)
if not value and value != '' and name in self.defaults:
value = self.defaults[name]
@@ -382,7 +394,7 @@ class URIVariable(object):
self.original: self.start + self.join_str.join(return_values)
}
- return {}
+ return {self.original: None}
def is_list_of_tuples(value):