104104 "U" , "IGNORECASE" , "LOCALE" , "MULTILINE" , "DOTALL" , "VERBOSE" ,
105105 "UNICODE" , "error" ]
106106
107- __version__ = "2.2.0 "
107+ __version__ = "2.2.1 "
108108
109109# this module works under 1.5.2 and later. don't use string methods
110110import string
@@ -244,26 +244,33 @@ def _expand(pattern, match, template):
244244 template = sre_parse .parse_template (template , pattern )
245245 return sre_parse .expand_template (template , match )
246246
247- def _sub (pattern , template , text , count = 0 ):
248- # internal: pattern.sub implementation hook
249- return _subn (pattern , template , text , count , 1 )[0 ]
250-
251- def _subn (pattern , template , text , count = 0 , sub = 0 ):
252- # internal: pattern.subn implementation hook
247+ def _subx (pattern , template ):
248+ # internal: pattern.sub/subn implementation helper
253249 if callable (template ):
254250 filter = template
255251 else :
256252 template = _compile_repl (template , pattern )
257- literals = template [1 ]
258- if sub and not count :
259- literal = pattern ._getliteral ()
260- if literal and "\\ " in literal :
261- literal = None # may contain untranslated escapes
262- if literal is not None and len (literals ) == 1 and literals [0 ]:
263- # shortcut: both pattern and string are literals
264- return string .replace (text , pattern .pattern , literals [0 ]), 0
265- def filter (match , template = template ):
266- return sre_parse .expand_template (template , match )
253+ if not template [0 ] and len (template [1 ]) == 1 :
254+ # literal replacement
255+ filter = template [1 ][0 ]
256+ else :
257+ def filter (match , template = template ):
258+ return sre_parse .expand_template (template , match )
259+ return filter
260+
261+ def _sub (pattern , template , text , count = 0 ):
262+ # internal: pattern.sub implementation hook
263+ # FIXME: not used in SRE 2.2.1 and later; will be removed soon
264+ return _subn (pattern , template , text , count )[0 ]
265+
266+ def _subn (pattern , template , text , count = 0 ):
267+ # internal: pattern.subn implementation hook
268+ # FIXME: not used in SRE 2.2.1 and later; will be removed soon
269+ filter = _subx (pattern , template )
270+ if not callable (filter ):
271+ # literal replacement
272+ def filter (match , literal = filter ):
273+ return literal
267274 n = i = 0
268275 s = []
269276 append = s .append
@@ -286,6 +293,7 @@ def filter(match, template=template):
286293
287294def _split (pattern , text , maxsplit = 0 ):
288295 # internal: pattern.split implementation hook
296+ # FIXME: not used in SRE 2.2.1 and later; will be removed soon
289297 n = i = 0
290298 s = []
291299 append = s .append
0 commit comments