122122"""
123123
124124import enum
125- from . import _compiler , _parser
125+ from . import sre_compile , sre_parse
126126import functools
127127try :
128128 import _locale
145145@enum ._simple_enum (enum .IntFlag , boundary = enum .KEEP )
146146class RegexFlag :
147147 NOFLAG = 0
148- ASCII = A = _compiler .SRE_FLAG_ASCII # assume ascii "locale"
149- IGNORECASE = I = _compiler .SRE_FLAG_IGNORECASE # ignore case
150- LOCALE = L = _compiler .SRE_FLAG_LOCALE # assume current 8-bit locale
151- UNICODE = U = _compiler .SRE_FLAG_UNICODE # assume unicode "locale"
152- MULTILINE = M = _compiler .SRE_FLAG_MULTILINE # make anchors look for newline
153- DOTALL = S = _compiler .SRE_FLAG_DOTALL # make dot match newline
154- VERBOSE = X = _compiler .SRE_FLAG_VERBOSE # ignore whitespace and comments
148+ ASCII = A = sre_compile .SRE_FLAG_ASCII # assume ascii "locale"
149+ IGNORECASE = I = sre_compile .SRE_FLAG_IGNORECASE # ignore case
150+ LOCALE = L = sre_compile .SRE_FLAG_LOCALE # assume current 8-bit locale
151+ UNICODE = U = sre_compile .SRE_FLAG_UNICODE # assume unicode "locale"
152+ MULTILINE = M = sre_compile .SRE_FLAG_MULTILINE # make anchors look for newline
153+ DOTALL = S = sre_compile .SRE_FLAG_DOTALL # make dot match newline
154+ VERBOSE = X = sre_compile .SRE_FLAG_VERBOSE # ignore whitespace and comments
155155 # sre extensions (experimental, don't rely on these)
156- TEMPLATE = T = _compiler .SRE_FLAG_TEMPLATE # disable backtracking
157- DEBUG = _compiler .SRE_FLAG_DEBUG # dump pattern after compilation
156+ TEMPLATE = T = sre_compile .SRE_FLAG_TEMPLATE # disable backtracking
157+ DEBUG = sre_compile .SRE_FLAG_DEBUG # dump pattern after compilation
158158 __str__ = object .__str__
159159 _numeric_repr_ = hex
160160
161161# sre exception
162- error = _compiler .error
162+ error = sre_compile .error
163163
164164# --------------------------------------------------------------------
165165# public interface
@@ -256,8 +256,8 @@ def escape(pattern):
256256 pattern = str (pattern , 'latin1' )
257257 return pattern .translate (_special_chars_map ).encode ('latin1' )
258258
259- Pattern = type (_compiler .compile ('' , 0 ))
260- Match = type (_compiler .compile ('' , 0 ).match ('' ))
259+ Pattern = type (sre_compile .compile ('' , 0 ))
260+ Match = type (sre_compile .compile ('' , 0 ).match ('' ))
261261
262262# --------------------------------------------------------------------
263263# internals
@@ -278,9 +278,9 @@ def _compile(pattern, flags):
278278 raise ValueError (
279279 "cannot process flags argument with a compiled pattern" )
280280 return pattern
281- if not _compiler .isstring (pattern ):
281+ if not sre_compile .isstring (pattern ):
282282 raise TypeError ("first argument must be string or compiled pattern" )
283- p = _compiler .compile (pattern , flags )
283+ p = sre_compile .compile (pattern , flags )
284284 if not (flags & DEBUG ):
285285 if len (_cache ) >= _MAXCACHE :
286286 # Drop the oldest item
@@ -294,12 +294,12 @@ def _compile(pattern, flags):
294294@functools .lru_cache (_MAXCACHE )
295295def _compile_repl (repl , pattern ):
296296 # internal: compile replacement pattern
297- return _parser .parse_template (repl , pattern )
297+ return sre_parse .parse_template (repl , pattern )
298298
299299def _expand (pattern , match , template ):
300300 # internal: Match.expand implementation hook
301- template = _parser .parse_template (template , pattern )
302- return _parser .expand_template (template , match )
301+ template = sre_parse .parse_template (template , pattern )
302+ return sre_parse .expand_template (template , match )
303303
304304def _subx (pattern , template ):
305305 # internal: Pattern.sub/subn implementation helper
@@ -308,7 +308,7 @@ def _subx(pattern, template):
308308 # literal replacement
309309 return template [1 ][0 ]
310310 def filter (match , template = template ):
311- return _parser .expand_template (template , match )
311+ return sre_parse .expand_template (template , match )
312312 return filter
313313
314314# register myself for pickling
@@ -325,22 +325,22 @@ def _pickle(p):
325325
326326class Scanner :
327327 def __init__ (self , lexicon , flags = 0 ):
328- from ._constants import BRANCH , SUBPATTERN
328+ from .sre_constants import BRANCH , SUBPATTERN
329329 if isinstance (flags , RegexFlag ):
330330 flags = flags .value
331331 self .lexicon = lexicon
332332 # combine phrases into a compound pattern
333333 p = []
334- s = _parser .State ()
334+ s = sre_parse .State ()
335335 s .flags = flags
336336 for phrase , action in lexicon :
337337 gid = s .opengroup ()
338- p .append (_parser .SubPattern (s , [
339- (SUBPATTERN , (gid , 0 , 0 , _parser .parse (phrase , flags ))),
338+ p .append (sre_parse .SubPattern (s , [
339+ (SUBPATTERN , (gid , 0 , 0 , sre_parse .parse (phrase , flags ))),
340340 ]))
341341 s .closegroup (gid , p [- 1 ])
342- p = _parser .SubPattern (s , [(BRANCH , (None , p ))])
343- self .scanner = _compiler .compile (p )
342+ p = sre_parse .SubPattern (s , [(BRANCH , (None , p ))])
343+ self .scanner = sre_compile .compile (p )
344344 def scan (self , string ):
345345 result = []
346346 append = result .append
0 commit comments