summaryrefslogtreecommitdiff
path: root/routes/route.py
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2019-06-11 15:20:46 +0100
committerStephen Finucane <stephen@that.guru>2019-06-11 15:38:20 +0100
commitaeb67cd762f45108f1dd0289127e4fe1b9f674ac (patch)
tree01ae385d6fff38dd12bbad423c92a151464c2545 /routes/route.py
parent0250968ee81d36de7dabbe19d76a418a202ca163 (diff)
downloadroutes-aeb67cd762f45108f1dd0289127e4fe1b9f674ac.tar.gz
Resolve invalid escape sequences
Integrate flake8 along the way which makes picking these up sooo much easier. Someone else can go fix the other violations in the future, if they're so inclined. Signed-off-by: Stephen Finucane <stephen@that.guru>
Diffstat (limited to 'routes/route.py')
-rw-r--r--routes/route.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/routes/route.py b/routes/route.py
index c649786..b03e1cf 100644
--- a/routes/route.py
+++ b/routes/route.py
@@ -34,9 +34,9 @@ class Route(object):
>>> newroute = Route(None, 'date/:year/:month/:day',
... controller="blog", action="view")
>>> newroute = Route(None, 'archives/:page', controller="blog",
- ... action="by_page", requirements = { 'page':'\d{1,2}' })
+ ... action="by_page", requirements = { 'page':'\\d{1,2}' })
>>> newroute.reqs
- {'page': '\\\d{1,2}'}
+ {'page': '\\\\d{1,2}'}
.. Note::
Route is generally not called directly, a Mapper instance
@@ -145,13 +145,22 @@ class Route(object):
"""Utility function to walk the route, and pull out the valid
dynamic/wildcard keys."""
collecting = False
+ escaping = False
current = ''
done_on = ''
var_type = ''
just_started = False
routelist = []
for char in routepath:
- if char in [':', '*', '{'] and not collecting and not self.static \
+ if escaping:
+ if char in ['\\', ':', '*', '{', '}']:
+ current += char
+ else:
+ current += '\\' + char
+ escaping = False
+ elif char == '\\':
+ escaping = True
+ elif char in [':', '*', '{'] and not collecting and not self.static \
or char in ['{'] and not collecting:
just_started = True
collecting = True
@@ -324,7 +333,7 @@ class Route(object):
else:
regpart = '(?:%s)' % partmatch
if part['type'] == '.':
- regparts.append('(?:\.%s)??' % regpart)
+ regparts.append(r'(?:\.%s)??' % regpart)
else:
regparts.append(regpart)
else:
@@ -367,7 +376,7 @@ class Route(object):
else:
partreg = '(?:%s)' % self.reqs[var]
if typ == '.':
- partreg = '(?:\.%s)??' % partreg
+ partreg = r'(?:\.%s)??' % partreg
elif var == 'controller':
if include_names:
partreg = '(?P<%s>%s)' % (var, '|'.join(map(re.escape,
@@ -390,7 +399,7 @@ class Route(object):
else:
partreg = '(?:[^%s]+?)' % exclude_chars
if typ == '.':
- partreg = '(?:\.%s)??' % partreg
+ partreg = r'(?:\.%s)??' % partreg
else:
end = ''.join(self.done_chars)
rem = rest
@@ -530,7 +539,7 @@ class Route(object):
if sub_domains and environ and 'HTTP_HOST' in environ:
host = environ['HTTP_HOST'].split(':')[0]
- sub_match = re.compile('^(.+?)\.%s$' % domain_match)
+ sub_match = re.compile(r'^(.+?)\.%s$' % domain_match)
subdomain = re.sub(sub_match, r'\1', host)
if subdomain not in sub_domains_ignore and host != subdomain:
sub_domain = subdomain