(original) (raw)
changeset: 75527:6c1964dee98b branch: 2.7 user: Ezio Melotti ezio.melotti@gmail.com date: Mon Mar 12 01:17:02 2012 +0200 files: Lib/test/test_file2k.py Misc/NEWS Objects/fileobject.c description: #14161: fix the __repr__ of file objects to escape the file name. diff -r b6ec3b717f7e -r 6c1964dee98b Lib/test/test_file2k.py --- a/Lib/test/test_file2k.py Sun Mar 11 19:29:12 2012 +0100 +++ b/Lib/test/test_file2k.py Mon Mar 12 01:17:02 2012 +0200 @@ -89,6 +89,13 @@ def testRepr(self): # verify repr works self.assertTrue(repr(self.f).startswith("f_name)) { #ifdef Py_USING_UNICODE - PyObject *ret = NULL; - PyObject *name = PyUnicode_AsUnicodeEscapeString(f->f_name); + name = PyUnicode_AsUnicodeEscapeString(f->f_name); const char *name_str = name ? PyString_AsString(name) : "?"; ret = PyString_FromFormat("<%s file u'%s', mode '%s' at %p>", f->f_fp == NULL ? "closed" : "open", @@ -649,11 +650,16 @@ return ret; #endif } else { - return PyString_FromFormat("<%s file '%s', mode '%s' at %p>", + name = PyObject_Repr(f->f_name); + if (name == NULL) + return NULL; + ret = PyString_FromFormat("<%s file %s, mode '%s' at %p>", f->f_fp == NULL ? "closed" : "open", - PyString_AsString(f->f_name), + PyString_AsString(name), PyString_AsString(f->f_mode), f); + Py_XDECREF(name); + return ret; } }/ezio.melotti@gmail.com