本文整理汇总了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)