Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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))
Beispiel #4
0
 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))
Beispiel #5
0
 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))
Beispiel #6
0
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)
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
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
Beispiel #10
0
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))
Beispiel #11
0
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))
Beispiel #12
0
 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)
Beispiel #13
0
 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)
Beispiel #14
0
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))
Beispiel #15
0
 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)
Beispiel #16
0
 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)
Beispiel #17
0
 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)
Beispiel #18
0
 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)
Beispiel #19
0
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))
Beispiel #20
0
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)
Beispiel #21
0
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 )
Beispiel #22
0
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
Beispiel #23
0
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))