aboutsummaryrefslogtreecommitdiff
path: root/uritemplate
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2013-07-25 20:27:36 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2013-07-25 20:27:36 -0500
commit797d4869e8b376a46ab45bc0a2f962bbd7b84bd3 (patch)
tree2fb36f5ca326be8ab3dda1d88c86275dc0362993 /uritemplate
parentb2874e1e44c2ba800c3ad067c30909ec0c466603 (diff)
downloaduritemplates-797d4869e8b376a46ab45bc0a2f962bbd7b84bd3.tar.gz
Refactoring URIVariable
Split part of URIVariable.__init__ into post_parse
Diffstat (limited to 'uritemplate')
-rw-r--r--uritemplate/template.py39
1 files changed, 23 insertions, 16 deletions
diff --git a/uritemplate/template.py b/uritemplate/template.py
index cc7382b..518878b 100644
--- a/uritemplate/template.py
+++ b/uritemplate/template.py
@@ -155,22 +155,7 @@ class URIVariable(object):
self.defaults = {}
# Parse the variable itself.
self.parse()
-
- self.start = self.join_str = self.operator
- if self.operator == '+':
- self.start = ''
- if self.operator in ('+', '#', ''):
- self.join_str = ','
- if self.operator == '#':
- self.start = '#'
- if self.operator == '?':
- self.start = '?'
- self.join_str = '&'
- if self.operator == '&':
- self.start = self.join_str = '&'
-
- if self.operator in ('+', '#'):
- self.safe = URIVariable.reserved
+ self.post_parse()
def __repr__(self):
return 'URIVariable(%s)' % self
@@ -223,6 +208,28 @@ class URIVariable(object):
self.variable_names = [name for (name, _) in self.variables]
+ def post_parse(self):
+ """Set ``start``, ``join_str`` and ``safe`` attributes.
+
+ After parsing the variable, we need to set up these attributes and it
+ only makes sense to do it in a more easily testable way.
+ """
+ self.start = self.join_str = self.operator
+ if self.operator == '+':
+ self.start = ''
+ if self.operator in ('+', '#', ''):
+ self.join_str = ','
+ if self.operator == '#':
+ self.start = '#'
+ if self.operator == '?':
+ self.start = '?'
+ self.join_str = '&'
+ if self.operator == '&':
+ self.start = self.join_str = '&'
+
+ if self.operator in ('+', '#'):
+ self.safe = URIVariable.reserved
+
def _query_expansion(self, name, value, explode, prefix):
"""Expansion method for the '?' and '&' operators."""
if value is None or (len(value) == 0 and value != ""):