[pypy-commit] pypy stdlib-2.7.4: test and fix for repr(file) to escape file name (cpython issue14161)
bdkearns
noreply at buildbot.pypy.org
Wed Apr 10 00:02:13 CEST 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch: stdlib-2.7.4
Changeset: r63172:6185cc1d30fc
Date: 2013-04-09 16:55 -0400
http://bitbucket.org/pypy/pypy/changeset/6185cc1d30fc/
Log: test and fix for repr(file) to escape file name (cpython issue14161)
diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -440,9 +440,6 @@
w_name = self.w_name
if w_name is None:
return '?'
- elif self.space.is_true(self.space.isinstance(w_name,
- self.space.w_str)):
- return "'%s'" % self.space.str_w(w_name)
else:
return self.space.str_w(self.space.repr(w_name))
diff --git a/pypy/module/_file/test/test_file_extra.py b/pypy/module/_file/test/test_file_extra.py
--- a/pypy/module/_file/test/test_file_extra.py
+++ b/pypy/module/_file/test/test_file_extra.py
@@ -607,10 +607,16 @@
assert file.closed.__doc__ == 'True if the file is closed'
def test_repr_unicode_filename(self):
- f = open(unicode(self.temptestfile), 'w')
- assert repr(f).startswith("<open file " +
- repr(unicode(self.temptestfile)))
- f.close()
+ with open(unicode(self.temptestfile), 'w') as f:
+ assert repr(f).startswith("<open file " +
+ repr(unicode(self.temptestfile)))
+
+ def test_repr_escape_filename(self):
+ import sys
+ fname = 'xx\rxx\nxx\'xx"xx' if sys.platform != "win32" else "xx'xx"
+ fname = self.temptestfile + fname
+ with open(fname, 'w') as f:
+ assert repr(f).startswith("<open file %r, mode 'w' at" % fname)
@py.test.mark.skipif("os.name != 'posix'")
def test_EAGAIN(self):
More information about the pypy-commit
mailing list