Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7490250

Browse files
committed
Addendum to #764548: restore 2.1 compatibility.
1 parent 12723ba commit 7490250

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

Lib/sre.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def _compile(*key):
221221
pattern, flags = key
222222
if isinstance(pattern, _pattern_type):
223223
return pattern
224-
if not isinstance(pattern, sre_compile.STRING_TYPES):
224+
if not sre_compile.isstring(pattern):
225225
raise TypeError, "first argument must be string or compiled pattern"
226226
try:
227227
p = sre_compile.compile(pattern, flags)

Lib/sre_compile.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,16 @@ def _compile_info(code, pattern, flags):
431431
try:
432432
unicode
433433
except NameError:
434-
STRING_TYPES = type("")
434+
STRING_TYPES = (type(""),)
435435
else:
436436
STRING_TYPES = (type(""), type(unicode("")))
437437

438+
def isstring(obj):
439+
for tp in STRING_TYPES:
440+
if isinstance(obj, tp):
441+
return 1
442+
return 0
443+
438444
def _code(p, flags):
439445

440446
flags = p.pattern.flags | flags
@@ -453,7 +459,7 @@ def _code(p, flags):
453459
def compile(p, flags=0):
454460
# internal: convert pattern list to internal format
455461

456-
if isinstance(p, STRING_TYPES):
462+
if isstring(p):
457463
import sre_parse
458464
pattern = p
459465
p = sre_parse.parse(p, flags)

0 commit comments

Comments
 (0)