本文整理匯總了Python中pypy.rlib.rstring.UnicodeBuilder.append_multiple_char方法的典型用法代碼示例。如果您正苦於以下問題:Python UnicodeBuilder.append_multiple_char方法的具體用法?Python UnicodeBuilder.append_multiple_char怎麽用?Python UnicodeBuilder.append_multiple_char使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pypy.rlib.rstring.UnicodeBuilder
的用法示例。
在下文中一共展示了UnicodeBuilder.append_multiple_char方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: backslashreplace_errors
# 需要導入模塊: from pypy.rlib.rstring import UnicodeBuilder [as 別名]
# 或者: from pypy.rlib.rstring.UnicodeBuilder import append_multiple_char [as 別名]
def backslashreplace_errors(space, w_exc):
check_exception(space, w_exc)
if space.isinstance_w(w_exc, space.w_UnicodeEncodeError):
obj = space.realunicode_w(space.getattr(w_exc, space.wrap('object')))
start = space.int_w(space.getattr(w_exc, space.wrap('start')))
w_end = space.getattr(w_exc, space.wrap('end'))
end = space.int_w(w_end)
builder = UnicodeBuilder()
pos = start
while pos < end:
oc = ord(obj[pos])
num = hex(oc)
if (oc >= 0x10000):
builder.append(u"\\U")
zeros = 8
elif (oc >= 0x100):
builder.append(u"\\u")
zeros = 4
else:
builder.append(u"\\x")
zeros = 2
lnum = len(num)
nb = zeros + 2 - lnum # num starts with '0x'
if nb > 0:
builder.append_multiple_char(u'0', nb)
builder.append_slice(unicode(num), 2, lnum)
pos += 1
return space.newtuple([space.wrap(builder.build()), w_end])
else:
typename = space.type(w_exc).getname(space, '?')
raise operationerrfmt(space.w_TypeError,
"don't know how to handle %s in error callback", typename)
示例2: func
# 需要導入模塊: from pypy.rlib.rstring import UnicodeBuilder [as 別名]
# 或者: from pypy.rlib.rstring.UnicodeBuilder import append_multiple_char [as 別名]
def func():
s = UnicodeBuilder()
s.append(u'a')
s.append(u'abc')
s.append(u'abcdef')
s.append_slice(u'abc', 1, 2)
s.append_multiple_char(u'u', 4)
return s.build()
示例3: test_unicode_builder
# 需要導入模塊: from pypy.rlib.rstring import UnicodeBuilder [as 別名]
# 或者: from pypy.rlib.rstring.UnicodeBuilder import append_multiple_char [as 別名]
def test_unicode_builder():
s = UnicodeBuilder()
s.append(u'a')
s.append(u'abc')
s.append_slice(u'abcdef', 1, 2)
s.append_multiple_char('d', 4)
assert s.build() == 'aabcbdddd'
assert isinstance(s.build(), unicode)