Addendum to #764548: restore 2.1 compatibility.
This commit is contained in:
parent
12723bacea
commit
74902508dc
|
@ -221,7 +221,7 @@ def _compile(*key):
|
||||||
pattern, flags = key
|
pattern, flags = key
|
||||||
if isinstance(pattern, _pattern_type):
|
if isinstance(pattern, _pattern_type):
|
||||||
return pattern
|
return pattern
|
||||||
if not isinstance(pattern, sre_compile.STRING_TYPES):
|
if not sre_compile.isstring(pattern):
|
||||||
raise TypeError, "first argument must be string or compiled pattern"
|
raise TypeError, "first argument must be string or compiled pattern"
|
||||||
try:
|
try:
|
||||||
p = sre_compile.compile(pattern, flags)
|
p = sre_compile.compile(pattern, flags)
|
||||||
|
|
|
@ -431,10 +431,16 @@ def _compile_info(code, pattern, flags):
|
||||||
try:
|
try:
|
||||||
unicode
|
unicode
|
||||||
except NameError:
|
except NameError:
|
||||||
STRING_TYPES = type("")
|
STRING_TYPES = (type(""),)
|
||||||
else:
|
else:
|
||||||
STRING_TYPES = (type(""), type(unicode("")))
|
STRING_TYPES = (type(""), type(unicode("")))
|
||||||
|
|
||||||
|
def isstring(obj):
|
||||||
|
for tp in STRING_TYPES:
|
||||||
|
if isinstance(obj, tp):
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
def _code(p, flags):
|
def _code(p, flags):
|
||||||
|
|
||||||
flags = p.pattern.flags | flags
|
flags = p.pattern.flags | flags
|
||||||
|
@ -453,7 +459,7 @@ def _code(p, flags):
|
||||||
def compile(p, flags=0):
|
def compile(p, flags=0):
|
||||||
# internal: convert pattern list to internal format
|
# internal: convert pattern list to internal format
|
||||||
|
|
||||||
if isinstance(p, STRING_TYPES):
|
if isstring(p):
|
||||||
import sre_parse
|
import sre_parse
|
||||||
pattern = p
|
pattern = p
|
||||||
p = sre_parse.parse(p, flags)
|
p = sre_parse.parse(p, flags)
|
||||||
|
|
Loading…
Reference in New Issue