<s> r"""<STR_LIT>""" <EOL> import sys <EOL> import sre_compile <EOL> import sre_parse <EOL> try : <EOL> import _locale <EOL> except ImportError : <EOL> _locale = None <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:I>" , "<STR_LIT:L>" , "<STR_LIT:M>" , "<STR_LIT:S>" , "<STR_LIT:X>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:error>" ] <EOL> __version__ = "<STR_LIT>" <EOL> I = IGNORECASE = sre_compile . SRE_FLAG_IGNORECASE <EOL> L = LOCALE = sre_compile . SRE_FLAG_LOCALE <EOL> U = UNICODE = sre_compile . SRE_FLAG_UNICODE <EOL> M = MULTILINE = sre_compile . SRE_FLAG_MULTILINE <EOL> S = DOTALL = sre_compile . SRE_FLAG_DOTALL <EOL> X = VERBOSE = sre_compile . SRE_FLAG_VERBOSE <EOL> T = TEMPLATE = sre_compile . SRE_FLAG_TEMPLATE <EOL> DEBUG = sre_compile . SRE_FLAG_DEBUG <EOL> error = sre_compile . error <EOL> def match ( pattern , string , flags = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return _compile ( pattern , flags ) . match ( string ) <EOL> def search ( pattern , string , flags = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return _compile ( pattern , flags ) . search ( string ) <EOL> def sub ( pattern , repl , string , count = <NUM_LIT:0> , flags = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return _compile ( pattern , flags ) . sub ( repl , string , count ) <EOL> def subn ( pattern , repl , string , count = <NUM_LIT:0> , flags = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return _compile ( pattern , flags ) . subn ( repl , string , count ) <EOL> def split ( pattern , string , maxsplit = <NUM_LIT:0> , flags = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return _compile ( pattern , flags ) . split ( string , maxsplit ) <EOL> def findall ( pattern , string , flags = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return _compile ( pattern , flags ) . findall ( string ) <EOL> if sys . hexversion >= <NUM_LIT> : <EOL> __all__ . append ( "<STR_LIT>" ) <EOL> def finditer ( pattern , string , flags = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return _compile ( pattern , flags ) . finditer ( string ) <EOL> def compile ( pattern , flags = <NUM_LIT:0> ) : <EOL> "<STR_LIT>" <EOL> return _compile ( pattern , flags ) <EOL> def purge ( ) : <EOL> "<STR_LIT>" <EOL> _cache . clear ( ) <EOL> _cache_repl . clear ( ) <EOL> def template ( pattern , flags = <NUM_LIT:0> ) : <EOL> "<STR_LIT>" <EOL> return _compile ( pattern , flags | T ) <EOL> _alphanum = frozenset ( <EOL> "<STR_LIT>" ) <EOL> def escape ( pattern ) : <EOL> "<STR_LIT>" <EOL> s = list ( pattern ) <EOL> alphanum = _alphanum <EOL> for i , c in enumerate ( pattern ) : <EOL> if c not in alphanum : <EOL> if c == "<STR_LIT>" : <EOL> s [ i ] = "<STR_LIT>" <EOL> else : <EOL> s [ i ] = "<STR_LIT:\\>" + c <EOL> return pattern [ : <NUM_LIT:0> ] . join ( s ) <EOL> _cache = { } <EOL> _cache_repl = { } <EOL> _pattern_type = type ( sre_compile . compile ( "<STR_LIT>" , <NUM_LIT:0> ) ) <EOL> _MAXCACHE = <NUM_LIT:100> <EOL> def _compile ( * key ) : <EOL> pattern , flags = key <EOL> bypass_cache = flags & DEBUG <EOL> if not bypass_cache : <EOL> cachekey = ( type ( key [ <NUM_LIT:0> ] ) , ) + key <EOL> try : <EOL> p , loc = _cache [ cachekey ] <EOL> if loc is None or loc == _locale . setlocale ( _locale . LC_CTYPE ) : <EOL> return p <EOL> except KeyError : <EOL> pass <EOL> if isinstance ( pattern , _pattern_type ) : <EOL> if flags : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return pattern <EOL> if not sre_compile . isstring ( pattern ) : <EOL> raise TypeError , "<STR_LIT>" <EOL> try : <EOL> p = sre_compile . compile ( pattern , flags ) <EOL> except error , v : <EOL> raise error , v <EOL> if not bypass_cache : <EOL> if len ( _cache ) >= _MAXCACHE : <EOL> _cache . clear ( ) <EOL> if p . flags & LOCALE : <EOL> if not _locale : <EOL> return p <EOL> loc = _locale . setlocale ( _locale . LC_CTYPE ) <EOL> else : <EOL> loc = None <EOL> _cache [ cachekey ] = p , loc <EOL> return p <EOL> def _compile_repl ( * key ) : <EOL> p = _cache_repl . get ( key ) <EOL> if p is not None : <EOL> return p <EOL> repl , pattern = key <EOL> try : <EOL> p = sre_parse . parse_template ( repl , pattern ) <EOL> except error , v : <EOL> raise error , v <EOL> if len ( _cache_repl ) >= _MAXCACHE : <EOL> _cache_repl . clear ( ) <EOL> _cache_repl [ key ] = p <EOL> return p <EOL> def _expand ( pattern , match , template ) : <EOL> template = sre_parse . parse_template ( template , pattern ) <EOL> return sre_parse . expand_template ( template , match ) <EOL> def _subx ( pattern , template ) : <EOL> template = _compile_repl ( template , pattern ) <EOL> if not template [ <NUM_LIT:0> ] and len ( template [ <NUM_LIT:1> ] ) == <NUM_LIT:1> : <EOL> return template [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> def filter ( match , template = template ) : <EOL> return sre_parse . expand_template ( template , match ) <EOL> return filter <EOL> import copy_reg <EOL> def _pickle ( p ) : <EOL> return _compile , ( p . pattern , p . flags ) <EOL> copy_reg . pickle ( _pattern_type , _pickle , _compile ) <EOL> class Scanner : <EOL> def __init__ ( self , lexicon , flags = <NUM_LIT:0> ) : <EOL> from sre_constants import BRANCH , SUBPATTERN <EOL> self . lexicon = lexicon <EOL> p = [ ] <EOL> s = sre_parse . Pattern ( ) <EOL> s . flags = flags <EOL> for phrase , action in lexicon : <EOL> p . append ( sre_parse . SubPattern ( s , [ <EOL> ( SUBPATTERN , ( len ( p ) + <NUM_LIT:1> , sre_parse . parse ( phrase , flags ) ) ) , <EOL> ] ) ) <EOL> s . groups = len ( p ) + <NUM_LIT:1> <EOL> p = sre_parse . SubPattern ( s , [ ( BRANCH , ( None , p ) ) ] ) <EOL> self . scanner = sre_compile . compile ( p ) <EOL> def scan ( self , string ) : <EOL> result = [ ] <EOL> append = result . append <EOL> match = self . scanner . scanner ( string ) . match <EOL> i = <NUM_LIT:0> <EOL> while <NUM_LIT:1> : <EOL> m = match ( ) <EOL> if not m : <EOL> break <EOL> j = m . end ( ) <EOL> if i == j : <EOL> break <EOL> action = self . lexicon [ m . lastindex - <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> if hasattr ( action , '<STR_LIT>' ) : <EOL> self . match = m <EOL> action = action ( self , m . group ( ) ) <EOL> if action is not None : <EOL> append ( action ) <EOL> i = j <EOL> return result , string [ i : ] </s>
