本文整理汇总了Python中__pypy__.builders.StringBuilder.append方法的典型用法代码示例。如果您正苦于以下问题:Python StringBuilder.append方法的具体用法?Python StringBuilder.append怎么用?Python StringBuilder.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类__pypy__.builders.StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.append方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_preallocate
# 需要导入模块: from __pypy__.builders import StringBuilder [as 别名]
# 或者: from __pypy__.builders.StringBuilder import append [as 别名]
def test_preallocate(self):
from __pypy__.builders import StringBuilder
b = StringBuilder(10)
b.append("abc")
b.append("123")
s = b.build()
assert s == "abc123"
示例2: OStringStream
# 需要导入模块: from __pypy__.builders import StringBuilder [as 别名]
# 或者: from __pypy__.builders.StringBuilder import append [as 别名]
class OStringStream(object):
def __init__(self):
self.__b = StringBuilder()
def write(self, s):
self.__b.append(s)
def getvalue(self):
return self.__b.build()
示例3: test_simple
# 需要导入模块: from __pypy__.builders import StringBuilder [as 别名]
# 或者: from __pypy__.builders.StringBuilder import append [as 别名]
def test_simple(self):
from __pypy__.builders import StringBuilder
b = StringBuilder()
b.append("abc")
b.append("123")
b.append("1")
s = b.build()
assert s == "abc1231"
raises(ValueError, b.build)
raises(ValueError, b.append, "123")
示例4: StringIO
# 需要导入模块: from __pypy__.builders import StringBuilder [as 别名]
# 或者: from __pypy__.builders.StringBuilder import append [as 别名]
class StringIO(object):
def __init__(self, s=b''):
if s:
self.builder = StringBuilder(len(s))
self.builder.append(s)
else:
self.builder = StringBuilder()
def write(self, s):
self.builder.append(s)
def getvalue(self):
return self.builder.build()
示例5: test_stringbuilder
# 需要导入模块: from __pypy__.builders import StringBuilder [as 别名]
# 或者: from __pypy__.builders.StringBuilder import append [as 别名]
def test_stringbuilder(self):
from __pypy__.builders import StringBuilder
b = StringBuilder()
b.append("abc")
b.append("123")
assert len(b) == 6
b.append("you and me")
s = b.build()
raises(ValueError, len, b)
assert s == "abc123you and me"
raises(ValueError, b.build)
示例6: StringOrUnicodeBuilder
# 需要导入模块: from __pypy__.builders import StringBuilder [as 别名]
# 或者: from __pypy__.builders.StringBuilder import append [as 别名]
class StringOrUnicodeBuilder(object):
def __init__(self):
self._builder = StringBuilder()
def append(self, string):
if (isinstance(string, unicode) and
type(self._builder) is StringBuilder):
ub = UnicodeBuilder()
ub.append(self._builder.build())
self._builder = ub
self.append = ub.append # shortcut only
self._builder.append(string)
def build(self):
return self._builder.build()
示例7: test
# 需要导入模块: from __pypy__.builders import StringBuilder [as 别名]
# 或者: from __pypy__.builders.StringBuilder import append [as 别名]
def test(chopcount, chopsize):
chop = '*' * chopsize
n = chopcount * chopsize
sb = StringBuilder(n)
i = 0
while i < chopcount:
sb.append(chop)
i += 1
s = sb.build()
assert(len(s) == n)
示例8: StringOrUnicodeBuilder
# 需要导入模块: from __pypy__.builders import StringBuilder [as 别名]
# 或者: from __pypy__.builders.StringBuilder import append [as 别名]
class StringOrUnicodeBuilder(object):
def __init__(self):
self._builder = StringBuilder()
def append(self, string):
try:
self._builder.append(string)
except UnicodeEncodeError:
ub = UnicodeBuilder()
ub.append(self._builder.build())
self._builder = ub
ub.append(string)
def build(self):
return self._builder.build()
示例9: PyPyStringBuilderWriter
# 需要导入模块: from __pypy__.builders import StringBuilder [as 别名]
# 或者: from __pypy__.builders.StringBuilder import append [as 别名]
class PyPyStringBuilderWriter(BaseJSONWriter):
def __init__(self):
super(PyPyStringBuilderWriter, self).__init__()
self._data = StringBuilder()
@classmethod
def is_available(cls):
return StringBuilder is not None
def _write(self, s):
self._data.append(s)
def build(self):
return self._data.build()
示例10: process
# 需要导入模块: from __pypy__.builders import StringBuilder [as 别名]
# 或者: from __pypy__.builders.StringBuilder import append [as 别名]
def process(self, data):
dlen = len(data)
r = StringBuilder(dlen)
i = 0
k = self.ptr
m = self.msk
while i < dlen:
# r.append(chr(ord(data[i]) ^ self.msk[k & 3]))
r.append(chr(ord(data[i]) ^ ord(m[k & 3])))
k += 1
i += 1
self.ptr += dlen
return r.build()