예제 #1
0
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)
예제 #2
0
 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)
예제 #3
0
 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")
예제 #4
0
파일: formatting.py 프로젝트: Qointum/pypy
 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))