当前位置: 首页>>代码示例>>Python>>正文


Python unicodetype.encode_object函数代码示例

本文整理汇总了Python中pypy.objspace.std.unicodetype.encode_object函数的典型用法代码示例。如果您正苦于以下问题:Python encode_object函数的具体用法?Python encode_object怎么用?Python encode_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了encode_object函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init__Bytearray

def init__Bytearray(space, w_bytearray, __args__):
    # this is on the silly side
    w_source, w_encoding, w_errors = __args__.parse_obj(
            None, 'bytearray', init_signature, init_defaults)

    if w_source is None:
        w_source = space.wrap('')
    if w_encoding is None:
        w_encoding = space.w_None
    if w_errors is None:
        w_errors = space.w_None

    # Unicode argument
    if not space.is_w(w_encoding, space.w_None):
        from pypy.objspace.std.unicodetype import (
            _get_encoding_and_errors, encode_object
        )
        encoding, errors = _get_encoding_and_errors(space, w_encoding, w_errors)

        # if w_source is an integer this correctly raises a TypeError
        # the CPython error message is: "encoding or errors without a string argument"
        # ours is: "expected unicode, got int object"
        w_source = encode_object(space, w_source, encoding, errors)

    # Is it an int?
    try:
        count = space.int_w(w_source)
    except OperationError, e:
        if not e.match(space, space.w_TypeError):
            raise
开发者ID:ieure,项目名称:pypy,代码行数:30,代码来源:bytearrayobject.py

示例2: unicode_encode__Unicode_ANY_ANY

def unicode_encode__Unicode_ANY_ANY(space, w_unistr, w_encoding=None, w_errors=None):

    from pypy.objspace.std.unicodetype import _get_encoding_and_errors
    from pypy.objspace.std.unicodetype import encode_object

    encoding, errors = _get_encoding_and_errors(space, w_encoding, w_errors)
    w_retval = encode_object(space, w_unistr, encoding, errors)
    return w_retval
开发者ID:pombredanne,项目名称:pypy,代码行数:8,代码来源:unicodeobject.py

示例3: unicode_encode__Unicode_ANY_ANY

def unicode_encode__Unicode_ANY_ANY(space, w_unistr,
                                    w_encoding=None,
                                    w_errors=None):

    from pypy.objspace.std.unicodetype import getdefaultencoding, \
        _get_encoding_and_errors, encode_object
    encoding, errors = _get_encoding_and_errors(space, w_encoding, w_errors)
    if encoding is None:
        encoding = getdefaultencoding(space)
    w_retval = encode_object(space, w_unistr, encoding, errors)
    return w_retval
开发者ID:antoine1fr,项目名称:pygirl,代码行数:11,代码来源:unicodeobject.py

示例4: unicode_call_errorhandler

        def unicode_call_errorhandler(errors,  encoding, reason, input,
                                      startpos, endpos):

            w_errorhandler = lookup_error(space, errors)
            if decode:
                w_cls = space.w_UnicodeDecodeError
            else:
                w_cls = space.w_UnicodeEncodeError
            w_exc =  space.call_function(
                w_cls,
                space.wrap(encoding),
                space.wrap(input),
                space.wrap(startpos),
                space.wrap(endpos),
                space.wrap(reason))
            w_res = space.call_function(w_errorhandler, w_exc)
            if (not space.is_true(space.isinstance(w_res, space.w_tuple))
                or space.len_w(w_res) != 2
                or not space.is_true(space.isinstance(
                                 space.getitem(w_res, space.wrap(0)),
                                 space.w_unicode))):
                if decode:
                    msg = ("decoding error handler must return "
                           "(unicode, int) tuple, not %s")
                else:
                    msg = ("encoding error handler must return "
                           "(unicode, int) tuple, not %s")
                raise operationerrfmt(
                    space.w_TypeError, msg,
                    space.str_w(space.repr(w_res)))
            w_replace, w_newpos = space.fixedview(w_res, 2)
            newpos = space.int_w(w_newpos)
            if newpos < 0:
                newpos = len(input) + newpos
            if newpos < 0 or newpos > len(input):
                raise operationerrfmt(
                    space.w_IndexError,
                    "position %d from error handler out of bounds", newpos)
            if decode:
                replace = space.unicode_w(w_replace)
                return replace, newpos
            else:
                from pypy.objspace.std.unicodetype import encode_object
                w_str = encode_object(space, w_replace, encoding, None)
                replace = space.str_w(w_str)
                return replace, newpos
开发者ID:ieure,项目名称:pypy,代码行数:46,代码来源:interp_codecs.py

示例5: str__Unicode

def str__Unicode(space, w_uni):
    from pypy.objspace.std.unicodetype import encode_object
    return encode_object(space, w_uni, None, None)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:3,代码来源:unicodeobject.py

示例6: encode

def encode(space, w_data, encoding=None, errors='strict'):
    from pypy.objspace.std.unicodetype import encode_object
    return encode_object(space, w_data, encoding, errors)
开发者ID:charred,项目名称:pypy,代码行数:3,代码来源:unicodehelper.py


注:本文中的pypy.objspace.std.unicodetype.encode_object函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。