[Python-checkins] r83236 - in python/branches/py3k: Doc/library/string.rst Lib/string.py Misc/NEWS

georg.brandl python-checkins at python.org
Thu Jul 29 19:16:10 CEST 2010


Author: georg.brandl
Date: Thu Jul 29 19:16:10 2010
New Revision: 83236

Log:
#6630: allow customizing flags for compiling string.Template.idpattern.

Modified:
   python/branches/py3k/Doc/library/string.rst
   python/branches/py3k/Lib/string.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Doc/library/string.rst
==============================================================================
--- python/branches/py3k/Doc/library/string.rst	(original)
+++ python/branches/py3k/Doc/library/string.rst	Thu Jul 29 19:16:10 2010
@@ -710,6 +710,14 @@
   appropriate).  The default value is the regular expression
   ``[_a-z][_a-z0-9]*``.
 
+* *flags* -- The regular expression flags that will be applied when compiling
+  the regular expression used for recognizing substitutions.  The default value
+  is ``re.IGNORECASE``.  Note that ``re.VERBOSE`` will always be added to the
+  flags, so custom *idpattern*\ s must follow conventions for verbose regular
+  expressions.
+
+  .. versionadded:: 3.2
+
 Alternatively, you can provide the entire regular expression pattern by
 overriding the class attribute *pattern*.  If you do this, the value must be a
 regular expression object with four named capturing groups.  The capturing

Modified: python/branches/py3k/Lib/string.py
==============================================================================
--- python/branches/py3k/Lib/string.py	(original)
+++ python/branches/py3k/Lib/string.py	Thu Jul 29 19:16:10 2010
@@ -81,7 +81,7 @@
                 'delim' : _re.escape(cls.delimiter),
                 'id'    : cls.idpattern,
                 }
-        cls.pattern = _re.compile(pattern, _re.IGNORECASE | _re.VERBOSE)
+        cls.pattern = _re.compile(pattern, cls.flags | _re.VERBOSE)
 
 
 class Template(metaclass=_TemplateMetaclass):
@@ -89,6 +89,7 @@
 
     delimiter = '$'
     idpattern = r'[_a-z][_a-z0-9]*'
+    flags = _re.IGNORECASE
 
     def __init__(self, template):
         self.template = template

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Thu Jul 29 19:16:10 2010
@@ -475,6 +475,9 @@
 Library
 -------
 
+- Issue #6630: Allow customizing regex flags when subclassing the
+  string.Template class.
+
 - Issue #9411: Allow specifying an encoding for config files in the
   configparser module.
 


More information about the Python-checkins mailing list