From: <pj...@us...> - 2009-05-27 02:42:24
|
Revision: 6390 http://jython.svn.sourceforge.net/jython/?rev=6390&view=rev Author: pjenvey Date: 2009-05-27 02:42:18 +0000 (Wed, 27 May 2009) Log Message: ----------- o fix file repr w/ windows paths and unicode o remove no longer needed test_repr workarounds Modified Paths: -------------- trunk/jython/Lib/test/test_repr.py trunk/jython/src/org/python/core/PyFile.java Modified: trunk/jython/Lib/test/test_repr.py =================================================================== --- trunk/jython/Lib/test/test_repr.py 2009-05-27 01:47:54 UTC (rev 6389) +++ trunk/jython/Lib/test/test_repr.py 2009-05-27 02:42:18 UTC (rev 6390) @@ -130,13 +130,10 @@ def test_file(self): fp = open(unittest.__file__) self.failUnless(repr(fp).startswith( - # XXX: Jython doesn't use hex ids - # "<open file '%s', mode 'r' at 0x" % unittest.__file__)) - "<open file '%s', mode 'r' at " % unittest.__file__)) + "<open file '%s', mode 'r' at 0x" % unittest.__file__)) fp.close() self.failUnless(repr(fp).startswith( - # "<closed file '%s', mode 'r' at 0x" % unittest.__file__)) - "<closed file '%s', mode 'r' at " % unittest.__file__)) + "<closed file '%s', mode 'r' at 0x" % unittest.__file__)) def test_lambda(self): self.failUnless(repr(lambda x: x).startswith( @@ -149,8 +146,7 @@ eq(repr(hash), '<built-in function hash>') # Methods self.failUnless(repr(''.split).startswith( - # '<built-in method split of str object at 0x')) - '<built-in method split of str object at ')) + '<built-in method split of str object at 0x')) def test_xrange(self): import warnings @@ -197,11 +193,9 @@ class C: def foo(cls): pass x = staticmethod(C.foo) - #self.failUnless(repr(x).startswith('<staticmethod object at 0x')) - self.failUnless(repr(x).startswith('<staticmethod object at ')) + self.failUnless(repr(x).startswith('<staticmethod object at 0x')) x = classmethod(C.foo) - #self.failUnless(repr(x).startswith('<classmethod object at 0x')) - self.failUnless(repr(x).startswith('<classmethod object at ')) + self.failUnless(repr(x).startswith('<classmethod object at 0x')) def test_unsortable(self): # Repr.repr() used to call sorted() on sets, frozensets and dicts @@ -283,8 +277,7 @@ from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar # Module name may be prefixed with "test.", depending on how run. self.failUnless(repr(bar.bar).startswith( - # "<class %s.bar at 0x" % bar.__name__)) - "<class %s.bar at " % bar.__name__)) + "<class %s.bar at 0x" % bar.__name__)) def test_instance(self): touch(os.path.join(self.subpkgname, 'baz'+os.extsep+'py'), '''\ @@ -294,8 +287,7 @@ from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz ibaz = baz.baz() self.failUnless(repr(ibaz).startswith( - # "<%s.baz instance at 0x" % baz.__name__)) - "<%s.baz instance at " % baz.__name__)) + "<%s.baz instance at 0x" % baz.__name__)) def test_method(self): eq = self.assertEquals @@ -310,8 +302,7 @@ # Bound method next iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() self.failUnless(repr(iqux.amethod).startswith( - # '<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa instance at 0x' \ - '<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa instance at ' \ + '<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa instance at 0x' \ % (qux.__name__,) )) def test_builtin_function(self): Modified: trunk/jython/src/org/python/core/PyFile.java =================================================================== --- trunk/jython/src/org/python/core/PyFile.java 2009-05-27 01:47:54 UTC (rev 6389) +++ trunk/jython/src/org/python/core/PyFile.java 2009-05-27 02:42:18 UTC (rev 6390) @@ -493,20 +493,13 @@ @ExposedMethod(names = {"__str__", "__repr__"}, doc = BuiltinDocs.file___str___doc) final String file_toString() { - StringBuilder s = new StringBuilder("<"); - if (file.closed()) { - s.append("closed "); - } else { - s.append("open "); + String state = file.closed() ? "closed" : "open"; + String id = Py.idstr(this); + if (name instanceof PyUnicode) { + String escapedName = PyString.encode_UnicodeEscape(name.toString(), false); + return String.format("<%s file u'%s', mode '%s' at %s>", state, escapedName, mode, id); } - s.append("file "); - s.append(name.__repr__()); - s.append(", mode '"); - s.append(mode); - s.append("' at "); - s.append(Py.idstr(this)); - s.append(">"); - return s.toString(); + return String.format("<%s file '%s', mode '%s' at %s>", state, name, mode, id); } public String toString() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |