def ascii(space, w_obj): """"ascii(object) -> string As repr(), return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by repr() using \\x, \\u or \\U escapes. This generates a string similar to that returned by repr() in Python 2.""" from pypy.objspace.std.unicodeobject import ascii_from_object return ascii_from_object(space, w_obj)
def fmt_a(self, w_value): from pypy.objspace.std.unicodeobject import ascii_from_object w_value = ascii_from_object(self.space, w_value) # %a calls ascii(), which should return an ascii unicode string if do_unicode: value = self.space.utf8_w(w_value) else: value = self.space.text_w(w_value) self.std_wp(value)
def _convert(self, w_obj, conversion): space = self.space conv = conversion[0] if conv == "r": return space.repr(w_obj) elif conv == "s": if self.is_unicode: return space.call_function(space.w_unicode, w_obj) return space.str(w_obj) elif conv == "a": from pypy.objspace.std.unicodeobject import ascii_from_object return ascii_from_object(space, w_obj) else: raise oefmt(space.w_ValueError, "invalid conversion")
def fmt_a(self, w_value): from pypy.objspace.std.unicodeobject import ascii_from_object w_value = ascii_from_object(self.space, w_value) self.std_wp(self.space.unicode_w(w_value))