<s> from pypy . tool . staticmethods import StaticMethods <EOL> from pypy . tool . pairtype import pairtype , pair <EOL> from pypy . annotation import model as annmodel <EOL> from pypy . rpython . error import TyperError <EOL> from pypy . rpython . rmodel import IntegerRepr , IteratorRepr <EOL> from pypy . rpython . rmodel import inputconst , Repr <EOL> from pypy . rpython . rtuple import AbstractTupleRepr <EOL> from pypy . rpython import rint <EOL> from pypy . rpython . lltypesystem . lltype import Signed , Bool , Void , UniChar , cast_primitive , typeOf <EOL> class AbstractStringRepr ( Repr ) : <EOL> pass <EOL> class AbstractCharRepr ( AbstractStringRepr ) : <EOL> pass <EOL> class AbstractUniCharRepr ( AbstractStringRepr ) : <EOL> pass <EOL> class AbstractUnicodeRepr ( AbstractStringRepr ) : <EOL> def rtype_method_upper ( self , hop ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> def rtype_method_lower ( self , hop ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> class __extend__ ( annmodel . SomeString ) : <EOL> def rtyper_makerepr ( self , rtyper ) : <EOL> return rtyper . type_system . rstr . string_repr <EOL> def rtyper_makekey ( self ) : <EOL> return self . __class__ , <EOL> class __extend__ ( annmodel . SomeUnicodeString ) : <EOL> def rtyper_makerepr ( self , rtyper ) : <EOL> return rtyper . type_system . rstr . unicode_repr <EOL> def rtyper_makekey ( self ) : <EOL> return self . __class__ , <EOL> class __extend__ ( annmodel . SomeChar ) : <EOL> def rtyper_makerepr ( self , rtyper ) : <EOL> return rtyper . type_system . rstr . char_repr <EOL> def rtyper_makekey ( self ) : <EOL> return self . __class__ , <EOL> class __extend__ ( annmodel . SomeUnicodeCodePoint ) : <EOL> def rtyper_makerepr ( self , rtyper ) : <EOL> return rtyper . type_system . rstr . unichar_repr <EOL> def rtyper_makekey ( self ) : <EOL> return self . __class__ , <EOL> class __extend__ ( AbstractStringRepr ) : <EOL> def _str_reprs ( self , hop ) : <EOL> return hop . args_r [ <NUM_LIT:0> ] . repr , hop . args_r [ <NUM_LIT:1> ] . repr <EOL> def get_ll_eq_function ( self ) : <EOL> return self . ll . ll_streq <EOL> def get_ll_hash_function ( self ) : <EOL> return self . ll . ll_strhash <EOL> def get_ll_fasthash_function ( self ) : <EOL> return self . ll . ll_strfasthash <EOL> def rtype_len ( self , hop ) : <EOL> string_repr = self . repr <EOL> v_str , = hop . inputargs ( string_repr ) <EOL> return hop . gendirectcall ( self . ll . ll_strlen , v_str ) <EOL> def rtype_is_true ( self , hop ) : <EOL> s_str = hop . args_s [ <NUM_LIT:0> ] <EOL> if s_str . can_be_None : <EOL> string_repr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> v_str , = hop . inputargs ( string_repr ) <EOL> return hop . gendirectcall ( self . ll . ll_str_is_true , v_str ) <EOL> else : <EOL> return super ( AbstractStringRepr , self ) . rtype_is_true ( hop ) <EOL> def rtype_ord ( self , hop ) : <EOL> string_repr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> v_str , = hop . inputargs ( string_repr ) <EOL> c_zero = inputconst ( Signed , <NUM_LIT:0> ) <EOL> v_chr = hop . gendirectcall ( self . ll . ll_stritem_nonneg , v_str , c_zero ) <EOL> if string_repr is hop . rtyper . type_system . rstr . string_repr : <EOL> return hop . genop ( '<STR_LIT>' , [ v_chr ] , resulttype = Signed ) <EOL> else : <EOL> assert string_repr is hop . rtyper . type_system . rstr . unicode_repr <EOL> return hop . genop ( '<STR_LIT>' , [ v_chr ] , resulttype = Signed ) <EOL> def rtype_method_startswith ( self , hop ) : <EOL> str1_repr , str2_repr = self . _str_reprs ( hop ) <EOL> v_str , v_value = hop . inputargs ( str1_repr , str2_repr ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( self . ll . ll_startswith , v_str , v_value ) <EOL> def rtype_method_endswith ( self , hop ) : <EOL> str1_repr , str2_repr = self . _str_reprs ( hop ) <EOL> v_str , v_value = hop . inputargs ( str1_repr , str2_repr ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( self . ll . ll_endswith , v_str , v_value ) <EOL> def rtype_method_find ( self , hop , reverse = False ) : <EOL> string_repr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> char_repr = hop . args_r [ <NUM_LIT:0> ] . char_repr <EOL> v_str = hop . inputarg ( string_repr , arg = <NUM_LIT:0> ) <EOL> if hop . args_r [ <NUM_LIT:1> ] == char_repr : <EOL> v_value = hop . inputarg ( char_repr , arg = <NUM_LIT:1> ) <EOL> llfn = reverse and self . ll . ll_rfind_char or self . ll . ll_find_char <EOL> else : <EOL> v_value = hop . inputarg ( string_repr , arg = <NUM_LIT:1> ) <EOL> llfn = reverse and self . ll . ll_rfind or self . ll . ll_find <EOL> if hop . nb_args > <NUM_LIT:2> : <EOL> v_start = hop . inputarg ( Signed , arg = <NUM_LIT:2> ) <EOL> if not hop . args_s [ <NUM_LIT:2> ] . nonneg : <EOL> raise TyperError ( "<STR_LIT>" ) <EOL> else : <EOL> v_start = hop . inputconst ( Signed , <NUM_LIT:0> ) <EOL> if hop . nb_args > <NUM_LIT:3> : <EOL> v_end = hop . inputarg ( Signed , arg = <NUM_LIT:3> ) <EOL> if not hop . args_s [ <NUM_LIT:3> ] . nonneg : <EOL> raise TyperError ( "<STR_LIT>" ) <EOL> else : <EOL> v_end = hop . gendirectcall ( self . ll . ll_strlen , v_str ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( llfn , v_str , v_value , v_start , v_end ) <EOL> def rtype_method_rfind ( self , hop ) : <EOL> return self . rtype_method_find ( hop , reverse = True ) <EOL> def rtype_method_count ( self , hop ) : <EOL> rstr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> v_str = hop . inputarg ( rstr . repr , arg = <NUM_LIT:0> ) <EOL> if hop . args_r [ <NUM_LIT:1> ] == rstr . char_repr : <EOL> v_value = hop . inputarg ( rstr . char_repr , arg = <NUM_LIT:1> ) <EOL> llfn = self . ll . ll_count_char <EOL> else : <EOL> v_value = hop . inputarg ( rstr . repr , arg = <NUM_LIT:1> ) <EOL> llfn = self . ll . ll_count <EOL> if hop . nb_args > <NUM_LIT:2> : <EOL> v_start = hop . inputarg ( Signed , arg = <NUM_LIT:2> ) <EOL> if not hop . args_s [ <NUM_LIT:2> ] . nonneg : <EOL> raise TyperError ( "<STR_LIT>" ) <EOL> else : <EOL> v_start = hop . inputconst ( Signed , <NUM_LIT:0> ) <EOL> if hop . nb_args > <NUM_LIT:3> : <EOL> v_end = hop . inputarg ( Signed , arg = <NUM_LIT:3> ) <EOL> if not hop . args_s [ <NUM_LIT:3> ] . nonneg : <EOL> raise TyperError ( "<STR_LIT>" ) <EOL> else : <EOL> v_end = hop . gendirectcall ( self . ll . ll_strlen , v_str ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( llfn , v_str , v_value , v_start , v_end ) <EOL> def rtype_method_strip ( self , hop , left = True , right = True ) : <EOL> rstr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> v_str = hop . inputarg ( rstr . repr , arg = <NUM_LIT:0> ) <EOL> v_char = hop . inputarg ( rstr . char_repr , arg = <NUM_LIT:1> ) <EOL> v_left = hop . inputconst ( Bool , left ) <EOL> v_right = hop . inputconst ( Bool , right ) <EOL> return hop . gendirectcall ( self . ll . ll_strip , v_str , v_char , v_left , v_right ) <EOL> def rtype_method_lstrip ( self , hop ) : <EOL> return self . rtype_method_strip ( hop , left = True , right = False ) <EOL> def rtype_method_rstrip ( self , hop ) : <EOL> return self . rtype_method_strip ( hop , left = False , right = True ) <EOL> def rtype_method_upper ( self , hop ) : <EOL> string_repr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> v_str , = hop . inputargs ( string_repr ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( self . ll . ll_upper , v_str ) <EOL> def rtype_method_lower ( self , hop ) : <EOL> string_repr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> v_str , = hop . inputargs ( string_repr ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( self . ll . ll_lower , v_str ) <EOL> def _list_length_items ( self , hop , v_lst , LIST ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def rtype_method_join ( self , hop ) : <EOL> hop . exception_cannot_occur ( ) <EOL> rstr = hop . args_r [ <NUM_LIT:0> ] <EOL> if hop . s_result . is_constant ( ) : <EOL> return inputconst ( rstr . repr , hop . s_result . const ) <EOL> r_lst = hop . args_r [ <NUM_LIT:1> ] <EOL> if not isinstance ( r_lst , hop . rtyper . type_system . rlist . BaseListRepr ) : <EOL> raise TyperError ( "<STR_LIT>" % r_lst ) <EOL> v_str , v_lst = hop . inputargs ( rstr . repr , r_lst ) <EOL> v_length , v_items = self . _list_length_items ( hop , v_lst , r_lst . lowleveltype ) <EOL> if hop . args_s [ <NUM_LIT:0> ] . is_constant ( ) and hop . args_s [ <NUM_LIT:0> ] . const == '<STR_LIT>' : <EOL> if r_lst . item_repr == rstr . repr : <EOL> llfn = self . ll . ll_join_strs <EOL> elif r_lst . item_repr == rstr . char_repr : <EOL> llfn = self . ll . ll_join_chars <EOL> else : <EOL> raise TyperError ( "<STR_LIT>" % r_lst ) <EOL> return hop . gendirectcall ( llfn , v_length , v_items ) <EOL> else : <EOL> if r_lst . item_repr == rstr . repr : <EOL> llfn = self . ll . ll_join <EOL> else : <EOL> raise TyperError ( "<STR_LIT>" % r_lst ) <EOL> return hop . gendirectcall ( llfn , v_str , v_length , v_items ) <EOL> def rtype_method_splitlines ( self , hop ) : <EOL> rstr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> if hop . nb_args == <NUM_LIT:2> : <EOL> args = hop . inputargs ( rstr . repr , Bool ) <EOL> else : <EOL> args = [ hop . inputarg ( rstr . repr , <NUM_LIT:0> ) , hop . inputconst ( Bool , False ) ] <EOL> try : <EOL> list_type = hop . r_result . lowleveltype . TO <EOL> except AttributeError : <EOL> list_type = hop . r_result . lowleveltype <EOL> cLIST = hop . inputconst ( Void , list_type ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( self . ll . ll_splitlines , cLIST , * args ) <EOL> def rtype_method_split ( self , hop ) : <EOL> rstr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> v_str , v_chr = hop . inputargs ( rstr . repr , rstr . char_repr ) <EOL> try : <EOL> list_type = hop . r_result . lowleveltype . TO <EOL> except AttributeError : <EOL> list_type = hop . r_result . lowleveltype <EOL> cLIST = hop . inputconst ( Void , list_type ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( self . ll . ll_split_chr , cLIST , v_str , v_chr ) <EOL> def rtype_method_replace ( self , hop ) : <EOL> rstr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> if not ( hop . args_r [ <NUM_LIT:1> ] == rstr . char_repr and hop . args_r [ <NUM_LIT:2> ] == rstr . char_repr ) : <EOL> raise TyperError , '<STR_LIT>' <EOL> v_str , v_c1 , v_c2 = hop . inputargs ( rstr . repr , rstr . char_repr , rstr . char_repr ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( self . ll . ll_replace_chr_chr , v_str , v_c1 , v_c2 ) <EOL> def rtype_int ( self , hop ) : <EOL> hop . has_implicit_exception ( ValueError ) <EOL> string_repr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> if hop . nb_args == <NUM_LIT:1> : <EOL> v_str , = hop . inputargs ( string_repr ) <EOL> c_base = inputconst ( Signed , <NUM_LIT:10> ) <EOL> hop . exception_is_here ( ) <EOL> return hop . gendirectcall ( self . ll . ll_int , v_str , c_base ) <EOL> if not hop . args_r [ <NUM_LIT:1> ] == rint . signed_repr : <EOL> raise TyperError , '<STR_LIT>' <EOL> v_str , v_base = hop . inputargs ( string_repr , rint . signed_repr ) <EOL> hop . exception_is_here ( ) <EOL> return hop . gendirectcall ( self . ll . ll_int , v_str , v_base ) <EOL> def rtype_unicode ( self , hop ) : <EOL> if hop . args_s [ <NUM_LIT:0> ] . is_constant ( ) : <EOL> return hop . inputconst ( hop . r_result , hop . s_result . const ) <EOL> repr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> v_str = hop . inputarg ( repr , <NUM_LIT:0> ) <EOL> if repr == hop . r_result : <EOL> hop . exception_cannot_occur ( ) <EOL> return v_str <EOL> hop . exception_is_here ( ) <EOL> return hop . gendirectcall ( self . ll . ll_str2unicode , v_str ) <EOL> def rtype_method_decode ( self , hop ) : <EOL> if not hop . args_s [ <NUM_LIT:1> ] . is_constant ( ) : <EOL> raise TyperError ( "<STR_LIT>" ) <EOL> encoding = hop . args_s [ <NUM_LIT:1> ] . const <EOL> v_self = hop . inputarg ( self . repr , <NUM_LIT:0> ) <EOL> hop . exception_is_here ( ) <EOL> if encoding == '<STR_LIT:ascii>' : <EOL> return hop . gendirectcall ( self . ll . ll_str2unicode , v_self ) <EOL> elif encoding == '<STR_LIT>' : <EOL> return hop . gendirectcall ( self . ll_decode_latin1 , v_self ) <EOL> else : <EOL> raise TyperError ( "<STR_LIT>" % ( encoding , ) ) <EOL> def rtype_float ( self , hop ) : <EOL> hop . has_implicit_exception ( ValueError ) <EOL> string_repr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> v_str , = hop . inputargs ( string_repr ) <EOL> hop . exception_is_here ( ) <EOL> return hop . gendirectcall ( self . ll . ll_float , v_str ) <EOL> def ll_str ( self , s ) : <EOL> return s <EOL> class __extend__ ( AbstractUnicodeRepr ) : <EOL> def rtype_method_encode ( self , hop ) : <EOL> if not hop . args_s [ <NUM_LIT:1> ] . is_constant ( ) : <EOL> raise TyperError ( "<STR_LIT>" ) <EOL> encoding = hop . args_s [ <NUM_LIT:1> ] . const <EOL> v_self = hop . inputarg ( self . repr , <NUM_LIT:0> ) <EOL> hop . exception_is_here ( ) <EOL> if encoding == "<STR_LIT:ascii>" : <EOL> return hop . gendirectcall ( self . ll_str , v_self ) <EOL> elif encoding == "<STR_LIT>" : <EOL> return hop . gendirectcall ( self . ll_encode_latin1 , v_self ) <EOL> else : <EOL> raise TyperError ( "<STR_LIT>" % ( encoding , ) ) <EOL> class __extend__ ( pairtype ( AbstractStringRepr , Repr ) ) : <EOL> def rtype_mod ( ( r_str , _ ) , hop ) : <EOL> return r_str . ll . do_stringformat ( hop , [ ( hop . args_v [ <NUM_LIT:1> ] , hop . args_r [ <NUM_LIT:1> ] ) ] ) <EOL> class __extend__ ( pairtype ( AbstractStringRepr , IntegerRepr ) ) : <EOL> def rtype_getitem ( ( r_str , r_int ) , hop , checkidx = False ) : <EOL> string_repr = r_str . repr <EOL> v_str , v_index = hop . inputargs ( string_repr , Signed ) <EOL> if checkidx : <EOL> if hop . args_s [ <NUM_LIT:1> ] . nonneg : <EOL> llfn = r_str . ll . ll_stritem_nonneg_checked <EOL> else : <EOL> llfn = r_str . ll . ll_stritem_checked <EOL> else : <EOL> if hop . args_s [ <NUM_LIT:1> ] . nonneg : <EOL> llfn = r_str . ll . ll_stritem_nonneg <EOL> else : <EOL> llfn = r_str . ll . ll_stritem <EOL> if checkidx : <EOL> hop . exception_is_here ( ) <EOL> else : <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( llfn , v_str , v_index ) <EOL> rtype_getitem_key = rtype_getitem <EOL> def rtype_getitem_idx ( ( r_str , r_int ) , hop ) : <EOL> return pair ( r_str , r_int ) . rtype_getitem ( hop , checkidx = True ) <EOL> rtype_getitem_idx_key = rtype_getitem_idx <EOL> class __extend__ ( AbstractStringRepr ) : <EOL> def rtype_getslice ( r_str , hop ) : <EOL> string_repr = r_str . repr <EOL> v_str = hop . inputarg ( string_repr , arg = <NUM_LIT:0> ) <EOL> kind , vlist = hop . decompose_slice_args ( ) <EOL> ll_fn = getattr ( r_str . ll , '<STR_LIT>' % ( kind , ) ) <EOL> return hop . gendirectcall ( ll_fn , v_str , * vlist ) <EOL> class __extend__ ( pairtype ( AbstractStringRepr , AbstractStringRepr ) ) : <EOL> def rtype_add ( ( r_str1 , r_str2 ) , hop ) : <EOL> str1_repr = r_str1 . repr <EOL> str2_repr = r_str2 . repr <EOL> if hop . s_result . is_constant ( ) : <EOL> return hop . inputconst ( str1_repr , hop . s_result . const ) <EOL> v_str1 , v_str2 = hop . inputargs ( str1_repr , str2_repr ) <EOL> return hop . gendirectcall ( r_str1 . ll . ll_strconcat , v_str1 , v_str2 ) <EOL> rtype_inplace_add = rtype_add <EOL> def rtype_eq ( ( r_str1 , r_str2 ) , hop ) : <EOL> v_str1 , v_str2 = hop . inputargs ( r_str1 . repr , r_str2 . repr ) <EOL> return hop . gendirectcall ( r_str1 . ll . ll_streq , v_str1 , v_str2 ) <EOL> def rtype_ne ( ( r_str1 , r_str2 ) , hop ) : <EOL> v_str1 , v_str2 = hop . inputargs ( r_str1 . repr , r_str2 . repr ) <EOL> vres = hop . gendirectcall ( r_str1 . ll . ll_streq , v_str1 , v_str2 ) <EOL> return hop . genop ( '<STR_LIT>' , [ vres ] , resulttype = Bool ) <EOL> def rtype_lt ( ( r_str1 , r_str2 ) , hop ) : <EOL> v_str1 , v_str2 = hop . inputargs ( r_str1 . repr , r_str2 . repr ) <EOL> vres = hop . gendirectcall ( r_str1 . ll . ll_strcmp , v_str1 , v_str2 ) <EOL> return hop . genop ( '<STR_LIT>' , [ vres , hop . inputconst ( Signed , <NUM_LIT:0> ) ] , <EOL> resulttype = Bool ) <EOL> def rtype_le ( ( r_str1 , r_str2 ) , hop ) : <EOL> v_str1 , v_str2 = hop . inputargs ( r_str1 . repr , r_str2 . repr ) <EOL> vres = hop . gendirectcall ( r_str1 . ll . ll_strcmp , v_str1 , v_str2 ) <EOL> return hop . genop ( '<STR_LIT>' , [ vres , hop . inputconst ( Signed , <NUM_LIT:0> ) ] , <EOL> resulttype = Bool ) <EOL> def rtype_ge ( ( r_str1 , r_str2 ) , hop ) : <EOL> v_str1 , v_str2 = hop . inputargs ( r_str1 . repr , r_str2 . repr ) <EOL> vres = hop . gendirectcall ( r_str1 . ll . ll_strcmp , v_str1 , v_str2 ) <EOL> return hop . genop ( '<STR_LIT>' , [ vres , hop . inputconst ( Signed , <NUM_LIT:0> ) ] , <EOL> resulttype = Bool ) <EOL> def rtype_gt ( ( r_str1 , r_str2 ) , hop ) : <EOL> v_str1 , v_str2 = hop . inputargs ( r_str1 . repr , r_str2 . repr ) <EOL> vres = hop . gendirectcall ( r_str1 . ll . ll_strcmp , v_str1 , v_str2 ) <EOL> return hop . genop ( '<STR_LIT>' , [ vres , hop . inputconst ( Signed , <NUM_LIT:0> ) ] , <EOL> resulttype = Bool ) <EOL> def rtype_contains ( ( r_str1 , r_str2 ) , hop ) : <EOL> v_str1 , v_str2 = hop . inputargs ( r_str1 . repr , r_str2 . repr ) <EOL> v_end = hop . gendirectcall ( r_str1 . ll . ll_strlen , v_str1 ) <EOL> vres = hop . gendirectcall ( r_str1 . ll . ll_find , v_str1 , v_str2 , <EOL> hop . inputconst ( Signed , <NUM_LIT:0> ) , v_end ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . genop ( '<STR_LIT>' , [ vres , hop . inputconst ( Signed , - <NUM_LIT:1> ) ] , <EOL> resulttype = Bool ) <EOL> class __extend__ ( pairtype ( AbstractStringRepr , AbstractCharRepr ) , <EOL> pairtype ( AbstractUnicodeRepr , AbstractUniCharRepr ) ) : <EOL> def rtype_contains ( ( r_str , r_chr ) , hop ) : <EOL> string_repr = r_str . repr <EOL> char_repr = r_chr . char_repr <EOL> v_str , v_chr = hop . inputargs ( string_repr , char_repr ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( r_str . ll . ll_contains , v_str , v_chr ) <EOL> class __extend__ ( pairtype ( AbstractStringRepr , AbstractTupleRepr ) ) : <EOL> def rtype_mod ( ( r_str , r_tuple ) , hop ) : <EOL> r_tuple = hop . args_r [ <NUM_LIT:1> ] <EOL> v_tuple = hop . args_v [ <NUM_LIT:1> ] <EOL> sourcevars = [ ] <EOL> for i , r_arg in enumerate ( r_tuple . external_items_r ) : <EOL> v_item = r_tuple . getitem ( hop . llops , v_tuple , i ) <EOL> sourcevars . append ( ( v_item , r_arg ) ) <EOL> return r_str . ll . do_stringformat ( hop , sourcevars ) <EOL> class __extend__ ( AbstractCharRepr , <EOL> AbstractUniCharRepr ) : <EOL> def convert_const ( self , value ) : <EOL> if not isinstance ( value , str ) or len ( value ) != <NUM_LIT:1> : <EOL> raise TyperError ( "<STR_LIT>" % ( value , ) ) <EOL> return value <EOL> def get_ll_eq_function ( self ) : <EOL> return None <EOL> def get_ll_hash_function ( self ) : <EOL> return self . ll . ll_char_hash <EOL> get_ll_fasthash_function = get_ll_hash_function <EOL> def ll_str ( self , ch ) : <EOL> return self . ll . ll_chr2str ( ch ) <EOL> def rtype_len ( _ , hop ) : <EOL> return hop . inputconst ( Signed , <NUM_LIT:1> ) <EOL> def rtype_is_true ( _ , hop ) : <EOL> assert not hop . args_s [ <NUM_LIT:0> ] . can_be_None <EOL> return hop . inputconst ( Bool , True ) <EOL> def rtype_ord ( _ , hop ) : <EOL> repr = hop . args_r [ <NUM_LIT:0> ] . char_repr <EOL> vlist = hop . inputargs ( repr ) <EOL> return hop . genop ( '<STR_LIT>' , vlist , resulttype = Signed ) <EOL> def _rtype_method_isxxx ( _ , llfn , hop ) : <EOL> repr = hop . args_r [ <NUM_LIT:0> ] . char_repr <EOL> vlist = hop . inputargs ( repr ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . gendirectcall ( llfn , vlist [ <NUM_LIT:0> ] ) <EOL> def rtype_method_isspace ( self , hop ) : <EOL> return self . _rtype_method_isxxx ( self . ll . ll_char_isspace , hop ) <EOL> def rtype_method_isdigit ( self , hop ) : <EOL> return self . _rtype_method_isxxx ( self . ll . ll_char_isdigit , hop ) <EOL> def rtype_method_isalpha ( self , hop ) : <EOL> return self . _rtype_method_isxxx ( self . ll . ll_char_isalpha , hop ) <EOL> def rtype_method_isalnum ( self , hop ) : <EOL> return self . _rtype_method_isxxx ( self . ll . ll_char_isalnum , hop ) <EOL> def rtype_method_isupper ( self , hop ) : <EOL> return self . _rtype_method_isxxx ( self . ll . ll_char_isupper , hop ) <EOL> def rtype_method_islower ( self , hop ) : <EOL> return self . _rtype_method_isxxx ( self . ll . ll_char_islower , hop ) <EOL> class __extend__ ( pairtype ( AbstractCharRepr , IntegerRepr ) , <EOL> pairtype ( AbstractUniCharRepr , IntegerRepr ) ) : <EOL> def rtype_mul ( ( r_chr , r_int ) , hop ) : <EOL> char_repr = r_chr . char_repr <EOL> v_char , v_int = hop . inputargs ( char_repr , Signed ) <EOL> return hop . gendirectcall ( r_chr . ll . ll_char_mul , v_char , v_int ) <EOL> rtype_inplace_mul = rtype_mul <EOL> class __extend__ ( pairtype ( IntegerRepr , AbstractCharRepr ) , <EOL> pairtype ( IntegerRepr , AbstractUniCharRepr ) ) : <EOL> def rtype_mul ( ( r_int , r_chr ) , hop ) : <EOL> char_repr = r_chr . char_repr <EOL> v_int , v_char = hop . inputargs ( Signed , char_repr ) <EOL> return hop . gendirectcall ( r_chr . ll . ll_char_mul , v_char , v_int ) <EOL> rtype_inplace_mul = rtype_mul <EOL> class __extend__ ( pairtype ( AbstractCharRepr , AbstractCharRepr ) ) : <EOL> def rtype_eq ( _ , hop ) : return _rtype_compare_template ( hop , '<STR_LIT>' ) <EOL> def rtype_ne ( _ , hop ) : return _rtype_compare_template ( hop , '<STR_LIT>' ) <EOL> def rtype_lt ( _ , hop ) : return _rtype_compare_template ( hop , '<STR_LIT>' ) <EOL> def rtype_le ( _ , hop ) : return _rtype_compare_template ( hop , '<STR_LIT>' ) <EOL> def rtype_gt ( _ , hop ) : return _rtype_compare_template ( hop , '<STR_LIT>' ) <EOL> def rtype_ge ( _ , hop ) : return _rtype_compare_template ( hop , '<STR_LIT>' ) <EOL> def _rtype_compare_template ( hop , func ) : <EOL> rstr = hop . rtyper . type_system . rstr <EOL> vlist = hop . inputargs ( rstr . char_repr , rstr . char_repr ) <EOL> return hop . genop ( '<STR_LIT>' + func , vlist , resulttype = Bool ) <EOL> class __extend__ ( AbstractUniCharRepr ) : <EOL> def convert_const ( self , value ) : <EOL> if isinstance ( value , str ) : <EOL> value = unicode ( value ) <EOL> if not isinstance ( value , unicode ) or len ( value ) != <NUM_LIT:1> : <EOL> raise TyperError ( "<STR_LIT>" % ( value , ) ) <EOL> return value <EOL> def get_ll_eq_function ( self ) : <EOL> return None <EOL> def get_ll_hash_function ( self ) : <EOL> return self . ll . ll_unichar_hash <EOL> get_ll_fasthash_function = get_ll_hash_function <EOL> def rtype_ord ( _ , hop ) : <EOL> rstr = hop . rtyper . type_system . rstr <EOL> vlist = hop . inputargs ( rstr . unichar_repr ) <EOL> return hop . genop ( '<STR_LIT>' , vlist , resulttype = Signed ) <EOL> class __extend__ ( pairtype ( AbstractUniCharRepr , AbstractUniCharRepr ) , <EOL> pairtype ( AbstractCharRepr , AbstractUniCharRepr ) , <EOL> pairtype ( AbstractUniCharRepr , AbstractCharRepr ) ) : <EOL> def rtype_eq ( _ , hop ) : return _rtype_unchr_compare_template ( hop , '<STR_LIT>' ) <EOL> def rtype_ne ( _ , hop ) : return _rtype_unchr_compare_template ( hop , '<STR_LIT>' ) <EOL> def _rtype_unchr_compare_template ( hop , func ) : <EOL> rstr = hop . rtyper . type_system . rstr <EOL> vlist = hop . inputargs ( rstr . unichar_repr , rstr . unichar_repr ) <EOL> return hop . genop ( '<STR_LIT>' + func , vlist , resulttype = Bool ) <EOL> class __extend__ ( pairtype ( AbstractCharRepr , AbstractStringRepr ) , <EOL> pairtype ( AbstractUniCharRepr , AbstractUnicodeRepr ) ) : <EOL> def convert_from_to ( ( r_from , r_to ) , v , llops ) : <EOL> rstr = llops . rtyper . type_system . rstr <EOL> if ( r_from == rstr . char_repr and r_to == rstr . string_repr ) or ( r_from == rstr . unichar_repr and r_to == rstr . unicode_repr ) : <EOL> return llops . gendirectcall ( r_from . ll . ll_chr2str , v ) <EOL> return NotImplemented <EOL> class __extend__ ( pairtype ( AbstractStringRepr , AbstractCharRepr ) ) : <EOL> def convert_from_to ( ( r_from , r_to ) , v , llops ) : <EOL> rstr = llops . rtyper . type_system . rstr <EOL> if r_from == rstr . string_repr and r_to == rstr . char_repr : <EOL> c_zero = inputconst ( Signed , <NUM_LIT:0> ) <EOL> return llops . gendirectcall ( r_from . ll . ll_stritem_nonneg , v , c_zero ) <EOL> return NotImplemented <EOL> class __extend__ ( pairtype ( AbstractCharRepr , AbstractUniCharRepr ) ) : <EOL> def convert_from_to ( ( r_from , r_to ) , v , llops ) : <EOL> v2 = llops . genop ( '<STR_LIT>' , [ v ] , resulttype = Signed ) <EOL> return llops . genop ( '<STR_LIT>' , [ v2 ] , resulttype = UniChar ) <EOL> class AbstractStringIteratorRepr ( IteratorRepr ) : <EOL> def newiter ( self , hop ) : <EOL> string_repr = hop . args_r [ <NUM_LIT:0> ] . repr <EOL> v_str , = hop . inputargs ( string_repr ) <EOL> return hop . gendirectcall ( self . ll_striter , v_str ) <EOL> def rtype_next ( self , hop ) : <EOL> v_iter , = hop . inputargs ( self ) <EOL> hop . has_implicit_exception ( StopIteration ) <EOL> hop . exception_is_here ( ) <EOL> return hop . gendirectcall ( self . ll_strnext , v_iter ) <EOL> class AbstractLLHelpers : <EOL> __metaclass__ = StaticMethods <EOL> def ll_char_isspace ( ch ) : <EOL> c = ord ( ch ) <EOL> return c == <NUM_LIT:32> or ( c <= <NUM_LIT> and c >= <NUM_LIT:9> ) <EOL> def ll_char_isdigit ( ch ) : <EOL> c = ord ( ch ) <EOL> return c <= <NUM_LIT> and c >= <NUM_LIT> <EOL> def ll_char_isalpha ( ch ) : <EOL> c = ord ( ch ) <EOL> if c >= <NUM_LIT> : <EOL> return c <= <NUM_LIT> <EOL> else : <EOL> return <NUM_LIT> <= c <= <NUM_LIT> <EOL> def ll_char_isalnum ( ch ) : <EOL> c = ord ( ch ) <EOL> if c >= <NUM_LIT> : <EOL> if c >= <NUM_LIT> : <EOL> return c <= <NUM_LIT> <EOL> else : <EOL> return c <= <NUM_LIT> <EOL> else : <EOL> return <NUM_LIT> <= c <= <NUM_LIT> <EOL> def ll_char_isupper ( ch ) : <EOL> c = ord ( ch ) <EOL> return <NUM_LIT> <= c <= <NUM_LIT> <EOL> def ll_char_islower ( ch ) : <EOL> c = ord ( ch ) <EOL> return <NUM_LIT> <= c <= <NUM_LIT> <EOL> def ll_char_hash ( ch ) : <EOL> return ord ( ch ) <EOL> def ll_unichar_hash ( ch ) : <EOL> return ord ( ch ) <EOL> def ll_str_is_true ( cls , s ) : <EOL> return bool ( s ) and cls . ll_strlen ( s ) != <NUM_LIT:0> <EOL> ll_str_is_true = classmethod ( ll_str_is_true ) <EOL> def ll_stritem_nonneg_checked ( cls , s , i ) : <EOL> if i >= cls . ll_strlen ( s ) : <EOL> raise IndexError <EOL> return cls . ll_stritem_nonneg ( s , i ) <EOL> ll_stritem_nonneg_checked = classmethod ( ll_stritem_nonneg_checked ) <EOL> def ll_stritem ( cls , s , i ) : <EOL> if i < <NUM_LIT:0> : <EOL> i += cls . ll_strlen ( s ) <EOL> return cls . ll_stritem_nonneg ( s , i ) <EOL> ll_stritem = classmethod ( ll_stritem ) <EOL> def ll_stritem_checked ( cls , s , i ) : <EOL> length = cls . ll_strlen ( s ) <EOL> if i < <NUM_LIT:0> : <EOL> i += length <EOL> if i >= length or i < <NUM_LIT:0> : <EOL> raise IndexError <EOL> return cls . ll_stritem_nonneg ( s , i ) <EOL> ll_stritem_checked = classmethod ( ll_stritem_checked ) <EOL> def parse_fmt_string ( fmt ) : <EOL> it = iter ( fmt ) <EOL> r = [ ] <EOL> curstr = '<STR_LIT>' <EOL> for c in it : <EOL> if c == '<STR_LIT:%>' : <EOL> f = it . next ( ) <EOL> if f == '<STR_LIT:%>' : <EOL> curstr += '<STR_LIT:%>' <EOL> continue <EOL> if curstr : <EOL> r . append ( curstr ) <EOL> curstr = '<STR_LIT>' <EOL> if f not in '<STR_LIT>' : <EOL> raise TyperError ( "<STR_LIT>" % ( f , fmt ) ) <EOL> r . append ( ( f , ) ) <EOL> else : <EOL> curstr += c <EOL> if curstr : <EOL> r . append ( curstr ) <EOL> return r <EOL> def ll_float ( ll_str ) : <EOL> from pypy . rpython . annlowlevel import hlstr <EOL> from pypy . rlib . rarithmetic import break_up_float , parts_to_float <EOL> s = hlstr ( ll_str ) <EOL> assert s is not None <EOL> n = len ( s ) <EOL> beg = <NUM_LIT:0> <EOL> while beg < n : <EOL> if s [ beg ] == '<STR_LIT:U+0020>' : <EOL> beg += <NUM_LIT:1> <EOL> else : <EOL> break <EOL> if beg == n : <EOL> raise ValueError <EOL> end = n - <NUM_LIT:1> <EOL> while end >= <NUM_LIT:0> : <EOL> if s [ end ] == '<STR_LIT:U+0020>' : <EOL> end -= <NUM_LIT:1> <EOL> else : <EOL> break <EOL> assert end >= <NUM_LIT:0> <EOL> sign , before_point , after_point , exponent = break_up_float ( s [ beg : end + <NUM_LIT:1> ] ) <EOL> if not before_point and not after_point : <EOL> raise ValueError <EOL> return parts_to_float ( sign , before_point , after_point , exponent ) <EOL> def ll_splitlines ( cls , LIST , ll_str , keep_newlines ) : <EOL> from pypy . rpython . annlowlevel import hlstr <EOL> s = hlstr ( ll_str ) <EOL> STR = typeOf ( ll_str ) <EOL> strlen = len ( s ) <EOL> i = <NUM_LIT:0> <EOL> j = <NUM_LIT:0> <EOL> res = LIST . ll_newlist ( <NUM_LIT:0> ) <EOL> while j < strlen : <EOL> while i < strlen and s [ i ] != '<STR_LIT:\n>' and s [ i ] != '<STR_LIT:\r>' : <EOL> i += <NUM_LIT:1> <EOL> eol = i <EOL> if i < strlen : <EOL> if s [ i ] == '<STR_LIT:\r>' and i + <NUM_LIT:1> < strlen and s [ i + <NUM_LIT:1> ] == '<STR_LIT:\n>' : <EOL> i += <NUM_LIT:2> <EOL> else : <EOL> i += <NUM_LIT:1> <EOL> if keep_newlines : <EOL> eol = i <EOL> list_length = res . ll_length ( ) <EOL> res . _ll_resize_ge ( list_length + <NUM_LIT:1> ) <EOL> item = cls . ll_stringslice_startstop ( ll_str , j , eol ) <EOL> res . ll_setitem_fast ( list_length , item ) <EOL> j = i <EOL> if j < strlen : <EOL> list_length = res . ll_length ( ) <EOL> res . _ll_resize_ge ( list_length + <NUM_LIT:1> ) <EOL> item = cls . ll_stringslice_startstop ( ll_str , j , strlen ) <EOL> res . ll_setitem_fast ( list_length , item ) <EOL> return res <EOL> ll_splitlines = classmethod ( ll_splitlines ) </s>
