def str_decode__String_ANY_ANY(space, w_string, w_encoding=None, w_errors=None): from pypy.objspace.std.unicodetype import _get_encoding_and_errors, \ unicode_from_string, decode_object encoding, errors = _get_encoding_and_errors(space, w_encoding, w_errors) if encoding is None and errors is None: return unicode_from_string(space, w_string) return decode_object(space, w_string, encoding, errors)
def add__Unicode_String(space, w_left, w_right): # this function is needed to make 'abc'.__radd__(u'def') return # u'defabc', although it's completely unclear if that's necessary # given that CPython doesn't even have a method str.__radd__(). from pypy.objspace.std.unicodetype import unicode_from_string return space.add(w_left, unicode_from_string(space, w_right))
def unicode_w(w_self, space): # Use the default encoding. from pypy.objspace.std.unicodetype import (unicode_from_string, decode_object, _get_encoding_and_errors) w_defaultencoding = space.call_function(space.sys.get( 'getdefaultencoding')) encoding, errors = _get_encoding_and_errors(space, w_defaultencoding, space.w_None) if encoding is None and errors is None: return space.unicode_w(unicode_from_string(space, w_self)) return space.unicode_w(decode_object(space, w_self, encoding, errors))
def add__String_Unicode(space, w_left, w_right): # this function is needed to make 'abc'.__add__(u'def') return # u'abcdef' instead of NotImplemented. This is what occurs on # top of CPython. from pypy.objspace.std.unicodetype import unicode_from_string # XXX fragile implementation detail: for "string + unicode subclass", # if the unicode subclass overrides __radd__(), then it will be # called (see test_str_unicode_concat_overrides). This occurs as a # result of the following call to space.add() in which the first # argument is a unicode and the second argument a subclass of unicode # (and thus the usual logic about calling __radd__() first applies). return space.add(unicode_from_string(space, w_left) , w_right)
def str_rindex__String_Unicode_ANY_ANY(space, w_self, w_substr, w_start, w_end): from pypy.objspace.std.unicodetype import unicode_from_string return space.call_method(unicode_from_string(space, w_self), 'rindex', w_substr, w_start, w_end)
def str_rstrip__String_Unicode(space, w_self, w_chars): from pypy.objspace.std.unicodetype import unicode_from_string return space.call_method(unicode_from_string(space, w_self), 'rstrip', w_chars)
def delegate_String2Unicode(space, w_str): from pypy.objspace.std.unicodetype import unicode_from_string w_uni = unicode_from_string(space, w_str) assert isinstance(w_uni, W_UnicodeObject) # help the annotator! return w_uni
def unicode_rstrip__Unicode_String(space, w_self, w_chars): from pypy.objspace.std.unicodetype import unicode_from_string return space.call_method(w_self, 'rstrip', unicode_from_string(space, w_chars))
def add__Unicode_String(space, w_left, w_right): from pypy.objspace.std.unicodetype import unicode_from_string return space.add(w_left, unicode_from_string(space, w_right))
def str_replace__String_Unicode_Unicode_ANY(space, w_self, w_old, w_new, w_maxsplit): from pypy.objspace.std.unicodetype import unicode_from_string return space.call_method(unicode_from_string(space, w_self), 'replace', w_old, w_new, w_maxsplit)
def str_lstrip__String_Unicode(space, w_self, w_chars): from pypy.objspace.std.unicodetype import unicode_from_string return space.call_method(unicode_from_string(space, w_self), 'lstrip', w_chars)
def str_rsplit__String_Unicode_ANY(space, w_self, w_delim, w_maxsplit): from pypy.objspace.std.unicodetype import unicode_from_string return space.call_method(unicode_from_string(space, w_self), 'rsplit', w_delim, w_maxsplit)
def contains__String_Unicode(space, w_container, w_item): from pypy.objspace.std.unicodetype import unicode_from_string return space.contains(unicode_from_string(space, w_container), w_item)
def contains__String_Unicode(space, w_container, w_item): from pypy.objspace.std.unicodetype import unicode_from_string return space.contains(unicode_from_string(space, w_container), w_item )
def unicode_lstrip__Unicode_String(space, w_self, w_chars): from pypy.objspace.std.unicodetype import unicode_from_string return space.call_method(w_self, 'lstrip', unicode_from_string(space, w_chars))