bpo-31672 - Add one last minor clarification for idpattern (#4483)

Add one last minor clarification for idpattern
This commit is contained in:
Barry Warsaw 2017-11-21 10:28:13 -05:00 committed by GitHub
parent 337cbbace0
commit e256b40888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -755,13 +755,15 @@ attributes:
* *idpattern* -- This is the regular expression describing the pattern for * *idpattern* -- This is the regular expression describing the pattern for
non-braced placeholders. The default value is the regular expression non-braced placeholders. The default value is the regular expression
``(?-i:[_a-zA-Z][_a-zA-Z0-9]*)``. If this is given and *braceidpattern* is ``(?a:[_a-zA-Z][_a-zA-Z0-9]*)``. If this is given and *braceidpattern* is
``None`` this pattern will also apply to braced placeholders. ``None`` this pattern will also apply to braced placeholders.
.. note:: .. note::
Since default *flags* is ``re.IGNORECASE``, pattern ``[a-z]`` can match Since default *flags* is ``re.IGNORECASE``, pattern ``[a-z]`` can match
with some non-ASCII characters. That's why we use local ``-i`` flag here. with some non-ASCII characters. That's why we use the local ``a`` flag
here. Further, with the default *flags* value, including ``A-Z`` in the
ranges is redundant, but required for backward compatibility.
While *flags* is kept to ``re.IGNORECASE`` for backward compatibility, While *flags* is kept to ``re.IGNORECASE`` for backward compatibility,
you can override it to ``0`` or ``re.IGNORECASE | re.ASCII`` when you can override it to ``0`` or ``re.IGNORECASE | re.ASCII`` when

View File

@ -79,11 +79,14 @@ class Template(metaclass=_TemplateMetaclass):
"""A string class for supporting $-substitutions.""" """A string class for supporting $-substitutions."""
delimiter = '$' delimiter = '$'
# r'[a-z]' matches to non-ASCII letters when used with IGNORECASE, # r'[a-z]' matches to non-ASCII letters when used with IGNORECASE, but
# but without ASCII flag. We can't add re.ASCII to flags because of # without the ASCII flag. We can't add re.ASCII to flags because of
# backward compatibility. So we use local -i flag and [a-zA-Z] pattern. # backward compatibility. So we use the ?a local flag and [a-z] pattern.
# We also can't remove the A-Z ranges, because although they are
# technically redundant with the IGNORECASE flag, the value is part of the
# publicly documented API.
# See https://bugs.python.org/issue31672 # See https://bugs.python.org/issue31672
idpattern = r'(?-i:[_a-zA-Z][_a-zA-Z0-9]*)' idpattern = r'(?a:[_a-zA-Z][_a-zA-Z0-9]*)'
braceidpattern = None braceidpattern = None
flags = _re.IGNORECASE flags = _re.IGNORECASE