本文整理汇总了Python中pypy.objspace.std.stringtype.wrapstr函数的典型用法代码示例。如果您正苦于以下问题:Python wrapstr函数的具体用法?Python wrapstr怎么用?Python wrapstr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wrapstr函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getitem__String_Slice
def getitem__String_Slice(space, w_str, w_slice):
s = w_str._value
length = len(s)
start, stop, step, sl = w_slice.indices4(space, length)
if sl == 0:
return W_StringObject.EMPTY
elif step == 1:
assert start >= 0 and stop >= 0
return sliced(space, s, start, stop, w_str)
else:
str = "".join([s[start + i*step] for i in range(sl)])
return wrapstr(space, str)
示例2: getitem__StringSlice_Slice
def getitem__StringSlice_Slice(space, w_str, w_slice):
w = space.wrap
length = w_str.stop - w_str.start
start, stop, step, sl = w_slice.indices4(space, length)
if sl == 0:
return W_StringObject.EMPTY
else:
s = w_str.str
start = w_str.start + start
if step == 1:
stop = w_str.start + stop
assert start >= 0 and stop >= 0
return W_StringSliceObject(s, start, stop)
else:
str = "".join([s[start + i*step] for i in range(sl)])
return wrapstr(space, str)
示例3: str_center__String_ANY_ANY
def str_center__String_ANY_ANY(space, w_self, w_arg, w_fillchar):
u_self = w_self._value
u_arg = space.int_w(w_arg)
fillchar = space.str_w(w_fillchar)
if len(fillchar) != 1:
raise OperationError(space.w_TypeError, space.wrap("center() argument 2 must be a single character"))
d = u_arg - len(u_self)
if d > 0:
offset = d // 2 + (d & u_arg & 1)
fillchar = fillchar[0] # annotator hint: it's a single character
u_centered = offset * fillchar + u_self + (d - offset) * fillchar
else:
u_centered = u_self
return wrapstr(space, u_centered)
示例4: str_expandtabs__String_ANY
def str_expandtabs__String_ANY(space, w_self, w_tabsize):
u_self = w_self._value
u_tabsize = space.int_w(w_tabsize)
u_expanded = ""
if u_self:
split = u_self.split("\t")
try:
ovfcheck(len(split) * u_tabsize)
except OverflowError:
raise OperationError(space.w_OverflowError,
space.wrap("new string is too long")
)
u_expanded = oldtoken = split.pop(0)
for token in split:
#print "%d#%d -%s-" % (_tabindent(oldtoken,u_tabsize), u_tabsize, token)
u_expanded += " " * _tabindent(oldtoken, u_tabsize) + token
oldtoken = token
return wrapstr(space, u_expanded)
示例5: wrap
def wrap(self, x):
"Wraps the Python value 'x' into one of the wrapper classes."
# You might notice that this function is rather conspicuously
# not RPython. We can get away with this because the function
# is specialized (see after the function body). Also worth
# noting is that the isinstance's involving integer types
# behave rather differently to how you might expect during
# annotation (see pypy/annotation/builtin.py)
if x is None:
return self.w_None
if isinstance(x, W_Object):
raise TypeError, "attempt to wrap already wrapped object: %s"%(x,)
if isinstance(x, OperationError):
raise TypeError, ("attempt to wrap already wrapped exception: %s"%
(x,))
if isinstance(x, int):
if isinstance(x, bool):
return self.newbool(x)
else:
return self.newint(x)
if isinstance(x, str):
from pypy.objspace.std.stringtype import wrapstr
return wrapstr(self, x)
if isinstance(x, unicode):
from pypy.objspace.std.unicodetype import wrapunicode
return wrapunicode(self, x)
if isinstance(x, float):
return W_FloatObject(x)
if isinstance(x, Wrappable):
w_result = x.__spacebind__(self)
#print 'wrapping', x, '->', w_result
return w_result
if isinstance(x, r_int) or isinstance(x, r_uint) or \
isinstance(x, r_longlong) or isinstance(x, r_ulonglong):
return W_LongObject.fromrarith_int(x)
# _____ below here is where the annotator should not get _____
# wrap() of a container works on CPython, but the code is
# not RPython. Don't use -- it is kept around mostly for tests.
# Use instead newdict(), newlist(), newtuple().
if isinstance(x, dict):
items_w = [(self.wrap(k), self.wrap(v)) for (k, v) in x.iteritems()]
r = self.newdict()
r.initialize_content(items_w)
return r
if isinstance(x, tuple):
wrappeditems = [self.wrap(item) for item in list(x)]
return W_TupleObject(wrappeditems)
if isinstance(x, list):
wrappeditems = [self.wrap(item) for item in x]
return self.newlist(wrappeditems)
# The following cases are even stranger.
# Really really only for tests.
if isinstance(x, long):
return W_LongObject.fromlong(x)
if isinstance(x, slice):
return W_SliceObject(self.wrap(x.start),
self.wrap(x.stop),
self.wrap(x.step))
if isinstance(x, complex):
return W_ComplexObject(x.real, x.imag)
if isinstance(x, set):
wrappeditems = [self.wrap(item) for item in x]
return W_SetObject(self, wrappeditems)
if isinstance(x, frozenset):
wrappeditems = [self.wrap(item) for item in x]
return W_FrozensetObject(self, wrappeditems)
if x is __builtin__.Ellipsis:
# '__builtin__.Ellipsis' avoids confusion with special.Ellipsis
return self.w_Ellipsis
if self.config.objspace.nofaking:
# annotation should actually not get here. If it does, you get
# an error during rtyping because '%r' is not supported. It tells
# you that there was a space.wrap() on a strange object.
raise OperationError(self.w_RuntimeError,
self.wrap("nofaking enabled: refusing "
"to wrap cpython value %r" %(x,)))
if isinstance(x, type(Exception)) and issubclass(x, Exception):
w_result = self.wrap_exception_cls(x)
if w_result is not None:
return w_result
#print "fake-wrapping", x
from fake import fake_object
return fake_object(self, x)
示例6: delegate_join2unicode
def delegate_join2unicode(space, w_strjoin):
w_str = wrapstr(space, w_strjoin.force())
return delegate_String2Unicode(space, w_str)
示例7: delegate_join2str
def delegate_join2str(space, w_strjoin):
return wrapstr(space, w_strjoin.force())
示例8: delegate_slice2unicode
def delegate_slice2unicode(space, w_strslice):
w_str = wrapstr(space, w_strslice.force())
return delegate_String2Unicode(space, w_str)
示例9: delegate_slice2str
def delegate_slice2str(space, w_strslice):
return wrapstr(space, w_strslice.force())