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


Python StringBuilder.append_multiple_char方法代码示例

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


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

示例1: fn

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_multiple_char [as 别名]
 def fn(_):
     s = StringBuilder()
     s.append("a")
     s.append("abc")
     s.append_slice("abc", 1, 2)
     s.append_multiple_char('d', 4)
     return s.build()
开发者ID:pombredanne,项目名称:pypy,代码行数:9,代码来源:test_newgc.py

示例2: rledecode_hqx

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_multiple_char [as 别名]
def rledecode_hqx(space, hexbin):
    "Decode hexbin RLE-coded string."

    # that's a guesstimation of the resulting length
    res = StringBuilder(len(hexbin))

    end = len(hexbin)
    i = 0
    lastpushed = -1
    while i < end:
        c = hexbin[i]
        i += 1
        if c != '\x90':
            res.append(c)
            lastpushed = ord(c)
        else:
            if i == end:
                raise_Incomplete(space, 'String ends with the RLE code \x90')
            count = ord(hexbin[i]) - 1
            i += 1
            if count < 0:
                res.append('\x90')
                lastpushed = 0x90
            else:
                if lastpushed < 0:
                    raise_Error(space, 'String starts with the RLE code \x90')
                res.append_multiple_char(chr(lastpushed), count)
    return space.wrap(res.build())
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:30,代码来源:interp_hqx.py

示例3: test_string_builder

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

示例4: fn

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_multiple_char [as 别名]
 def fn():
     s = StringBuilder(4)
     s.append("abcd")
     s.append("defg")
     s.append("rty")
     s.append_multiple_char('y', 1000)
     gc.collect()
     s.append_multiple_char('y', 1000)
     res = s.build()[1000]
     gc.collect()
     return ord(res)
开发者ID:alkorzt,项目名称:pypy,代码行数:13,代码来源:test_transformed_gc.py

示例5: str_zfill__String_ANY

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_multiple_char [as 别名]
def str_zfill__String_ANY(space, w_self, w_width):
    input = w_self._value
    width = space.int_w(w_width)

    num_zeros = width - len(input)
    if num_zeros <= 0:
        # cannot return w_self, in case it is a subclass of str
        return space.wrap(input)

    builder = StringBuilder(width)
    if len(input) > 0 and (input[0] == '+' or input[0] == '-'):
        builder.append(input[0])
        start = 1
    else:
        start = 0

    builder.append_multiple_char('0', num_zeros)
    builder.append_slice(input, start, len(input))
    return space.wrap(builder.build())
开发者ID:craigkerstiens,项目名称:pypy,代码行数:21,代码来源:stringobject.py

示例6: a2b_uu

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_multiple_char [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

示例7: PackFormatIterator

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_multiple_char [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

示例8: format_number

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_multiple_char [as 别名]
def format_number(digits, buflen, sign, decpt, code, precision, flags, upper):
    # We got digits back, format them.  We may need to pad 'digits'
    # either on the left or right (or both) with extra zeros, so in
    # general the resulting string has the form
    #
    # [<sign>]<zeros><digits><zeros>[<exponent>]
    #
    # where either of the <zeros> pieces could be empty, and there's a
    # decimal point that could appear either in <digits> or in the
    # leading or trailing <zeros>.
    #
    # Imagine an infinite 'virtual' string vdigits, consisting of the
    # string 'digits' (starting at index 0) padded on both the left
    # and right with infinite strings of zeros.  We want to output a
    # slice
    #
    # vdigits[vdigits_start : vdigits_end]
    #
    # of this virtual string.  Thus if vdigits_start < 0 then we'll
    # end up producing some leading zeros; if vdigits_end > digits_len
    # there will be trailing zeros in the output.  The next section of
    # code determines whether to use an exponent or not, figures out
    # the position 'decpt' of the decimal point, and computes
    # 'vdigits_start' and 'vdigits_end'.
    builder = StringBuilder(20)

    use_exp = False
    vdigits_end = buflen
    if code == 'e':
        use_exp = True
        vdigits_end = precision
    elif code == 'f':
        vdigits_end = decpt + precision
    elif code == 'g':
        if decpt <= -4:
            use_exp = True
        elif decpt > precision:
            use_exp = True
        elif flags & rfloat.DTSF_ADD_DOT_0 and decpt == precision:
            use_exp = True
        if flags & rfloat.DTSF_ALT:
            vdigits_end = precision
    elif code == 'r':
        #  convert to exponential format at 1e16.  We used to convert
        #  at 1e17, but that gives odd-looking results for some values
        #  when a 16-digit 'shortest' repr is padded with bogus zeros.
        #  For example, repr(2e16+8) would give 20000000000000010.0;
        #  the true value is 20000000000000008.0.
        if decpt <= -4 or decpt > 16:
            use_exp = True
    else:
        raise ValueError

    # if using an exponent, reset decimal point position to 1 and
    # adjust exponent accordingly.
    if use_exp:
        exp = decpt - 1
        decpt = 1
    else:
        exp = 0

    # ensure vdigits_start < decpt <= vdigits_end, or vdigits_start <
    # decpt < vdigits_end if add_dot_0_if_integer and no exponent
    if decpt <= 0:
        vdigits_start = decpt-1
    else:
        vdigits_start = 0
    if vdigits_end <= decpt:
        if not use_exp and flags & rfloat.DTSF_ADD_DOT_0:
            vdigits_end = decpt + 1
        else:
            vdigits_end = decpt

    # double check inequalities
    assert vdigits_start <= 0
    assert 0 <= buflen <= vdigits_end
    # decimal point should be in (vdigits_start, vdigits_end]
    assert vdigits_start < decpt <= vdigits_end

    if sign == 1:
        builder.append('-')
    elif flags & rfloat.DTSF_SIGN:
        builder.append('+')

    # note that exactly one of the three 'if' conditions is true, so
    # we include exactly one decimal point
    # 1. Zero padding on left of digit string
    if decpt <= 0:
        builder.append_multiple_char('0', decpt - vdigits_start)
        builder.append('.')
        builder.append_multiple_char('0', 0 - decpt)
    else:
        builder.append_multiple_char('0', 0 - vdigits_start)

    # 2. Digits, with included decimal point
    if 0 < decpt <= buflen:
        builder.append(rffi.charpsize2str(digits, decpt - 0))
        builder.append('.')
        ptr = rffi.ptradd(digits, decpt)
        builder.append(rffi.charpsize2str(ptr, buflen - decpt))
#.........这里部分代码省略.........
开发者ID:gorakhargosh,项目名称:pypy,代码行数:103,代码来源:rdtoa.py


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