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


Python StringBuilder.getlength方法代码示例

本文整理汇总了Python中pypy.rlib.rstring.StringBuilder.getlength方法的典型用法代码示例。如果您正苦于以下问题:Python StringBuilder.getlength方法的具体用法?Python StringBuilder.getlength怎么用?Python StringBuilder.getlength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pypy.rlib.rstring.StringBuilder的用法示例。


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

示例1: test_string_builder

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import getlength [as 别名]
def test_string_builder():
    s = StringBuilder()
    s.append("a")
    s.append("abc")
    assert s.getlength() == len('aabc')
    s.append("a")
    s.append_slice("abc", 1, 2)
    s.append_multiple_char('d', 4)
    assert s.build() == "aabcabdddd"
开发者ID:gorakhargosh,项目名称:pypy,代码行数:11,代码来源:test_rstring.py

示例2: readall_w

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import getlength [as 别名]
    def readall_w(self, space):
        builder = StringBuilder()
        while True:
            w_data = space.call_method(self, "read", space.wrap(DEFAULT_BUFFER_SIZE))
            if space.is_w(w_data, space.w_None):
                if not builder.getlength():
                    return w_data
                break

            if not space.isinstance_w(w_data, space.w_str):
                raise OperationError(space.w_TypeError, space.wrap("read() should return bytes"))
            data = space.str_w(w_data)
            if not data:
                break
            builder.append(data)
        return space.wrap(builder.build())
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:18,代码来源:interp_iobase.py

示例3: a2b_uu

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import getlength [as 别名]
def a2b_uu(space, ascii):
    "Decode a line of uuencoded data."

    if len(ascii) == 0:    # obscure case, for compability with CPython
        length = (-0x20) & 0x3f
    else:
        length = (ord(ascii[0]) - 0x20) & 0x3f
    res = StringBuilder(length)

    for i in range(1, len(ascii), 4):
        A = _a2b_read(space, ascii, i)
        B = _a2b_read(space, ascii, i+1)
        C = _a2b_read(space, ascii, i+2)
        D = _a2b_read(space, ascii, i+3)
        #
        _a2b_write(space, res, length, A << 2 | B >> 4)
        _a2b_write(space, res, length, (B & 0xf) << 4 | C >> 2)
        _a2b_write(space, res, length, (C & 0x3) << 6 | D)

    remaining = length - res.getlength()
    if remaining > 0:
        res.append_multiple_char('\x00', remaining)
    return space.wrap(res.build())
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:interp_uu.py

示例4: PackFormatIterator

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import getlength [as 别名]
class PackFormatIterator(FormatIterator):

    def __init__(self, space, args_w, size):
        self.space = space
        self.args_w = args_w
        self.args_index = 0
        self.result = StringBuilder(size)

    # This *should* be always unroll safe, the only way to get here is by
    # unroll the interpret function, which means the fmt is const, and thus
    # this should be const (in theory ;)
    @jit.unroll_safe
    @specialize.arg(1)
    def operate(self, fmtdesc, repetitions):
        if fmtdesc.needcount:
            fmtdesc.pack(self, repetitions)
        else:
            for i in range(repetitions):
                fmtdesc.pack(self)
    _operate_is_specialized_ = True

    @jit.unroll_safe
    def align(self, mask):
        pad = (-self.result.getlength()) & mask
        self.result.append_multiple_char('\x00', pad)

    def finished(self):
        if self.args_index != len(self.args_w):
            raise StructError("too many arguments for struct format")

    def accept_obj_arg(self):
        try:
            w_obj = self.args_w[self.args_index]
        except IndexError:
            raise StructError("struct format requires more arguments")
        self.args_index += 1
        return w_obj

    if PACK_ACCEPTS_BROKEN_INPUT:
        # permissive version - accepts float arguments too

        def accept_int_arg(self):
            return self._accept_integral("int_w")

        def accept_uint_arg(self):
            return self._accept_integral("uint_w")

        def accept_longlong_arg(self):
            return self._accept_integral("r_longlong_w")

        def accept_ulonglong_arg(self):
            return self._accept_integral("r_ulonglong_w")

        @specialize.arg(1)
        def _accept_integral(self, meth):
            space = self.space
            w_obj = self.accept_obj_arg()
            if (space.isinstance_w(w_obj, space.w_int) or
                space.isinstance_w(w_obj, space.w_long)):
                w_index = w_obj
            else:
                w_index = None
                w_index_method = space.lookup(w_obj, "__index__")
                if w_index_method is not None:
                    try:
                        w_index = space.index(w_obj)
                    except OperationError, e:
                        if not e.match(space, space.w_TypeError):
                            raise
                        pass
                if w_index is None:
                    w_index = self._maybe_float(w_obj)
            return getattr(space, meth)(w_index)

        def _maybe_float(self, w_obj):
            space = self.space
            if space.is_true(space.isinstance(w_obj, space.w_float)):
                space.warn("struct: integer argument expected, got float",
                           space.w_DeprecationWarning)
            else:
                space.warn("integer argument expected, got non-integer",
                           space.w_DeprecationWarning)
            return space.int(w_obj)   # wrapped float -> wrapped int or long
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:85,代码来源:formatiterator.py

示例5: func

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import getlength [as 别名]
 def func():
     s = StringBuilder()
     s.append("a")
     s.append("abc")
     return s.getlength()
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_rbuilder.py


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