Mercurial > piecrust2
comparison piecrust/appconfig.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 | 97b1b46cc156 |
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 json | 5 import json |
5 import urllib | 6 import urllib |
6 import logging | 7 import logging |
7 import hashlib | 8 import hashlib |
370 | 371 |
371 pgn_suffix_fmt = v.replace('%num%', '%(num)d') | 372 pgn_suffix_fmt = v.replace('%num%', '%(num)d') |
372 cache.write('pagination_suffix_format', pgn_suffix_fmt) | 373 cache.write('pagination_suffix_format', pgn_suffix_fmt) |
373 | 374 |
374 pgn_suffix_re = re.escape(v) | 375 pgn_suffix_re = re.escape(v) |
375 pgn_suffix_re = (pgn_suffix_re.replace("\\%num\\%", "(?P<num>\\d+)") + | 376 escaped_token = "%num%" if sys.hexversion >= 0x3070000 else "\\%num\\%" |
377 pgn_suffix_re = (pgn_suffix_re.replace(escaped_token, "(?P<num>\\d+)") + | |
376 '$') | 378 '$') |
377 cache.write('pagination_suffix_re', pgn_suffix_re) | 379 cache.write('pagination_suffix_re', pgn_suffix_re) |
378 return v | 380 return v |
379 | 381 |
380 | 382 |