當前位置: 首頁>>代碼示例>>Python>>正文


Python StringBuilder.build方法代碼示例

本文整理匯總了Python中__pypy__.builders.StringBuilder.build方法的典型用法代碼示例。如果您正苦於以下問題:Python StringBuilder.build方法的具體用法?Python StringBuilder.build怎麽用?Python StringBuilder.build使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在__pypy__.builders.StringBuilder的用法示例。


在下文中一共展示了StringBuilder.build方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: StringOrUnicodeBuilder

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [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()
開發者ID:abhinavthomas,項目名稱:pypy,代碼行數:15,代碼來源:encoder.py

示例2: StringOrUnicodeBuilder

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [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()
開發者ID:Alkalit,項目名稱:pypyjs,代碼行數:15,代碼來源:encoder.py

示例3: test_preallocate

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [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"
開發者ID:Qointum,項目名稱:pypy,代碼行數:9,代碼來源:test_builders.py

示例4: test_append_slice

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [as 別名]
 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,代碼行數:10,代碼來源:test_builders.py

示例5: OStringStream

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [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()
開發者ID:lichray,項目名稱:moecache,代碼行數:11,代碼來源:moecache.py

示例6: test_simple

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [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")
開發者ID:Qointum,項目名稱:pypy,代碼行數:12,代碼來源:test_builders.py

示例7: StringIO

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [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()
開發者ID:a5an0,項目名稱:msgpack-python,代碼行數:13,代碼來源:fallback.py

示例8: test_stringbuilder

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [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)
開發者ID:Darriall,項目名稱:pypy,代碼行數:13,代碼來源:test_builders.py

示例9: test

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [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)
開發者ID:luodaobin,項目名稱:scratchbox,代碼行數:15,代碼來源:test_stringbuilder1.py

示例10: PyPyStringBuilderWriter

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [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()
開發者ID:alex,項目名稱:json_writer,代碼行數:16,代碼來源:writer.py

示例11: process

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [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()
開發者ID:luodaobin,項目名稱:scratchbox,代碼行數:17,代碼來源:xormasker.py

示例12: encode

# 需要導入模塊: from __pypy__.builders import StringBuilder [as 別名]
# 或者: from __pypy__.builders.StringBuilder import build [as 別名]
    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,代碼行數:19,代碼來源:encoder.py


注:本文中的__pypy__.builders.StringBuilder.build方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。