Mercurial > piecrust2
comparison piecrust/routing.py @ 1168:10520472cc73
routing: Fix breakages with routing on some versions of Python.
Finally figured what happened with change 6baa94da8b16 (this is a Mercurial
hash by the way if you're looking at the Git mirror). Between Python 3.6 and
3.7 there was a change where the percent sign ('%') went from being escaped by
`re.escape` to _not_ being escaped. So now we need to use different regex
patterns dependin on the Python version, yay.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 04 Oct 2019 11:13:33 -0700 |
parents | 6baa94da8b16 |
children |
comparison
equal
deleted
inserted
replaced
1167:c0c00dc1eac7 | 1168:10520472cc73 |
---|---|
1 import re | 1 import re |
2 import os.path | 2 import os.path |
3 import sys | |
3 import copy | 4 import copy |
4 import logging | 5 import logging |
5 import urllib.parse | 6 import urllib.parse |
6 from werkzeug.utils import cached_property | 7 from werkzeug.utils import cached_property |
7 | 8 |
8 | 9 |
9 logger = logging.getLogger(__name__) | 10 logger = logging.getLogger(__name__) |
10 | 11 |
11 | 12 |
12 route_re = re.compile(r'%((?P<qual>[\w\d]+):)?(?P<var>\+)?(?P<name>\w+)%') | 13 route_re = re.compile(r'%((?P<qual>[\w\d]+):)?(?P<var>\+)?(?P<name>\w+)%') |
13 route_esc_re = re.compile( | 14 if sys.hexversion >= 0x3070000: |
14 r'%((?P<qual>[\w\d]+)\\:)?(?P<var>\\\+)?(?P<name>\w+)%') | 15 route_esc_re = re.compile( |
16 r'%((?P<qual>[\w\d]+)\\:)?(?P<var>\\\+)?(?P<name>\w+)%') | |
17 else: | |
18 route_esc_re = re.compile( | |
19 r'\\%((?P<qual>[\w\d]+)\\:)?(?P<var>\\\+)?(?P<name>\w+)\\%') | |
20 | |
15 ugly_url_cleaner = re.compile(r'\.html$') | 21 ugly_url_cleaner = re.compile(r'\.html$') |
16 | 22 |
17 | 23 |
18 class RouteNotFoundError(Exception): | 24 class RouteNotFoundError(Exception): |
19 pass | 25 pass |