Fixed compile error in issue #22410. The _locale module is optional.

This commit is contained in:
Serhiy Storchaka 2014-10-31 01:34:45 +02:00
parent d9b8dc272a
commit cf7b1cadd1
1 changed files with 6 additions and 1 deletions

View File

@ -122,7 +122,10 @@ This module also defines an exception 'error'.
import sys
import sre_compile
import sre_parse
try:
import _locale
except ImportError:
_locale = None
# public symbols
__all__ = [ "match", "fullmatch", "search", "sub", "subn", "split", "findall",
@ -293,6 +296,8 @@ def _compile(pattern, flags):
if len(_cache) >= _MAXCACHE:
_cache.clear()
if p.flags & LOCALE:
if not _locale:
return p
loc = _locale.setlocale(_locale.LC_CTYPE)
else:
loc = None