summaryrefslogtreecommitdiff
path: root/routes
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
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')
-rw-r--r--routes/mapper.py6
-rw-r--r--routes/route.py23
-rw-r--r--routes/util.py4
3 files changed, 21 insertions, 12 deletions
diff --git a/routes/mapper.py b/routes/mapper.py
index eb4060a..cf4dcf1 100644
--- a/routes/mapper.py
+++ b/routes/mapper.py
@@ -511,7 +511,7 @@ class Mapper(SubMapperParent):
m.connect('date/:year/:month/:day', controller="blog",
action="view")
m.connect('archives/:page', controller="blog", action="by_page",
- requirements = { 'page':'\d{1,2}' })
+ requirements = { 'page':'\\d{1,2}' })
m.connect('category_list', 'archives/category/:section',
controller='blog', action='category',
section='home', type='list')
@@ -995,7 +995,7 @@ class Mapper(SubMapperParent):
map.resource('message', 'messages',
path_prefix='{project_id}/',
- requirements={"project_id": R"\d+"})
+ requirements={"project_id": R"\\d+"})
# POST /01234/message
# success, project_id is set to "01234"
# POST /foo/message
@@ -1177,7 +1177,7 @@ class Mapper(SubMapperParent):
**route_options)
self.connect(name_prefix + name, path, **route_options)
- requirements_regexp = '[^\/]+(?<!\\\)'
+ requirements_regexp = '[^\\/]+(?<!\\\\)'
# Add the routes that deal with member methods of a resource
for method, lst in six.iteritems(member_methods):
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
diff --git a/routes/util.py b/routes/util.py
index c48445f..54c8951 100644
--- a/routes/util.py
+++ b/routes/util.py
@@ -94,7 +94,7 @@ def _subdomain_check(kargs, mapper, environ):
if len(hostmatch) > 1:
port += ':' + hostmatch[1]
- match = re.match('^(.+?)\.(%s)$' % mapper.domain_match, host)
+ match = re.match(r'^(.+?)\.(%s)$' % mapper.domain_match, host)
host_subdomain, domain = match.groups() if match else (None, host)
subdomain = as_unicode(subdomain, mapper.encoding)
@@ -512,7 +512,7 @@ def controller_scan(directory=None):
for fname in os.listdir(dirname):
filename = os.path.join(dirname, fname)
if os.path.isfile(filename) and \
- re.match('^[^_]{1,1}.*\.py$', fname):
+ re.match(r'^[^_]{1,1}.*\.py$', fname):
controllers.append(prefix + fname[:-3])
elif os.path.isdir(filename):
controllers.extend(find_controllers(filename,