mirror of
https://github.com/python/cpython.git
synced 2025-01-20 15:34:52 +08:00
SRE bug #441409:
compile should raise error for non-strings SRE bug #432570, 448951: reset group after failed match also bumped version number to 2.2.0
This commit is contained in:
parent
3bb4d214a4
commit
397a654791
10
Lib/sre.py
10
Lib/sre.py
@ -104,7 +104,7 @@ __all__ = [ "match", "search", "sub", "subn", "split", "findall",
|
||||
"U", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
|
||||
"UNICODE", "error" ]
|
||||
|
||||
__version__ = "2.1.1"
|
||||
__version__ = "2.2.0"
|
||||
|
||||
# this module works under 1.5.2 and later. don't use string methods
|
||||
import string
|
||||
@ -197,6 +197,8 @@ def escape(pattern):
|
||||
_cache = {}
|
||||
_cache_repl = {}
|
||||
|
||||
_pattern_type = type(sre_compile.compile("", 0))
|
||||
|
||||
_MAXCACHE = 100
|
||||
|
||||
def _join(seq, sep):
|
||||
@ -209,8 +211,10 @@ def _compile(*key):
|
||||
if p is not None:
|
||||
return p
|
||||
pattern, flags = key
|
||||
if type(pattern) not in sre_compile.STRING_TYPES:
|
||||
if type(pattern) is _pattern_type:
|
||||
return pattern
|
||||
if type(pattern) not in sre_compile.STRING_TYPES:
|
||||
raise TypeError, "first argument must be string or compiled pattern"
|
||||
try:
|
||||
p = sre_compile.compile(pattern, flags)
|
||||
except error, v:
|
||||
@ -312,7 +316,7 @@ import copy_reg
|
||||
def _pickle(p):
|
||||
return _compile, (p.pattern, p.flags)
|
||||
|
||||
copy_reg.pickle(type(_compile("", 0)), _pickle, _compile)
|
||||
copy_reg.pickle(_pattern_type, _pickle, _compile)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# experimental stuff (see python-dev discussions for details)
|
||||
|
@ -204,6 +204,12 @@ test(r"""pat.match('a').group(1, 2, 3)""", ('a', None, None))
|
||||
test(r"""pat.match('b').group('a1', 'b2', 'c3')""", (None, 'b', None))
|
||||
test(r"""pat.match('ac').group(1, 'b2', 3)""", ('a', None, 'c'))
|
||||
|
||||
# bug 448951 (similar to 429357, but with single char match)
|
||||
# (Also test greedy matches.)
|
||||
for op in '','?','*':
|
||||
test(r"""sre.match(r'((.%s):)?z', 'z').groups()"""%op, (None, None))
|
||||
test(r"""sre.match(r'((.%s):)?z', 'a:z').groups()"""%op, ('a:', 'a'))
|
||||
|
||||
if verbose:
|
||||
print "Running tests on sre.escape"
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
* 2001-05-14 fl fixes for 1.5.2
|
||||
* 2001-07-01 fl added BIGCHARSET support (from Martin von Loewis)
|
||||
* 2001-09-18 fl added _getliteral helper
|
||||
* 2001-10-18 fl fixed group reset issue (from Matthew Mueller)
|
||||
*
|
||||
* Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
|
||||
*
|
||||
@ -47,7 +48,7 @@
|
||||
#ifndef SRE_RECURSIVE
|
||||
|
||||
static char copyright[] =
|
||||
" SRE 2.1.1 Copyright (c) 1997-2001 by Secret Labs AB ";
|
||||
" SRE 2.2.0 Copyright (c) 1997-2001 by Secret Labs AB ";
|
||||
|
||||
#include "Python.h"
|
||||
#include "structmember.h" /* offsetof */
|
||||
@ -1061,6 +1062,7 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
|
||||
if (i)
|
||||
return i;
|
||||
i = mark_restore(state, 0, lastmark);
|
||||
state->lastmark = lastmark;
|
||||
if (i < 0)
|
||||
return i;
|
||||
rp->count = count - 1;
|
||||
|
Loading…
Reference in New Issue
Block a user