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


Python builders.StringBuilder类代码示例

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


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

示例1: test_preallocate

 def test_preallocate(self):
     from __pypy__.builders import StringBuilder
     b = StringBuilder(10)
     b.append("abc")
     b.append("123")
     s = b.build()
     assert s == "abc123"
开发者ID:Qointum,项目名称:pypy,代码行数:7,代码来源:test_builders.py

示例2: test_append_slice

 def test_append_slice(self):
     from __pypy__.builders import StringBuilder
     b = StringBuilder()
     b.append_slice("abcdefgh", 2, 5)
     raises(ValueError, b.append_slice, "1", 2, 1)
     s = b.build()
     assert s == "cde"
     raises(ValueError, b.append_slice, "abc", 1, 2)
开发者ID:Qointum,项目名称:pypy,代码行数:8,代码来源:test_builders.py

示例3: OStringStream

    class OStringStream(object):
        def __init__(self):
            self.__b = StringBuilder()

        def write(self, s):
            self.__b.append(s)

        def getvalue(self):
            return self.__b.build()
开发者ID:lichray,项目名称:moecache,代码行数:9,代码来源:moecache.py

示例4: StringIO

 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()
开发者ID:a5an0,项目名称:msgpack-python,代码行数:11,代码来源:fallback.py

示例5: test

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)
开发者ID:luodaobin,项目名称:scratchbox,代码行数:13,代码来源:test_stringbuilder1.py

示例6: StringOrUnicodeBuilder

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()
开发者ID:Alkalit,项目名称:pypyjs,代码行数:13,代码来源:encoder.py

示例7: StringOrUnicodeBuilder

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()
开发者ID:abhinavthomas,项目名称:pypy,代码行数:13,代码来源:encoder.py

示例8: PyPyStringBuilderWriter

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()
开发者ID:alex,项目名称:json_writer,代码行数:14,代码来源:writer.py

示例9: process

   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()
开发者ID:luodaobin,项目名称:scratchbox,代码行数:15,代码来源:xormasker.py

示例10: encode

    def encode(self, o):
        """Return a JSON string representation of a Python data structure.

        >>> JSONEncoder().encode({"foo": ["bar", "baz"]})
        '{"foo": ["bar", "baz"]}'

        """
        if self.check_circular:
            markers = {}
        else:
            markers = None
        if self.ensure_ascii:
            builder = StringBuilder()
        else:
            builder = StringOrUnicodeBuilder()
        self.__encode(o, markers, builder, 0)
        return builder.build()
开发者ID:abhinavthomas,项目名称:pypy,代码行数:17,代码来源:encoder.py

示例11: test_simple

 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")
开发者ID:Qointum,项目名称:pypy,代码行数:10,代码来源:test_builders.py

示例12: test_stringbuilder

 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)
开发者ID:Darriall,项目名称:pypy,代码行数:11,代码来源:test_builders.py

示例13: __init__

 def __init__(self, s=b''):
     if s:
         self.builder = StringBuilder(len(s))
         self.builder.append(s)
     else:
         self.builder = StringBuilder()
开发者ID:a5an0,项目名称:msgpack-python,代码行数:6,代码来源:fallback.py

示例14: __init__

 def __init__(self):
     self._builder = StringBuilder()
开发者ID:abhinavthomas,项目名称:pypy,代码行数:2,代码来源:encoder.py

示例15: __init__

 def __init__(self):
     self.__b = StringBuilder()
开发者ID:lichray,项目名称:moecache,代码行数:2,代码来源:moecache.py


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