[Python-checkins] CVS: python/dist/src/Lib sre.py,1.41,1.42

Fredrik Lundh effbot@users.sourceforge.net
2001年10月21日 14:48:32 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv18443/Lib
Modified Files:
	sre.py 
Log Message:
fixed character set description in docstring (SRE uses Python
strings, not C strings)
removed USE_PYTHON defines, and related sre.py helpers
skip calling the subx helper if the template is callable.
interestingly enough, this means that
	def callback(m):
	 return literal
	result = pattern.sub(callback, string)
is much faster than
	result = pattern.sub(literal, string)
Index: sre.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** sre.py	2001年10月21日 18:04:11	1.41
--- sre.py	2001年10月21日 21:48:30	1.42
***************
*** 18,30 ****
 
 This module provides regular expression matching operations similar to
! those found in Perl. It's 8-bit clean: the strings being processed may
! contain both null bytes and characters whose high bit is set. Regular
! expression pattern strings may not contain null bytes, but can specify
! the null byte using the \\number notation. Characters with the high
! bit set may be included.
 
! Regular expressions can contain both special and ordinary
! characters. Most ordinary characters, like "A", "a", or "0", are the
! simplest regular expressions; they simply match themselves. You can
 concatenate ordinary characters, so last matches the string 'last'.
 
--- 18,28 ----
 
 This module provides regular expression matching operations similar to
! those found in Perl. It supports both 8-bit and Unicode strings; both
! the pattern and the strings being processed can contain null bytes and
! characters outside the US ASCII range.
 
! Regular expressions can contain both special and ordinary characters.
! Most ordinary characters, like "A", "a", or "0", are the simplest
! regular expressions; they simply match themselves. You can
 concatenate ordinary characters, so last matches the string 'last'.
 
***************
*** 46,50 ****
 (...) Matches the RE inside the parentheses.
 The contents can be retrieved or matched later in the string.
! (?iLmsx) Set the I, L, M, S, or X flag for the RE (see below).
 (?:...) Non-grouping version of regular parentheses.
 (?P<name>...) The substring matched by the group is accessible by name.
--- 44,48 ----
 (...) Matches the RE inside the parentheses.
 The contents can be retrieved or matched later in the string.
! (?iLmsux) Set the I, L, M, S, U, or X flag for the RE (see below).
 (?:...) Non-grouping version of regular parentheses.
 (?P<name>...) The substring matched by the group is accessible by name.
***************
*** 55,59 ****
 
 The special sequences consist of "\\" and a character from the list
! below. If the ordinary character is not on the list, then the
 resulting RE will match the second character.
 \number Matches the contents of the group of the same number.
--- 53,57 ----
 
 The special sequences consist of "\\" and a character from the list
! below. If the ordinary character is not on the list, then the
 resulting RE will match the second character.
 \number Matches the contents of the group of the same number.
***************
*** 247,320 ****
 def _subx(pattern, template):
 # internal: pattern.sub/subn implementation helper
! if callable(template):
! filter = template
! else:
! template = _compile_repl(template, pattern)
! if not template[0] and len(template[1]) == 1:
! # literal replacement
! filter = template[1][0]
! else:
! def filter(match, template=template):
! return sre_parse.expand_template(template, match)
! return filter
! 
! def _sub(pattern, template, text, count=0):
! # internal: pattern.sub implementation hook
! # FIXME: not used in SRE 2.2.1 and later; will be removed soon
! return _subn(pattern, template, text, count)[0]
! 
! def _subn(pattern, template, text, count=0):
! # internal: pattern.subn implementation hook
! # FIXME: not used in SRE 2.2.1 and later; will be removed soon
! filter = _subx(pattern, template)
! if not callable(filter):
 # literal replacement
! def filter(match, literal=filter):
! return literal
! n = i = 0
! s = []
! append = s.append
! c = pattern.scanner(text)
! while not count or n < count:
! m = c.search()
! if not m:
! break
! b, e = m.span()
! if i < b:
! append(text[i:b])
! elif i == b == e and n:
! append(text[i:b])
! continue # ignore empty match at previous position
! append(filter(m))
! i = e
! n = n + 1
! append(text[i:])
! return _join(s, text[:0]), n
! 
! def _split(pattern, text, maxsplit=0):
! # internal: pattern.split implementation hook
! # FIXME: not used in SRE 2.2.1 and later; will be removed soon
! n = i = 0
! s = []
! append = s.append
! extend = s.extend
! c = pattern.scanner(text)
! g = pattern.groups
! while not maxsplit or n < maxsplit:
! m = c.search()
! if not m:
! break
! b, e = m.span()
! if b == e:
! if i >= len(text):
! break
! continue
! append(text[i:b])
! if g and b != e:
! extend(list(m.groups()))
! i = e
! n = n + 1
! append(text[i:])
! return s
 
 # register myself for pickling
--- 245,255 ----
 def _subx(pattern, template):
 # internal: pattern.sub/subn implementation helper
! template = _compile_repl(template, pattern)
! if not template[0] and len(template[1]) == 1:
 # literal replacement
! return template[1][0]
! def filter(match, template=template):
! return sre_parse.expand_template(template, match)
! return filter
 
 # register myself for pickling

AltStyle によって変換されたページ (->オリジナル) /