def std_wp(self, r): length = len(r) if do_unicode and isinstance(r, str): # convert string to unicode explicitely here from pypy.objspace.std.unicodetype import plain_str2unicode r = plain_str2unicode(self.space, r) prec = self.prec if prec == -1 and self.width == 0: # fast path self.result.append(const(r)) return if prec >= 0 and prec < length: length = prec # ignore the end of the string if too long result = self.result padding = self.width - length if padding < 0: padding = 0 assert padding >= 0 if not self.f_ljust and padding > 0: result.append_multiple_char(const(' '), padding) # add any padding at the left of 'r' padding = 0 result.append_slice(r, 0, length) # add 'r' itself if padding > 0: result.append_multiple_char(const(' '), padding)
def format(space, w_fmt, values_w, w_valuedict=None, do_unicode=False): "Entry point" if not do_unicode: fmt = space.str_w(w_fmt) formatter = StringFormatter(space, fmt, values_w, w_valuedict) try: result = formatter.format() except NeedUnicodeFormattingError: # fall through to the unicode case from pypy.objspace.std.unicodetype import plain_str2unicode fmt = plain_str2unicode(space, fmt) else: return space.wrap(result) else: fmt = space.unicode_w(w_fmt) formatter = UnicodeFormatter(space, fmt, values_w, w_valuedict) result = formatter.format() return space.wrap(result)
def unicode_w__String(space, w_self): # XXX should this use the default encoding? from pypy.objspace.std.unicodetype import plain_str2unicode return plain_str2unicode(space, w_self._value)
def unicode_w(w_self, space): # XXX should this use the default encoding? from pypy.objspace.std.unicodetype import plain_str2unicode return plain_str2unicode(space, w_self._value)
def unicode_w(w_self, space): # XXX should this use the default encoding? from pypy.objspace.std.unicodetype import plain_str2unicode return plain_str2unicode(space, w_self._node.flatten_string())