response to comments

This commit is contained in:
Jeremy Langley 2022-03-04 00:11:59 -08:00
parent d31d428c97
commit a35b946150
3 changed files with 5 additions and 5 deletions

View File

@ -254,7 +254,7 @@ class SimpleRouter(BaseRouter):
# so a slash in the beginning will (A) cause Django to give # so a slash in the beginning will (A) cause Django to give
# warnings and (B) generate URLS that will require using '//'. # warnings and (B) generate URLS that will require using '//'.
if not prefix and regex[:2] == '^/': if not prefix and regex[:2] == '^/':
regex = f'^{regex[2:]}' regex = '^' + regex[2:]
initkwargs = route.initkwargs.copy() initkwargs = route.initkwargs.copy()
initkwargs.update({ initkwargs.update({

View File

@ -11,7 +11,7 @@ def _get_format_path_converter(suffix_kwarg, allowed):
else: else:
allowed_cases = "|".join(allowed) allowed_cases = "|".join(allowed)
allowed_pattern = f'(?:{allowed_cases})' allowed_pattern = f'(?:{allowed_cases})'
suffix_pattern = fr"\.{allowed_pattern}/?" suffix_pattern = r"\.%s/?" % allowed_pattern
else: else:
suffix_pattern = r"\.[a-z0-9]+/?" suffix_pattern = r"\.[a-z0-9]+/?"
@ -102,9 +102,9 @@ def format_suffix_patterns(urlpatterns, suffix_required=False, allowed=None):
else: else:
allowed_cases = "|".join(allowed) allowed_cases = "|".join(allowed)
allowed_pattern = f'({allowed_cases})' allowed_pattern = f'({allowed_cases})'
suffix_pattern = fr'\.(?P<{suffix_kwarg}>{allowed_pattern})/?$' suffix_pattern = r'\.(?P<%s>%s)/?$' % (suffix_kwarg, allowed_pattern)
else: else:
suffix_pattern = fr'\.(?P<{suffix_kwarg}>[a-z0-9]+)/?$' suffix_pattern = r'\.(?P<%s>[a-z0-9]+)/?$' % suffix_kwarg
converter_name, suffix_converter = _get_format_path_converter(suffix_kwarg, allowed) converter_name, suffix_converter = _get_format_path_converter(suffix_kwarg, allowed)
register_converter(suffix_converter, converter_name) register_converter(suffix_converter, converter_name)

View File

@ -83,7 +83,7 @@ def parse_html_dict(dictionary, prefix=''):
} }
""" """
ret = MultiValueDict() ret = MultiValueDict()
regex = re.compile(fr'^{re.escape(prefix)}\.(.+)$') regex = re.compile(r'^%s\.(.+)$' % re.escape(prefix))
for field in dictionary: for field in dictionary:
match = regex.match(field) match = regex.match(field)
if not match: if not match: