<s> """<STR_LIT>""" <EOL> import sys <EOL> import _sre <EOL> def compile ( pattern , flags , code , groups = <NUM_LIT:0> , groupindex = { } , indexgroup = [ None ] ) : <EOL> """<STR_LIT>""" <EOL> return SRE_Pattern ( pattern , flags , code , groups , groupindex , indexgroup ) <EOL> class SRE_Pattern ( object ) : <EOL> def __init__ ( self , pattern , flags , code , groups = <NUM_LIT:0> , groupindex = { } , indexgroup = [ None ] ) : <EOL> self . pattern = pattern <EOL> self . flags = flags <EOL> self . groups = groups <EOL> self . groupindex = groupindex <EOL> self . _indexgroup = indexgroup <EOL> self . _code = code <EOL> def match ( self , string , pos = <NUM_LIT:0> , endpos = sys . maxint ) : <EOL> """<STR_LIT>""" <EOL> state = _sre . _State ( string , pos , endpos , self . flags ) <EOL> if _sre . _match ( state , self . _code ) : <EOL> return SRE_Match ( self , state ) <EOL> else : <EOL> return None <EOL> def search ( self , string , pos = <NUM_LIT:0> , endpos = sys . maxint ) : <EOL> """<STR_LIT>""" <EOL> state = _sre . _State ( string , pos , endpos , self . flags ) <EOL> if _sre . _search ( state , self . _code ) : <EOL> return SRE_Match ( self , state ) <EOL> else : <EOL> return None <EOL> def findall ( self , string , pos = <NUM_LIT:0> , endpos = sys . maxint ) : <EOL> """<STR_LIT>""" <EOL> matchlist = [ ] <EOL> state = _sre . _State ( string , pos , endpos , self . flags ) <EOL> while state . start <= state . end : <EOL> state . reset ( ) <EOL> if not _sre . _search ( state , self . _code ) : <EOL> break <EOL> match = SRE_Match ( self , state ) <EOL> if self . groups == <NUM_LIT:0> or self . groups == <NUM_LIT:1> : <EOL> item = match . group ( self . groups ) <EOL> else : <EOL> item = match . groups ( "<STR_LIT>" ) <EOL> matchlist . append ( item ) <EOL> if state . string_position == state . start : <EOL> state . start += <NUM_LIT:1> <EOL> else : <EOL> state . start = state . string_position <EOL> return matchlist <EOL> def subn ( self , repl , string , count = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> filter = repl <EOL> if not callable ( repl ) and "<STR_LIT:\\>" in repl : <EOL> import re <EOL> filter = re . _subx ( self , repl ) <EOL> state = _sre . _State ( string , <NUM_LIT:0> , sys . maxint , self . flags ) <EOL> sublist = [ ] <EOL> need_unicode = ( isinstance ( string , unicode ) or <EOL> isinstance ( repl , unicode ) ) <EOL> n = last_pos = <NUM_LIT:0> <EOL> while not count or n < count : <EOL> state . reset ( ) <EOL> if not _sre . _search ( state , self . _code ) : <EOL> break <EOL> if last_pos < state . start : <EOL> sublist . append ( string [ last_pos : state . start ] ) <EOL> if not ( last_pos == state . start and <EOL> last_pos == state . string_position and n > <NUM_LIT:0> ) : <EOL> if callable ( filter ) : <EOL> to_app = filter ( SRE_Match ( self , state ) ) <EOL> else : <EOL> to_app = filter <EOL> if isinstance ( to_app , unicode ) : <EOL> need_unicode = True <EOL> sublist . append ( to_app ) <EOL> last_pos = state . string_position <EOL> n += <NUM_LIT:1> <EOL> if state . string_position == state . start : <EOL> state . start += <NUM_LIT:1> <EOL> else : <EOL> state . start = state . string_position <EOL> if last_pos < state . end : <EOL> sublist . append ( string [ last_pos : state . end ] ) <EOL> if n == <NUM_LIT:0> : <EOL> return string , n <EOL> if need_unicode : <EOL> item = u"<STR_LIT>" . join ( sublist ) <EOL> else : <EOL> item = "<STR_LIT>" . join ( sublist ) <EOL> return item , n <EOL> def sub ( self , repl , string , count = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> item , n = self . subn ( repl , string , count ) <EOL> return item <EOL> def split ( self , string , maxsplit = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> splitlist = [ ] <EOL> state = _sre . _State ( string , <NUM_LIT:0> , sys . maxint , self . flags ) <EOL> n = <NUM_LIT:0> <EOL> last = state . start <EOL> while not maxsplit or n < maxsplit : <EOL> state . reset ( ) <EOL> if not _sre . _search ( state , self . _code ) : <EOL> break <EOL> if state . start == state . string_position : <EOL> if last == state . end : <EOL> break <EOL> state . start += <NUM_LIT:1> <EOL> continue <EOL> splitlist . append ( string [ last : state . start ] ) <EOL> if self . groups : <EOL> match = SRE_Match ( self , state ) <EOL> splitlist . extend ( list ( match . groups ( None ) ) ) <EOL> n += <NUM_LIT:1> <EOL> last = state . start = state . string_position <EOL> splitlist . append ( string [ last : state . end ] ) <EOL> return splitlist <EOL> def finditer ( self , string , pos = <NUM_LIT:0> , endpos = sys . maxint ) : <EOL> """<STR_LIT>""" <EOL> scanner = self . scanner ( string , pos , endpos ) <EOL> return iter ( scanner . search , None ) <EOL> def scanner ( self , string , start = <NUM_LIT:0> , end = sys . maxint ) : <EOL> return SRE_Scanner ( self , string , start , end ) <EOL> def __copy__ ( self ) : <EOL> raise TypeError , "<STR_LIT>" <EOL> def __deepcopy__ ( self ) : <EOL> raise TypeError , "<STR_LIT>" <EOL> class SRE_Scanner ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , pattern , string , start , end ) : <EOL> self . pattern = pattern <EOL> self . _state = _sre . _State ( string , start , end , self . pattern . flags ) <EOL> def _match_search ( self , matcher ) : <EOL> state = self . _state <EOL> state . reset ( ) <EOL> match = None <EOL> if matcher ( state , self . pattern . _code ) : <EOL> match = SRE_Match ( self . pattern , state ) <EOL> if match is None or state . string_position == state . start : <EOL> state . start += <NUM_LIT:1> <EOL> else : <EOL> state . start = state . string_position <EOL> return match <EOL> def match ( self ) : <EOL> return self . _match_search ( _sre . _match ) <EOL> def search ( self ) : <EOL> return self . _match_search ( _sre . _search ) <EOL> class SRE_Match ( object ) : <EOL> def __init__ ( self , pattern , state ) : <EOL> self . re = pattern <EOL> self . string = state . string <EOL> self . pos = state . pos <EOL> self . endpos = state . end <EOL> self . lastindex = state . lastindex <EOL> if self . lastindex < <NUM_LIT:0> : <EOL> self . lastindex = None <EOL> self . regs = state . create_regs ( self . re . groups ) <EOL> if pattern . _indexgroup and <NUM_LIT:0> <= self . lastindex < len ( pattern . _indexgroup ) : <EOL> self . lastgroup = pattern . _indexgroup [ self . lastindex ] <EOL> else : <EOL> self . lastgroup = None <EOL> def _get_index ( self , group ) : <EOL> if isinstance ( group , int ) : <EOL> if group >= <NUM_LIT:0> and group <= self . re . groups : <EOL> return group <EOL> else : <EOL> if self . re . groupindex . has_key ( group ) : <EOL> return self . re . groupindex [ group ] <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> def _get_slice ( self , group , default ) : <EOL> group_indices = self . regs [ group ] <EOL> if group_indices [ <NUM_LIT:0> ] >= <NUM_LIT:0> : <EOL> return self . string [ group_indices [ <NUM_LIT:0> ] : group_indices [ <NUM_LIT:1> ] ] <EOL> else : <EOL> return default <EOL> def start ( self , group = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return self . regs [ self . _get_index ( group ) ] [ <NUM_LIT:0> ] <EOL> def end ( self , group = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return self . regs [ self . _get_index ( group ) ] [ <NUM_LIT:1> ] <EOL> def span ( self , group = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return self . start ( group ) , self . end ( group ) <EOL> def expand ( self , template ) : <EOL> """<STR_LIT>""" <EOL> import re <EOL> return re . _expand ( self . re , self , template ) <EOL> def groups ( self , default = None ) : <EOL> """<STR_LIT>""" <EOL> groups = [ ] <EOL> for indices in self . regs [ <NUM_LIT:1> : ] : <EOL> if indices [ <NUM_LIT:0> ] >= <NUM_LIT:0> : <EOL> groups . append ( self . string [ indices [ <NUM_LIT:0> ] : indices [ <NUM_LIT:1> ] ] ) <EOL> else : <EOL> groups . append ( default ) <EOL> return tuple ( groups ) <EOL> def groupdict ( self , default = None ) : <EOL> """<STR_LIT>""" <EOL> groupdict = { } <EOL> for key , value in self . re . groupindex . items ( ) : <EOL> groupdict [ key ] = self . _get_slice ( value , default ) <EOL> return groupdict <EOL> def group ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> args = ( <NUM_LIT:0> , ) <EOL> grouplist = [ ] <EOL> for group in args : <EOL> grouplist . append ( self . _get_slice ( self . _get_index ( group ) , None ) ) <EOL> if len ( grouplist ) == <NUM_LIT:1> : <EOL> return grouplist [ <NUM_LIT:0> ] <EOL> else : <EOL> return tuple ( grouplist ) <EOL> def __copy__ ( ) : <EOL> raise TypeError , "<STR_LIT>" <EOL> def __deepcopy__ ( ) : <EOL> raise TypeError , "<STR_LIT>" </s>
