aboutsummaryrefslogtreecommitdiff
path: root/uritemplate
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2013-05-11 17:33:23 -0400
committerIan Cordasco <graffatcolmingov@gmail.com>2013-05-11 17:35:23 -0400
commit00777a1c0bf671e0ca0f2fd0131f84b35848504a (patch)
tree50b4f739570ce7cd70627c9209568a64f5759a95 /uritemplate
parentbf456a3ba13dda2afbb4b5bc160da37bb6ab22b5 (diff)
downloaduritemplates-00777a1c0bf671e0ca0f2fd0131f84b35848504a.tar.gz
pep257 compliance
Diffstat (limited to 'uritemplate')
-rw-r--r--uritemplate/api.py1
-rw-r--r--uritemplate/template.py34
2 files changed, 26 insertions, 9 deletions
diff --git a/uritemplate/api.py b/uritemplate/api.py
index 5bbcc31..848f942 100644
--- a/uritemplate/api.py
+++ b/uritemplate/api.py
@@ -24,6 +24,7 @@ def expand(uri, var_dict=None, **kwargs):
.. note:: Passing values by both parts, will override values in
``var_dict``.
+
"""
t = URITemplate(uri)
return t.expand(var_dict, **kwargs)
diff --git a/uritemplate/template.py b/uritemplate/template.py
index 7f3f7c1..f92c3e5 100644
--- a/uritemplate/template.py
+++ b/uritemplate/template.py
@@ -23,8 +23,10 @@ template_re = re.compile('{([^\}]+)}')
class URITemplate(object):
- """The :class:`URITemplate <URITemplate>` object is the central object to
- uritemplate. This parses the template and will be used to expand it.
+
+ """This parses the template and will be used to expand it.
+
+ This is the most important object as the center of the API.
Example::
@@ -52,6 +54,7 @@ class URITemplate(object):
dictionaries.
"""
+
def __init__(self, uri):
self.uri = uri
self.variables = [
@@ -82,6 +85,7 @@ class URITemplate(object):
.. note:: Passing values by both parts, will override values in
``var_dict``.
+
"""
if not self.variables:
return self.uri
@@ -92,13 +96,16 @@ class URITemplate(object):
class URIVariable(object):
- """The :class:`URIVariable <URIVariable>` object validates everything
- underneath the Template object. It validates template expansions and will
- truncate length as decided by the template.
+
+ """This object validates everything inside the URITemplate object.
+
+ It validates template expansions and will truncate length as decided by
+ the template.
Please note that just like the :class:`URITemplate <URITemplate>`, this
object's ``__str__`` and ``__repr__`` methods do not return the same
information. Calling ``str(var)`` will return the original variable.
+
"""
operators = ('+', '#', '.', '/', ';', '?', '&', '|', '!', '@')
@@ -119,8 +126,14 @@ class URIVariable(object):
return self.original
def parse(self):
- """Parse the variable: find the operator, the set of safe characters,
- all the variables and the defaults.
+ """Parse the variable.
+
+ This finds the:
+ - operator,
+ - set of safe characters,
+ - variables, and
+ - defaults.
+
"""
if self.original[0] in URIVariable.operators:
self.operator = self.original[0]
@@ -150,7 +163,10 @@ class URIVariable(object):
self.vars.append((name, {'explode': explode, 'prefix': prefix}))
def expand(self, var_dict=None):
- """Expand the variable in question using ``var_dict`` and the
- parsed defaults.
+ """Expand the variable in question.
+
+ Using ``var_dict`` and the previously parsed defaults, expand this
+ variable and subvariables.
+
"""
var_dict = dict((k, quote(v)) for k, v in var_dict.items())