Author: Philip Jenvey <[email protected]>
Branch: 
Changeset: r64639:16b26a59745a
Date: 2013-05-28 14:34 -0700
http://bitbucket.org/pypy/pypy/changeset/16b26a59745a/

Log:    add a %R format to operationerrfmt

diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -307,7 +307,7 @@
 
 _fmtcache = {}
 _fmtcache2 = {}
-_FMTS = tuple('dsNT')
+_FMTS = tuple('NRTds')
 
 def decompose_valuefmt(valuefmt):
     """Returns a tuple of string parts extracted from valuefmt,
@@ -354,7 +354,9 @@
                 for i, fmt, attr in entries:
                     lst[i + i] = self.xstrings[i]
                     value = getattr(self, attr)
-                    if fmt in 'NT':
+                    if fmt == 'R':
+                        result = space.str_w(space.repr(value))
+                    elif fmt in 'NT':
                         if fmt == 'T':
                             value = space.type(value)
                         result = value.getname(space)
@@ -383,6 +385,7 @@
     Supports the standard %s and %d formats, plus the following:
 
     %N - The result of w_arg.getname(space)
+    %R - The result of space.str_w(space.repr(w_arg))
     %T - The result of space.type(w_arg).getname(space)
 
     """
diff --git a/pypy/interpreter/test/test_error.py 
b/pypy/interpreter/test/test_error.py
--- a/pypy/interpreter/test/test_error.py
+++ b/pypy/interpreter/test/test_error.py
@@ -61,8 +61,14 @@
                             space.wrap('foo'), 'foo')
     assert operr._compute_value(space) == "'?' object has no attribute 'foo'"
 
-def test_operationerrfmt_empty():
-    py.test.raises(AssertionError, operationerrfmt, "w_type", "foobar")
+def test_operationerrfmt_R(space):
+    operr = operationerrfmt(space.w_ValueError, "illegal newline value: %R",
+                            space.wrap('foo'))
+    assert operr._compute_value(space) == "illegal newline value: 'foo'"
+    operr = operationerrfmt(space.w_ValueError, "illegal newline value: %R",
+                            space.wrap("'PyLadies'"))
+    expected = "illegal newline value: \"'PyLadies'\""
+    assert operr._compute_value(space) == expected
 
 def test_errorstr(space):
     operr = OperationError(space.w_ValueError, space.wrap("message"))
diff --git a/pypy/module/_codecs/interp_codecs.py 
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -52,13 +52,11 @@
                                  space.w_unicode)):
                 if decode:
                     msg = ("decoding error handler must return "
-                           "(unicode, int) tuple, not %s")
+                           "(unicode, int) tuple, not %R")
                 else:
                     msg = ("encoding error handler must return "
-                           "(unicode, int) tuple, not %s")
-                raise operationerrfmt(
-                    space.w_TypeError, msg,
-                    space.str_w(space.repr(w_res)))
+                           "(unicode, int) tuple, not %R")
+                raise operationerrfmt(space.w_TypeError, msg, w_res)
             w_replace, w_newpos = space.fixedview(w_res, 2)
             newpos = space.int_w(w_newpos)
             if newpos < 0:
diff --git a/pypy/module/_io/interp_io.py b/pypy/module/_io/interp_io.py
--- a/pypy/module/_io/interp_io.py
+++ b/pypy/module/_io/interp_io.py
@@ -42,9 +42,7 @@
     if not (space.isinstance_w(w_file, space.w_basestring) or
         space.isinstance_w(w_file, space.w_int) or
         space.isinstance_w(w_file, space.w_long)):
-        raise operationerrfmt(space.w_TypeError,
-            "invalid file: %s", space.str_w(space.repr(w_file))
-        )
+        raise operationerrfmt(space.w_TypeError, "invalid file: %R", w_file)
 
     reading = writing = appending = updating = text = binary = universal = 
False
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to