summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Ballestrini <russell.ballestrini@gmail.com>2017-05-06 20:15:40 -0400
committerGitHub <noreply@github.com>2017-05-06 20:15:40 -0400
commit203101c06c61a80d1023f1d21302eceae5f66e81 (patch)
tree41b5e8da197d52d42883594b176d52f7f694f235
parentab8c57811d904377416c2786670ecf0e81d8ca33 (diff)
downloadpyramid-203101c06c61a80d1023f1d21302eceae5f66e81.tar.gz
pyramid-203101c06c61a80d1023f1d21302eceae5f66e81.tar.bz2
pyramid-203101c06c61a80d1023f1d21302eceae5f66e81.zip
Update url.py | Refactor parse_url_overrides
Refactor parse_url_overrides: * pop values with default if key is missing * change conditionals to test for truth * prevent throwing an exception if passing keyword with default value * test if anchor starts with '#' before blindly adding it
-rw-r--r--pyramid/url.py42
1 files changed, 15 insertions, 27 deletions
diff --git a/pyramid/url.py b/pyramid/url.py
index 9634f61da..7b88c385c 100644
--- a/pyramid/url.py
+++ b/pyramid/url.py
@@ -34,40 +34,28 @@ ANCHOR_SAFE = QUERY_SAFE
def parse_url_overrides(kw):
"""Parse special arguments passed when generating urls.
- The supplied dictionary is mutated, popping arguments as necessary.
- Returns a 6-tuple of the format ``(app_url, scheme, host, port,
- qs, anchor)``.
+ The supplied dictionary is mutated when we pop arguments.
+ Returns a 6-tuple of the format:
+
+ ``(app_url, scheme, host, port, qs, anchor)``.
"""
- anchor = ''
- qs = ''
- app_url = None
- host = None
- scheme = None
- port = None
-
- if '_query' in kw:
- query = kw.pop('_query')
+ app_url = kw.pop('_app_url', None)
+ scheme = kw.pop('_scheme', None)
+ host = kw.pop('_host', None)
+ port = kw.pop('_port', None)
+ qs = query = kw.pop('_query', '')
+ anchor = kw.pop('_anchor', '')
+
+ if query:
if isinstance(query, string_types):
qs = '?' + url_quote(query, QUERY_SAFE)
elif query:
qs = '?' + urlencode(query, doseq=True)
- if '_anchor' in kw:
- anchor = kw.pop('_anchor')
+ if anchor:
anchor = url_quote(anchor, ANCHOR_SAFE)
- anchor = '#' + anchor
-
- if '_app_url' in kw:
- app_url = kw.pop('_app_url')
-
- if '_host' in kw:
- host = kw.pop('_host')
-
- if '_scheme' in kw:
- scheme = kw.pop('_scheme')
-
- if '_port' in kw:
- port = kw.pop('_port')
+ if anchor.startswith('#') == False:
+ anchor = '#' + anchor
return app_url, scheme, host, port, qs, anchor