From: <cg...@us...> - 2007-10-05 04:51:42
|
Revision: 3561 http://jython.svn.sourceforge.net/jython/?rev=3561&view=rev Author: cgroves Date: 2007-10-04 21:51:41 -0700 (Thu, 04 Oct 2007) Log Message: ----------- Merged revisions 3551,3553,3555-3556,3559 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r3551 | pjenvey | 2007-10-01 23:37:03 -0700 (Mon, 01 Oct 2007) | 1 line remove .cvsignore ........ r3553 | pjenvey | 2007-10-02 11:28:06 -0700 (Tue, 02 Oct 2007) | 1 line remove .cvsignore ........ r3555 | cgroves | 2007-10-03 01:54:08 -0700 (Wed, 03 Oct 2007) | 1 line Exit if the encoding given in python.console.encoding isn't supported on this JVM ........ r3556 | cgroves | 2007-10-03 01:55:51 -0700 (Wed, 03 Oct 2007) | 1 line Run the input stream given for the parser through ISO-8859-1 to get chars rather than the JVM's default encoding ........ r3559 | cgroves | 2007-10-04 10:25:52 -0700 (Thu, 04 Oct 2007) | 1 line This seems to be testing if \x99 can survive javacc, and not cp1542 ........ Modified Paths: -------------- branches/Release_2_2maint/jython/bugtests/test302.py branches/Release_2_2maint/jython/src/org/python/core/parser.java branches/Release_2_2maint/jython/src/org/python/util/InteractiveInterpreter.java branches/Release_2_2maint/jython/src/org/python/util/jython.java Removed Paths: ------------- branches/Release_2_2maint/installer/.cvsignore branches/Release_2_2maint/jython/.cvsignore Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559 Deleted: branches/Release_2_2maint/installer/.cvsignore =================================================================== --- branches/Release_2_2maint/installer/.cvsignore 2007-10-04 17:50:41 UTC (rev 3560) +++ branches/Release_2_2maint/installer/.cvsignore 2007-10-05 04:51:41 UTC (rev 3561) @@ -1,5 +0,0 @@ -.classpath -.project -.ipr -.iws -.iml Deleted: branches/Release_2_2maint/jython/.cvsignore =================================================================== --- branches/Release_2_2maint/jython/.cvsignore 2007-10-04 17:50:41 UTC (rev 3560) +++ branches/Release_2_2maint/jython/.cvsignore 2007-10-05 04:51:41 UTC (rev 3561) @@ -1,10 +0,0 @@ -.classpath -.project -*.ipr -*.iws -*.iml -build -dist -ant.properties -bin -cachedir Modified: branches/Release_2_2maint/jython/bugtests/test302.py =================================================================== --- branches/Release_2_2maint/jython/bugtests/test302.py 2007-10-04 17:50:41 UTC (rev 3560) +++ branches/Release_2_2maint/jython/bugtests/test302.py 2007-10-05 04:51:41 UTC (rev 3561) @@ -1,5 +1,4 @@ """ -Test the cp1542 encoding (euro-centric console) In bug #439688 the value 0x99 does not survive the JavaCC parser. """ @@ -12,15 +11,15 @@ try: import test302s except SyntaxError: - raise support.TestWarning('Should not raise a Syntaxerror') + raise support.TestError('Importing a file with str byte > 128 should not raise a Syntaxerror') -f = open("test302.out", "wb") +f = open("test302.out", "w") f.write("\x99") f.close(); -import java -readerval = java.io.FileReader("test302.out").read() +from java.io import FileInputStream, InputStreamReader +readval = InputStreamReader(FileInputStream("test302.out"), 'ISO-8859-1').read() -if ord(test302s.v) != readerval: +if ord(test302s.v) != readval: raise support.TestError("Module source was not decoded correctly %x %x" % - (ord(test302s.v), ord(readerval))) + (ord(test302s.v), readval)) Modified: branches/Release_2_2maint/jython/src/org/python/core/parser.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/parser.java 2007-10-04 17:50:41 UTC (rev 3560) +++ branches/Release_2_2maint/jython/src/org/python/core/parser.java 2007-10-05 04:51:41 UTC (rev 3561) @@ -92,7 +92,7 @@ return parse(new ByteArrayInputStream(PyString.to_bytes(string)), kind, "<string>", null); } - + public static modType parse(InputStream istream, String kind, String filename, CompilerFlags cflags) { @@ -205,15 +205,22 @@ nbytes = 10000; if (nbytes > 100000) nbytes = 100000; - - Reader reader = null; - try { - if (cflags != null && cflags.encoding != null) { + Reader reader; + if(cflags != null && cflags.encoding != null) { + try { reader = new InputStreamReader(istream, cflags.encoding); + } catch(UnsupportedEncodingException exc) { + throw Py.SystemError("python.console.encoding, " + cflags.encoding + + ", isn't supported by this JVM so we can't parse this data."); } - } catch (UnsupportedEncodingException exc) { ; } - if (reader == null) { - reader = new InputStreamReader(istream); + } else { + try { + // Use ISO-8859-1 to get bytes off the input stream since it leaves their values alone. + reader = new InputStreamReader(istream, "ISO-8859-1"); + } catch(UnsupportedEncodingException e) { + // This JVM is whacked, it doesn't even have iso-8859-1 + throw Py.SystemError("Java couldn't find the ISO-8859-1 encoding"); + } } //if (Options.fixMacReaderBug); Modified: branches/Release_2_2maint/jython/src/org/python/util/InteractiveInterpreter.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/util/InteractiveInterpreter.java 2007-10-04 17:50:41 UTC (rev 3560) +++ branches/Release_2_2maint/jython/src/org/python/util/InteractiveInterpreter.java 2007-10-05 04:51:41 UTC (rev 3561) @@ -50,7 +50,7 @@ public boolean runsource(String source, String filename, String symbol) { PyObject code; try { - code = Py.compile_command_flags(source, filename, symbol,cflags,true); + code = Py.compile_command_flags(source, filename, symbol, cflags, true); } catch (PyException exc) { if (Py.matchException(exc, Py.SyntaxError)) { // Case 1 Modified: branches/Release_2_2maint/jython/src/org/python/util/jython.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/util/jython.java 2007-10-04 17:50:41 UTC (rev 3560) +++ branches/Release_2_2maint/jython/src/org/python/util/jython.java 2007-10-05 04:51:41 UTC (rev 3561) @@ -1,9 +1,21 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.util; -import org.python.core.*; -import java.util.zip.*; -import java.io.*; +import java.io.File; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import org.python.core.Options; +import org.python.core.Py; +import org.python.core.PyCode; +import org.python.core.PyException; +import org.python.core.PyModule; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyStringMap; +import org.python.core.PySystemState; +import org.python.core.imp; public class jython { @@ -221,7 +233,12 @@ opts.encoding = PySystemState.registry.getProperty( "python.console.encoding", null); } - if (opts.encoding != null) { + if(opts.encoding != null) { + if(!Charset.isSupported(opts.encoding)) { + System.err.println(opts.encoding + + " is not a supported encoding on this JVM, so it can't be used in python.console.encoding."); + System.exit(1); + } interp.cflags.encoding = opts.encoding; } try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-10-05 04:58:40
|
Revision: 3564 http://jython.svn.sourceforge.net/jython/?rev=3564&view=rev Author: cgroves Date: 2007-10-04 21:58:38 -0700 (Thu, 04 Oct 2007) Log Message: ----------- Merged revisions 3563 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r3563 | cgroves | 2007-10-04 21:57:40 -0700 (Thu, 04 Oct 2007) | 1 line add a couple more fixes for 221rc2 ........ Modified Paths: -------------- branches/Release_2_2maint/jython/NEWS Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563 Modified: branches/Release_2_2maint/jython/NEWS =================================================================== --- branches/Release_2_2maint/jython/NEWS 2007-10-05 04:57:40 UTC (rev 3563) +++ branches/Release_2_2maint/jython/NEWS 2007-10-05 04:58:38 UTC (rev 3564) @@ -2,8 +2,10 @@ Jython 2.2.1 rc2 Bugs fixed + - Python files are parsed using the JVM's default encoding - [ 1800378 ] __unicode__ ignored on subclasses of builtin types - [ 1801802 ] JavaImportHelper not thread safe + - python.console.encoding is silently ignored if the JVM doesn't support the given encoding Jython 2.2.1 rc1 Bugs fixed This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-10-13 18:36:00
|
Revision: 3596 http://jython.svn.sourceforge.net/jython/?rev=3596&view=rev Author: cgroves Date: 2007-10-13 11:35:56 -0700 (Sat, 13 Oct 2007) Log Message: ----------- Merged revisions 3592 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r3592 | pjenvey | 2007-10-12 19:51:09 -0700 (Fri, 12 Oct 2007) | 3 lines always flush socket files after writing, incase they buffer (although they currently don't) ........ Modified Paths: -------------- branches/Release_2_2maint/jython/Lib/test/test_socket.py Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3592 Modified: branches/Release_2_2maint/jython/Lib/test/test_socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/test/test_socket.py 2007-10-13 18:34:53 UTC (rev 3595) +++ branches/Release_2_2maint/jython/Lib/test/test_socket.py 2007-10-13 18:35:56 UTC (rev 3596) @@ -786,6 +786,7 @@ self.serv_conn.close() try: self.cli_file.write(MSG) + self.cli_file.flush() except Exception, x: self.fail("Closing socket appears to have closed file wrapper: %s" % str(x)) @@ -834,7 +835,7 @@ def _testFullRead(self): self.cli_file.write(MSG) - self.cli_file.close() + self.cli_file.flush() def testUnbufferedRead(self): # Performing unbuffered file read test This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-10-13 18:46:21
|
Revision: 3599 http://jython.svn.sourceforge.net/jython/?rev=3599&view=rev Author: cgroves Date: 2007-10-13 11:46:13 -0700 (Sat, 13 Oct 2007) Log Message: ----------- Merged revisions 3598 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r3598 | cgroves | 2007-10-13 11:45:19 -0700 (Sat, 13 Oct 2007) | 1 line 2.2.1 version bump ........ Modified Paths: -------------- branches/Release_2_2maint/jython/NEWS Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3592 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3592,3598 Modified: branches/Release_2_2maint/jython/NEWS =================================================================== --- branches/Release_2_2maint/jython/NEWS 2007-10-13 18:45:19 UTC (rev 3598) +++ branches/Release_2_2maint/jython/NEWS 2007-10-13 18:46:13 UTC (rev 3599) @@ -1,5 +1,8 @@ Jython NEWS +Jython 2.2.1 + Identical to 2.2.1 rc2 + Jython 2.2.1 rc2 Bugs fixed - Python files are parsed using the JVM's default encoding This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-11-12 03:49:10
|
Revision: 3669 http://jython.svn.sourceforge.net/jython/?rev=3669&view=rev Author: cgroves Date: 2007-11-11 19:48:59 -0800 (Sun, 11 Nov 2007) Log Message: ----------- Merged revisions 3668 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r3668 | cgroves | 2007-11-11 19:28:06 -0800 (Sun, 11 Nov 2007) | 1 line Use String.getBytes with an encoding instead of a byte array since the latter isn't supported on CVM ........ Modified Paths: -------------- branches/Release_2_2maint/jython/src/org/python/core/PyString.java Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3592,3598 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3592,3598,3668 Modified: branches/Release_2_2maint/jython/src/org/python/core/PyString.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PyString.java 2007-11-12 03:28:06 UTC (rev 3668) +++ branches/Release_2_2maint/jython/src/org/python/core/PyString.java 2007-11-12 03:48:59 UTC (rev 3669) @@ -1,6 +1,8 @@ /// Copyright (c) Corporation for National Research Initiatives package org.python.core; +import java.io.UnsupportedEncodingException; + /** * A builtin python string. */ @@ -2027,10 +2029,12 @@ * the low-order bits of its corresponding char. */ public static byte[] to_bytes(String s) { - int len = s.length(); - byte[] b = new byte[len]; - s.getBytes(0, len, b, 0); - return b; + try { + return s.getBytes("ISO-8859-1"); + } catch(UnsupportedEncodingException e) { + // This JVM is whacked, it doesn't even have iso-8859-1 + throw Py.SystemError("Java couldn't find the ISO-8859-1 encoding"); + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-11-16 23:08:07
|
Revision: 3688 http://jython.svn.sourceforge.net/jython/?rev=3688&view=rev Author: pjenvey Date: 2007-11-16 15:08:05 -0800 (Fri, 16 Nov 2007) Log Message: ----------- Merged revisions 3570,3574-3575,3577-3590,3593-3597,3599-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3667,3669-3681,3684,3686-3687 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ................ r3570 | pjenvey | 2007-10-05 12:37:42 -0700 (Fri, 05 Oct 2007) | 3 lines make os.path.join('foo', '') == 'foo' + os.sep fixes #1806980 ................ r3663 | pjenvey | 2007-11-09 18:43:29 -0800 (Fri, 09 Nov 2007) | 27 lines Merged revisions 3648,3652 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/branches/pyfile-nio ........ r3648 | pjenvey | 2007-11-05 20:35:50 -0800 (Mon, 05 Nov 2007) | 15 lines o replace usage of PyFile in socket.makefile with the pure python file-like socket._fileobject from CPython 2.4.4. fixes deadlocks with makefile objects, #1744567 o kill FileWrapper and move the file vs socket close() handling to the pure python _socketobject and _closedsocket wrappers (both adapted from CPython 2.4.4) and _fileobject o make file_count more of a reference_count. move it down into _nonblocking_api_mixin so file objects' close() works for UDP sockets. with a test o kill socket.SocketTypes now that socket._socketobject always wraps both _tcpsocket and _udpsocket ........ r3652 | pjenvey | 2007-11-06 12:38:30 -0800 (Tue, 06 Nov 2007) | 2 lines add a _socketobject passthrough for getchannel refs #1744567 ........ ................ r3687 | pjenvey | 2007-11-16 14:56:36 -0800 (Fri, 16 Nov 2007) | 1 line r3663 removed SocketTypes but forgot to remove it from __all__ ................ Modified Paths: -------------- branches/Release_2_2maint/jython/Lib/javapath.py branches/Release_2_2maint/jython/Lib/socket.py branches/Release_2_2maint/jython/Lib/test/test_socket.py Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3592,3598,3668 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687 Modified: branches/Release_2_2maint/jython/Lib/javapath.py =================================================================== --- branches/Release_2_2maint/jython/Lib/javapath.py 2007-11-16 22:56:36 UTC (rev 3687) +++ branches/Release_2_2maint/jython/Lib/javapath.py 2007-11-16 23:08:05 UTC (rev 3688) @@ -115,6 +115,8 @@ if g.isAbsolute() or len(f.getPath()) == 0: f = g else: + if a == "": + a = os.sep f = File(f, a) return f.getPath() Modified: branches/Release_2_2maint/jython/Lib/socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/socket.py 2007-11-16 22:56:36 UTC (rev 3687) +++ branches/Release_2_2maint/jython/Lib/socket.py 2007-11-16 23:08:05 UTC (rev 3688) @@ -75,7 +75,6 @@ import java.nio.channels.UnsupportedAddressTypeException import javax.net.ssl.SSLSocketFactory -import org.python.core.PyFile class error(Exception): pass class herror(error): pass @@ -287,7 +286,7 @@ __all__ = [ 'AF_INET', 'SO_REUSEADDR', 'SOCK_DGRAM', 'SOCK_RAW', 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', - 'SocketType', 'SocketTypes', 'error', 'herror', 'gaierror', 'timeout', + 'SocketType', 'error', 'herror', 'gaierror', 'timeout', 'getfqdn', 'gethostbyaddr', 'gethostbyname', 'gethostname', 'socket', 'getaddrinfo', 'getdefaulttimeout', 'setdefaulttimeout', 'has_ipv6', 'htons', 'htonl', 'ntohs', 'ntohl', @@ -360,7 +359,7 @@ # Same situation as above raise NotImplementedError("getprotobyname not yet supported on jython.") -def socket(family = AF_INET, type = SOCK_STREAM, flags=0): +def _realsocket(family = AF_INET, type = SOCK_STREAM, flags=0): assert family == AF_INET assert type in (SOCK_DGRAM, SOCK_STREAM) assert flags == 0 @@ -409,6 +408,8 @@ timeout = _defaulttimeout mode = MODE_BLOCKING + reference_count = 0 + close_lock = threading.Lock() def gettimeout(self): return self.timeout @@ -464,7 +465,6 @@ ostream = None local_addr = None server = 0 - file_count = 0 reuse_addr = 0 def bind(self, addr): @@ -610,66 +610,6 @@ if optname == SO_REUSEADDR: return self.reuse_addr - def makefile(self, mode="r", bufsize=-1): - file = None - if self.istream: - if self.ostream: - file = org.python.core.PyFile(self.istream, self.ostream, - "<socket>", mode) - else: - file = org.python.core.PyFile(self.istream, "<socket>", mode) - elif self.ostream: - file = org.python.core.PyFile(self.ostream, "<socket>", mode) - else: - raise IOError, "both istream and ostream have been shut down" - if file: - return _tcpsocket.FileWrapper(self, file) - - class FileWrapper: - def __init__(self, socket, file): - self.socket = socket - self.istream = socket.istream - self.ostream = socket.ostream - - self.file = file - self.read = file.read - self.readline = file.readline - self.readlines = file.readlines - self.write = file.write - self.writelines = file.writelines - self.flush = file.flush - self.seek = file.seek - self.tell = file.tell - self.closed = file.closed - - self.socket.file_count += 1 - - def close(self): - if self.closed: - # Already closed - return - - self.socket.file_count -= 1 - # AMAK: 20070715: Cannot close the PyFile, because closing - # it causes the InputStream and OutputStream to be closed. - # This in turn causes the underlying socket to be closed. - # This was always true for java.net sockets - # And continues to be true for java.nio sockets - # http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4717638 -# self.file.close() - istream = self.istream - ostream = self.ostream - self.istream = None - self.ostream = None -# self.closed = self.file.closed - self.closed = 1 - - if self.socket.file_count == 0 and self.socket.sock_impl is None: - # This is the last file Only close the socket and streams - # if there are no outstanding files left. - istream.close() - ostream.close() - def shutdown(self, how): assert how in (SHUT_RD, SHUT_WR, SHUT_RDWR) assert self.sock_impl @@ -680,23 +620,12 @@ def close(self): try: - if not self.sock_impl: - return - sock_impl = self.sock_impl - istream = self.istream - ostream = self.ostream - self.sock_impl = None - self.istream = None - self.ostream = None - # Only close the socket and streams if there are no - # outstanding files left. - if self.file_count == 0: - if istream: - istream.close() - if ostream: - ostream.close() - if sock_impl: - sock_impl.close() + if self.istream: + self.istream.close() + if self.ostream: + self.ostream.close() + if self.sock_impl: + self.sock_impl.close() except java.lang.Exception, jlx: raise _map_exception(jlx) @@ -814,11 +743,8 @@ def close(self): try: - if not self.sock_impl: - return - sock = self.sock_impl - self.sock_impl = None - sock.close() + if self.sock_impl: + self.sock_impl.close() except java.lang.Exception, jlx: raise _map_exception(jlx) @@ -839,9 +765,323 @@ except java.lang.Exception, jlx: raise _map_exception(jlx) -SocketType = _tcpsocket -SocketTypes = [_tcpsocket, _udpsocket] +_socketmethods = ( + 'bind', 'connect', 'connect_ex', 'fileno', 'listen', + 'getpeername', 'getsockname', 'getsockopt', 'setsockopt', + 'sendall', 'setblocking', + 'settimeout', 'gettimeout', 'shutdown', 'getchannel') +class _closedsocket(object): + __slots__ = [] + def _dummy(*args): + raise error(errno.EBADF, 'Bad file descriptor') + send = recv = sendto = recvfrom = __getattr__ = _dummy + +class _socketobject(object): + + __doc__ = _realsocket.__doc__ + + __slots__ = ["_sock", "send", "recv", "sendto", "recvfrom", + "__weakref__"] + + def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None): + if _sock is None: + _sock = _realsocket(family, type, proto) + _sock.reference_count += 1 + elif not isinstance(_sock, _closedsocket): + _sock.reference_count += 1 + self._sock = _sock + self.send = self._sock.send + self.recv = self._sock.recv + if hasattr(self._sock, 'sendto'): + self.sendto = self._sock.sendto + self.recvfrom = self._sock.recvfrom + + def close(self): + _sock = self._sock + if not isinstance(_sock, _closedsocket): + _sock.close_lock.acquire() + try: + _sock.reference_count -=1 + if not _sock.reference_count: + _sock.close() + self._sock = _closedsocket() + self.send = self.recv = self.sendto = self.recvfrom = \ + self._sock._dummy + finally: + _sock.close_lock.release() + #close.__doc__ = _realsocket.close.__doc__ + + def accept(self): + sock, addr = self._sock.accept() + return _socketobject(_sock=sock), addr + #accept.__doc__ = _realsocket.accept.__doc__ + + def dup(self): + """dup() -> socket object + + Return a new socket object connected to the same system resource.""" + _sock = self._sock + if isinstance(_sock, _closedsocket): + return _socketobject(_sock=_sock) + + _sock.close_lock.acquire() + try: + duped = _socketobject(_sock=_sock) + finally: + _sock.close_lock.release() + return duped + + def makefile(self, mode='r', bufsize=-1): + """makefile([mode[, bufsize]]) -> file object + + Return a regular file object corresponding to the socket. The mode + and bufsize arguments are as for the built-in open() function.""" + _sock = self._sock + if isinstance(_sock, _closedsocket): + return _fileobject(_sock, mode, bufsize) + + _sock.close_lock.acquire() + try: + fileobject = _fileobject(_sock, mode, bufsize) + finally: + _sock.close_lock.release() + return fileobject + + _s = ("def %s(self, *args): return self._sock.%s(*args)\n\n" + #"%s.__doc__ = _realsocket.%s.__doc__\n") + ) + for _m in _socketmethods: + #exec _s % (_m, _m, _m, _m) + exec _s % (_m, _m) + del _m, _s + +socket = SocketType = _socketobject + +class _fileobject(object): + """Faux file object attached to a socket object.""" + + default_bufsize = 8192 + name = "<socket>" + + __slots__ = ["mode", "bufsize", "softspace", + # "closed" is a property, see below + "_sock", "_rbufsize", "_wbufsize", "_rbuf", "_wbuf", + "_close"] + + def __init__(self, sock, mode='rb', bufsize=-1): + self._sock = sock + if not isinstance(sock, _closedsocket): + sock.reference_count += 1 + self.mode = mode # Not actually used in this version + if bufsize < 0: + bufsize = self.default_bufsize + self.bufsize = bufsize + self.softspace = False + if bufsize == 0: + self._rbufsize = 1 + elif bufsize == 1: + self._rbufsize = self.default_bufsize + else: + self._rbufsize = bufsize + self._wbufsize = bufsize + self._rbuf = "" # A string + self._wbuf = [] # A list of strings + + def _getclosed(self): + return self._sock is None + closed = property(_getclosed, doc="True if the file is closed") + + def close(self): + try: + if self._sock: + self.flush() + finally: + if self._sock and not isinstance(self._sock, _closedsocket): + self._sock.reference_count -= 1 + if not self._sock.reference_count: + self._sock.close() + self._sock = None + + def __del__(self): + try: + self.close() + except: + # close() may fail if __init__ didn't complete + pass + + def flush(self): + if self._wbuf: + buffer = "".join(self._wbuf) + self._wbuf = [] + self._sock.sendall(buffer) + + def fileno(self): + return self._sock.fileno() + + def write(self, data): + data = str(data) # XXX Should really reject non-string non-buffers + if not data: + return + self._wbuf.append(data) + if (self._wbufsize == 0 or + self._wbufsize == 1 and '\n' in data or + self._get_wbuf_len() >= self._wbufsize): + self.flush() + + def writelines(self, list): + # XXX We could do better here for very long lists + # XXX Should really reject non-string non-buffers + self._wbuf.extend(filter(None, map(str, list))) + if (self._wbufsize <= 1 or + self._get_wbuf_len() >= self._wbufsize): + self.flush() + + def _get_wbuf_len(self): + buf_len = 0 + for x in self._wbuf: + buf_len += len(x) + return buf_len + + def read(self, size=-1): + data = self._rbuf + if size < 0: + # Read until EOF + buffers = [] + if data: + buffers.append(data) + self._rbuf = "" + if self._rbufsize <= 1: + recv_size = self.default_bufsize + else: + recv_size = self._rbufsize + while True: + data = self._sock.recv(recv_size) + if not data: + break + buffers.append(data) + return "".join(buffers) + else: + # Read until size bytes or EOF seen, whichever comes first + buf_len = len(data) + if buf_len >= size: + self._rbuf = data[size:] + return data[:size] + buffers = [] + if data: + buffers.append(data) + self._rbuf = "" + while True: + left = size - buf_len + recv_size = max(self._rbufsize, left) + data = self._sock.recv(recv_size) + if not data: + break + buffers.append(data) + n = len(data) + if n >= left: + self._rbuf = data[left:] + buffers[-1] = data[:left] + break + buf_len += n + return "".join(buffers) + + def readline(self, size=-1): + data = self._rbuf + if size < 0: + # Read until \n or EOF, whichever comes first + if self._rbufsize <= 1: + # Speed up unbuffered case + assert data == "" + buffers = [] + recv = self._sock.recv + while data != "\n": + data = recv(1) + if not data: + break + buffers.append(data) + return "".join(buffers) + nl = data.find('\n') + if nl >= 0: + nl += 1 + self._rbuf = data[nl:] + return data[:nl] + buffers = [] + if data: + buffers.append(data) + self._rbuf = "" + while True: + data = self._sock.recv(self._rbufsize) + if not data: + break + buffers.append(data) + nl = data.find('\n') + if nl >= 0: + nl += 1 + self._rbuf = data[nl:] + buffers[-1] = data[:nl] + break + return "".join(buffers) + else: + # Read until size bytes or \n or EOF seen, whichever comes first + nl = data.find('\n', 0, size) + if nl >= 0: + nl += 1 + self._rbuf = data[nl:] + return data[:nl] + buf_len = len(data) + if buf_len >= size: + self._rbuf = data[size:] + return data[:size] + buffers = [] + if data: + buffers.append(data) + self._rbuf = "" + while True: + data = self._sock.recv(self._rbufsize) + if not data: + break + buffers.append(data) + left = size - buf_len + nl = data.find('\n', 0, left) + if nl >= 0: + nl += 1 + self._rbuf = data[nl:] + buffers[-1] = data[:nl] + break + n = len(data) + if n >= left: + self._rbuf = data[left:] + buffers[-1] = data[:left] + break + buf_len += n + return "".join(buffers) + + def readlines(self, sizehint=0): + total = 0 + list = [] + while True: + line = self.readline() + if not line: + break + list.append(line) + total += len(line) + if sizehint and total >= sizehint: + break + return list + + # Iterator protocols + + def __iter__(self): + return self + + def next(self): + line = self.readline() + if not line: + raise StopIteration + return line + + # Define the SSL support class ssl: Modified: branches/Release_2_2maint/jython/Lib/test/test_socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/test/test_socket.py 2007-11-16 22:56:36 UTC (rev 3687) +++ branches/Release_2_2maint/jython/Lib/test/test_socket.py 2007-11-16 23:08:05 UTC (rev 3688) @@ -583,6 +583,18 @@ time.sleep(0.5) self.fail("Sending on remotely closed socket should have raised exception") + def testDup(self): + msg = self.cli_conn.recv(len(MSG)) + self.assertEqual(msg, MSG) + + dup_conn = self.cli_conn.dup() + msg = dup_conn.recv(len('and ' + MSG)) + self.assertEqual(msg, 'and ' + MSG) + + def _testDup(self): + self.serv_conn.send(MSG) + self.serv_conn.send('and ' + MSG) + class BasicUDPTest(ThreadedUDPSocketTest): def __init__(self, methodName='runTest'): @@ -762,7 +774,7 @@ # TODO: Write some non-blocking UDP tests # -class FileObjectClassOpenCloseTests(SocketConnectedTest): +class TCPFileObjectClassOpenCloseTests(SocketConnectedTest): def testCloseFileDoesNotCloseSocket(self): # This test is necessary on java/jython @@ -790,6 +802,71 @@ except Exception, x: self.fail("Closing socket appears to have closed file wrapper: %s" % str(x)) +class UDPFileObjectClassOpenCloseTests(ThreadedUDPSocketTest): + + def testCloseFileDoesNotCloseSocket(self): + # This test is necessary on java/jython + msg = self.serv.recv(1024) + self.assertEqual(msg, MSG) + + def _testCloseFileDoesNotCloseSocket(self): + self.cli_file = self.cli.makefile('wb') + self.cli_file.close() + try: + self.cli.sendto(MSG, 0, (HOST, PORT)) + except Exception, x: + self.fail("Closing file wrapper appears to have closed underlying socket: %s" % str(x)) + + def testCloseSocketDoesNotCloseFile(self): + self.serv_file = self.serv.makefile('rb') + self.serv.close() + msg = self.serv_file.readline() + self.assertEqual(msg, MSG) + + def _testCloseSocketDoesNotCloseFile(self): + try: + self.cli.sendto(MSG, 0, (HOST, PORT)) + except Exception, x: + self.fail("Closing file wrapper appears to have closed underlying socket: %s" % str(x)) + +class FileAndDupOpenCloseTests(SocketConnectedTest): + + def testCloseDoesNotCloseOthers(self): + msg = self.cli_conn.recv(len(MSG)) + self.assertEqual(msg, MSG) + + msg = self.cli_conn.recv(len('and ' + MSG)) + self.assertEqual(msg, 'and ' + MSG) + + def _testCloseDoesNotCloseOthers(self): + self.dup_conn1 = self.serv_conn.dup() + self.dup_conn2 = self.serv_conn.dup() + self.cli_file = self.serv_conn.makefile('wb') + self.serv_conn.close() + self.dup_conn1.close() + + try: + self.serv_conn.send(MSG) + except socket.error, se: + self.failUnlessEqual(se[0], errno.EBADF) + else: + self.fail("Original socket did not close") + try: + self.dup_conn1.send(MSG) + except socket.error, se: + self.failUnlessEqual(se[0], errno.EBADF) + else: + self.fail("Duplicate socket 1 did not close") + + self.dup_conn2.send(MSG) + self.dup_conn2.close() + + try: + self.cli_file.write('and ' + MSG) + except Exception, x: + self.fail("Closing others appears to have closed the socket file: %s" % str(x)) + self.cli_file.close() + class FileObjectClassTestCase(SocketConnectedTest): bufsize = -1 # Use default buffer size @@ -1021,7 +1098,6 @@ else: self.fail("Binding to already bound host/port should have raised exception") - def testUnresolvedAddress(self): try: self.s.connect( ('non.existent.server', PORT) ) @@ -1050,6 +1126,26 @@ else: self.fail("Receive on unconnected socket raised exception") + def testClosedSocket(self): + self.s.close() + try: + self.s.send(MSG) + except socket.error, se: + self.failUnlessEqual(se[0], errno.EBADF) + + dup = self.s.dup() + try: + dup.send(MSG) + except socket.error, se: + self.failUnlessEqual(se[0], errno.EBADF) + + fp = self.s.makefile() + try: + fp.write(MSG) + fp.flush() + except socket.error, se: + self.failUnlessEqual(se[0], errno.EBADF) + class TestAddressParameters: def testBindNonTupleEndpointRaisesTypeError(self): @@ -1099,7 +1195,9 @@ UDPTimeoutTest, NonBlockingTCPTests, NonBlockingUDPTests, - FileObjectClassOpenCloseTests, + TCPFileObjectClassOpenCloseTests, + UDPFileObjectClassOpenCloseTests, + FileAndDupOpenCloseTests, FileObjectClassTestCase, UnbufferedFileObjectClassTestCase, LineBufferedFileObjectClassTestCase, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-11-17 01:13:19
|
Revision: 3693 http://jython.svn.sourceforge.net/jython/?rev=3693&view=rev Author: pjenvey Date: 2007-11-16 17:13:17 -0800 (Fri, 16 Nov 2007) Log Message: ----------- Merged revisions 3692 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r3692 | pjenvey | 2007-11-16 17:05:35 -0800 (Fri, 16 Nov 2007) | 4 lines handle closers being null in some strange cases fixes #1831710 patch from Byron Foster ........ Modified Paths: -------------- branches/Release_2_2maint/jython/NEWS branches/Release_2_2maint/jython/src/org/python/core/PyFile.java Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692 Modified: branches/Release_2_2maint/jython/NEWS =================================================================== --- branches/Release_2_2maint/jython/NEWS 2007-11-17 01:05:35 UTC (rev 3692) +++ branches/Release_2_2maint/jython/NEWS 2007-11-17 01:13:17 UTC (rev 3693) @@ -4,6 +4,7 @@ Bugs fixed - [ 1806980 ] os.path.join ignores empty string - [ 1744567 ] Simultaneous read & write on socket FileWrapper causes hang + - [ 1831710 ] PyFileCloser throws NullPointerException on shutdown Jython 2.2.1 Identical to 2.2.1 rc2 Modified: branches/Release_2_2maint/jython/src/org/python/core/PyFile.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PyFile.java 2007-11-17 01:05:35 UTC (rev 3692) +++ branches/Release_2_2maint/jython/src/org/python/core/PyFile.java 2007-11-17 01:13:17 UTC (rev 3693) @@ -1630,6 +1630,10 @@ } public void run() { + if (closers == null) { + // closers can be null in some strange cases + return; + } synchronized(closers) { while(closers.size() > 0) { try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-11-18 02:16:22
|
Revision: 3696 http://jython.svn.sourceforge.net/jython/?rev=3696&view=rev Author: pjenvey Date: 2007-11-17 18:16:20 -0800 (Sat, 17 Nov 2007) Log Message: ----------- Merged revisions 3695 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r3695 | pjenvey | 2007-11-17 18:15:11 -0800 (Sat, 17 Nov 2007) | 3 lines fix broken link for corner icon in html documentation fixes #1817908 patch from Nicolas Duboc ........ Modified Paths: -------------- branches/Release_2_2maint/jython/Misc/htgen/JyLocalGenerator.py branches/Release_2_2maint/jython/NEWS Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695 Modified: branches/Release_2_2maint/jython/Misc/htgen/JyLocalGenerator.py =================================================================== --- branches/Release_2_2maint/jython/Misc/htgen/JyLocalGenerator.py 2007-11-18 02:15:11 UTC (rev 3695) +++ branches/Release_2_2maint/jython/Misc/htgen/JyLocalGenerator.py 2007-11-18 02:16:20 UTC (rev 3696) @@ -25,5 +25,5 @@ return ''' <center> <a href="http://www.jython.org/"> - <img border="0" src="%(rootdir)s/images/jpython-new-small.gif"></a></center>''' % \ + <img border="0" src="%(rootdir)s/images/jython-new-small.gif"></a></center>''' % \ self._d Modified: branches/Release_2_2maint/jython/NEWS =================================================================== --- branches/Release_2_2maint/jython/NEWS 2007-11-18 02:15:11 UTC (rev 3695) +++ branches/Release_2_2maint/jython/NEWS 2007-11-18 02:16:20 UTC (rev 3696) @@ -5,6 +5,7 @@ - [ 1806980 ] os.path.join ignores empty string - [ 1744567 ] Simultaneous read & write on socket FileWrapper causes hang - [ 1831710 ] PyFileCloser throws NullPointerException on shutdown + - [ 1817908 ] Broken link for corner icon in html documentation Jython 2.2.1 Identical to 2.2.1 rc2 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-12-29 00:29:07
|
Revision: 3885 http://jython.svn.sourceforge.net/jython/?rev=3885&view=rev Author: pjenvey Date: 2007-12-28 16:29:05 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Merged revisions 3732-3734,3739,3745,3747-3748,3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3882 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r3732 | pjenvey | 2007-11-26 14:27:24 -0800 (Mon, 26 Nov 2007) | 1 line use repr() for OSError filenames like CPython does ........ r3863 | pjenvey | 2007-12-24 11:36:03 -0800 (Mon, 24 Dec 2007) | 6 lines restrict reference counting code to isinstance(sock, _nonblocking_api_mixin) instead not isinstance(sock, _closedsocket). allows urllib2's usage of _fileobject to wrap a non socket object fixes #1850722 thanks Daniel Menezes ........ r3882 | pjenvey | 2007-12-28 16:06:25 -0800 (Fri, 28 Dec 2007) | 3 lines need to pass the real socket (_nonblocking_api_mixin) to ssl now that we're wrapping it, just like CPython does ........ Modified Paths: -------------- branches/Release_2_2maint/jython/Lib/socket.py branches/Release_2_2maint/jython/Lib/test/test_socket.py branches/Release_2_2maint/jython/src/org/python/core/exceptions.java Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3745,3747-3748,3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3882 Modified: branches/Release_2_2maint/jython/Lib/socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/socket.py 2007-12-29 00:26:31 UTC (rev 3884) +++ branches/Release_2_2maint/jython/Lib/socket.py 2007-12-29 00:29:05 UTC (rev 3885) @@ -788,7 +788,7 @@ if _sock is None: _sock = _realsocket(family, type, proto) _sock.reference_count += 1 - elif not isinstance(_sock, _closedsocket): + elif isinstance(_sock, _nonblocking_api_mixin): _sock.reference_count += 1 self._sock = _sock self.send = self._sock.send @@ -799,7 +799,7 @@ def close(self): _sock = self._sock - if not isinstance(_sock, _closedsocket): + if isinstance(_sock, _nonblocking_api_mixin): _sock.close_lock.acquire() try: _sock.reference_count -=1 @@ -822,7 +822,7 @@ Return a new socket object connected to the same system resource.""" _sock = self._sock - if isinstance(_sock, _closedsocket): + if not isinstance(_sock, _nonblocking_api_mixin): return _socketobject(_sock=_sock) _sock.close_lock.acquire() @@ -838,7 +838,7 @@ Return a regular file object corresponding to the socket. The mode and bufsize arguments are as for the built-in open() function.""" _sock = self._sock - if isinstance(_sock, _closedsocket): + if not isinstance(_sock, _nonblocking_api_mixin): return _fileobject(_sock, mode, bufsize) _sock.close_lock.acquire() @@ -871,7 +871,7 @@ def __init__(self, sock, mode='rb', bufsize=-1): self._sock = sock - if not isinstance(sock, _closedsocket): + if isinstance(sock, _nonblocking_api_mixin): sock.reference_count += 1 self.mode = mode # Not actually used in this version if bufsize < 0: @@ -897,7 +897,7 @@ if self._sock: self.flush() finally: - if self._sock and not isinstance(self._sock, _closedsocket): + if self._sock and isinstance(self._sock, _nonblocking_api_mixin): self._sock.reference_count -= 1 if not self._sock.reference_count: self._sock.close() @@ -1128,6 +1128,12 @@ cert = self._get_server_cert() return cert.getIssuerDN().toString() +_realssl = ssl +def ssl(sock, keyfile=None, certfile=None): + if hasattr(sock, "_sock"): + sock = sock._sock + return _realssl(sock, keyfile, certfile) + def test(): s = socket(AF_INET, SOCK_STREAM) s.connect(("", 80)) Modified: branches/Release_2_2maint/jython/Lib/test/test_socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/test/test_socket.py 2007-12-29 00:26:31 UTC (rev 3884) +++ branches/Release_2_2maint/jython/Lib/test/test_socket.py 2007-12-29 00:29:05 UTC (rev 3885) @@ -15,6 +15,7 @@ import Queue import sys from weakref import proxy +from StringIO import StringIO PORT = 50007 HOST = 'localhost' @@ -943,6 +944,26 @@ def _testClosedAttr(self): self.assert_(not self.cli_file.closed) +class PrivateFileObjectTestCase(unittest.TestCase): + + """Test usage of socket._fileobject with an arbitrary socket-like + object. + + E.g. urllib2 wraps an httplib.HTTPResponse object with _fileobject. + """ + + def setUp(self): + self.socket_like = StringIO() + self.socket_like.recv = self.socket_like.read + self.socket_like.sendall = self.socket_like.write + + def testPrivateFileObject(self): + fileobject = socket._fileobject(self.socket_like, 'rb') + fileobject.write('hello jython') + fileobject.flush() + self.socket_like.seek(0) + self.assertEqual(fileobject.read(), 'hello jython') + class UnbufferedFileObjectClassTestCase(FileObjectClassTestCase): """Repeat the tests from FileObjectClassTestCase with bufsize==0. @@ -1199,6 +1220,7 @@ UDPFileObjectClassOpenCloseTests, FileAndDupOpenCloseTests, FileObjectClassTestCase, + PrivateFileObjectTestCase, UnbufferedFileObjectClassTestCase, LineBufferedFileObjectClassTestCase, SmallBufferedFileObjectClassTestCase Modified: branches/Release_2_2maint/jython/src/org/python/core/exceptions.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/exceptions.java 2007-12-29 00:26:31 UTC (rev 3884) +++ branches/Release_2_2maint/jython/src/org/python/core/exceptions.java 2007-12-29 00:29:05 UTC (rev 3885) @@ -380,7 +380,7 @@ PyObject self = ap.getPyObject(0); if (self.__getattr__("filename") != Py.None) { - return Py.newString("[Errno %s] %s: %s").__mod__( + return Py.newString("[Errno %s] %s: %r").__mod__( new PyTuple(new PyObject[] { self.__getattr__("errno"), self.__getattr__("strerror"), self.__getattr__("filename") })).__str__(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-12-29 02:02:30
|
Revision: 3892 http://jython.svn.sourceforge.net/jython/?rev=3892&view=rev Author: pjenvey Date: 2007-12-28 18:02:29 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Merged revisions 3891 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r3891 | pjenvey | 2007-12-28 18:01:58 -0800 (Fri, 28 Dec 2007) | 1 line changelog r3885 (r3863 merge) ........ Modified Paths: -------------- branches/Release_2_2maint/jython/NEWS Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3745,3747-3748,3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3882 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3745,3747-3748,3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3882,3891 Modified: branches/Release_2_2maint/jython/NEWS =================================================================== --- branches/Release_2_2maint/jython/NEWS 2007-12-29 02:01:58 UTC (rev 3891) +++ branches/Release_2_2maint/jython/NEWS 2007-12-29 02:02:29 UTC (rev 3892) @@ -6,6 +6,7 @@ - [ 1744567 ] Simultaneous read & write on socket FileWrapper causes hang - [ 1831710 ] PyFileCloser throws NullPointerException on shutdown - [ 1817908 ] Broken link for corner icon in html documentation + - [ 1850722 ] socket.py - ClientCookie and ClientForm (and urllib2) Jython 2.2.1 Identical to 2.2.1 rc2 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-12-30 23:01:22
|
Revision: 3914 http://jython.svn.sourceforge.net/jython/?rev=3914&view=rev Author: cgroves Date: 2007-12-30 15:01:18 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Merged revisions 3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3862,3864,3866,3871-3875,3879,3881,3883-3885,3890,3892,3895-3896,3898-3900,3904,3912-3913 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r3742 | cgroves | 2007-11-30 12:53:42 -0800 (Fri, 30 Nov 2007) | 1 line Applying patch #1814683 from markacy to fix bugs #1796425, 1796415 and 1814678 ........ r3743 | cgroves | 2007-11-30 13:21:59 -0800 (Fri, 30 Nov 2007) | 1 line Check that f_back isn't null when throwing an exception in case it's rethrown. Fixes bug #1812122 ........ r3751 | cgroves | 2007-12-02 00:36:39 -0800 (Sun, 02 Dec 2007) | 1 line patch #1830916 from byronf to attach the initially thrown Java exception to PyException so the exception chain isn't broken ........ r3753 | cgroves | 2007-12-02 11:20:58 -0800 (Sun, 02 Dec 2007) | 1 line Fix for bug #1816134 from boisgerault. Remove equals from PyString to allow PyObject's equals to be used which respects Python's __eq__ semantics. PyString's implementation was just a little optimization which actually didn't do much: it checked for interned which String.equals does already. See the added test case for the brokeness this was causing. Also have PySequenceList.equals call PyObject.equals, but leave it overriding so it can handle equality with Java List types. ........ r3754 | cgroves | 2007-12-02 12:13:08 -0800 (Sun, 02 Dec 2007) | 1 line Fix for bug #1839871. CPython's dict uses an internal setitem method to initialize itself rather than __setitem__ which can go through to its subclasses. Now Jython does as well. ........ r3755 | cgroves | 2007-12-02 14:03:30 -0800 (Sun, 02 Dec 2007) | 7 lines Fix for bug #1841445. PythonInterpreter.get(String name) would return the local value of name or null if it wasn't bound. PythonInterpreter.get(String name, Class javaclass) would return the local value as an instance of the given javaclass or throw a NullPointerException if it wasn't bound. Now the second form returns null as well when the name isn't bound. ........ r3913 | cgroves | 2007-12-30 14:54:48 -0800 (Sun, 30 Dec 2007) | 1 line Added everything I'm about to pull over to Release_2_2maint ........ Modified Paths: -------------- branches/Release_2_2maint/jython/Lib/javaos.py branches/Release_2_2maint/jython/NEWS branches/Release_2_2maint/jython/src/org/python/core/Py.java branches/Release_2_2maint/jython/src/org/python/core/PyDictionary.java branches/Release_2_2maint/jython/src/org/python/core/PyObject.java branches/Release_2_2maint/jython/src/org/python/core/PySequenceList.java branches/Release_2_2maint/jython/src/org/python/core/PyString.java branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java Added Paths: ----------- branches/Release_2_2maint/jython/Lib/test/test_dict_jy.py branches/Release_2_2maint/jython/Lib/test/test_str_jy.py Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3745,3747-3748,3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3882,3891 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913 Modified: branches/Release_2_2maint/jython/Lib/javaos.py =================================================================== --- branches/Release_2_2maint/jython/Lib/javaos.py 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/Lib/javaos.py 2007-12-30 23:01:18 UTC (rev 3914) @@ -20,11 +20,11 @@ (e.g., split and join). """ -__all__ = ["altsep", "curdir", "pardir", "sep", "pathsep", "linesep", - "defpath", "name", - "system", "environ", "putenv", "getenv", - "popen", "popen2", "popen3", "popen4", "getlogin" - ] +__all__ = ["altsep", "chdir", "curdir", "defpath", "environ", "getcwd", + "getenv", "getlogin", "linesep", "listdir", "mkdir", "name", + "pardir", "pathsep", "popen", "popen2", "popen3", "popen4", + "putenv","remove", "rename", "rmdir", "sep", "stat", "system", + "unlink", "utime"] from java.io import File import java.lang.System @@ -165,6 +165,8 @@ if not File(path).delete(): raise OSError(0, "couldn't delete file", path) +unlink = remove + def rename(path, newpath): """rename(old, new) @@ -173,6 +175,33 @@ if not File(path).renameTo(File(newpath)): raise OSError(0, "couldn't rename file", path) +#XXX: copied from CPython 2.5.1 +def renames(old, new): + """renames(old, new) + + Super-rename; create directories as necessary and delete any left + empty. Works like rename, except creation of any intermediate + directories needed to make the new pathname good is attempted + first. After the rename, directories corresponding to rightmost + path segments of the old name will be pruned way until either the + whole path is consumed or a nonempty directory is found. + + Note: this function can fail with the new directory structure made + if you lack permissions needed to unlink the leaf directory or + file. + + """ + head, tail = path.split(new) + if head and tail and not path.exists(head): + makedirs(head) + rename(old, new) + head, tail = path.split(old) + if head and tail: + try: + removedirs(head) + except error: + pass + def rmdir(path): """rmdir(path) @@ -180,8 +209,31 @@ if not File(path).delete(): raise OSError(0, "couldn't delete directory", path) -unlink = remove +#XXX: copied from CPython 2.5.1 +def removedirs(name): + """removedirs(path) + Super-rmdir; remove a leaf directory and empty all intermediate + ones. Works like rmdir except that, if the leaf directory is + successfully removed, directories corresponding to rightmost path + segments will be pruned away until either the whole path is + consumed or an error occurs. Errors during this latter phase are + ignored -- they generally mean that a directory was not empty. + + """ + rmdir(name) + head, tail = path.split(name) + if not tail: + head, tail = path.split(head) + while head and tail: + try: + rmdir(head) + except error: + break + head, tail = path.split(head) + +__all__.extend(['makedirs', 'renames', 'removedirs']) + def stat(path): """stat(path) -> stat result Copied: branches/Release_2_2maint/jython/Lib/test/test_dict_jy.py (from rev 3755, trunk/jython/Lib/test/test_dict_jy.py) =================================================================== --- branches/Release_2_2maint/jython/Lib/test/test_dict_jy.py (rev 0) +++ branches/Release_2_2maint/jython/Lib/test/test_dict_jy.py 2007-12-30 23:01:18 UTC (rev 3914) @@ -0,0 +1,30 @@ +import test_support +import unittest + +class DictInitTest(unittest.TestCase): + def testInternalSetitemInInit(self): + '''Test for http://jython.org/bugs/1816134 + + CPython's dict uses an internal setitem method to initialize itself + rather than the one on its subclasses, and this tests that Jython does + as well. + ''' + class Subdict(dict): + def __init__(self): + super(Subdict, self).__init__([('a',1)]) + self.createdInInit = 1 + + def __setitem__(self, key, value): + super(Subdict, self).__setitem__(key, value) + assert hasattr(self, 'createdInInit') + self.createdInInit = value + + s = Subdict() + s[7] = 'called' + self.assertEquals('called', s.createdInInit) + +def test_main(): + test_support.run_unittest(DictInitTest) + +if __name__ == '__main__': + test_main() Copied: branches/Release_2_2maint/jython/Lib/test/test_str_jy.py (from rev 3755, trunk/jython/Lib/test/test_str_jy.py) =================================================================== --- branches/Release_2_2maint/jython/Lib/test/test_str_jy.py (rev 0) +++ branches/Release_2_2maint/jython/Lib/test/test_str_jy.py 2007-12-30 23:01:18 UTC (rev 3914) @@ -0,0 +1,28 @@ +import test_support +import unittest + +class WrappedStrCmpTest(unittest.TestCase): + def testWrappedWorksAsKey(self): + '''Test for http://jython.org/bugs/1816134 + + PyString's equal used to check for str explicitly, so Wrapper's __cmp__ wasn't used + and a KeyError would be raised by the lookup on ABC. + ''' + class Wrapper(object): + def __init__(self, content): + self.content = content + def __hash__(self): + return hash(self.content) + def __cmp__(self, other): + if isinstance(other, Wrapper): + return cmp(self.content, other.content) + return cmp(self.content, other) + d = {'ABC' : 1} + ABC = Wrapper('ABC') + self.assertEquals(1, d[ABC]) + +def test_main(): + test_support.run_unittest(WrappedStrCmpTest) + +if __name__ == '__main__': + test_main() Modified: branches/Release_2_2maint/jython/NEWS =================================================================== --- branches/Release_2_2maint/jython/NEWS 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/NEWS 2007-12-30 23:01:18 UTC (rev 3914) @@ -7,6 +7,15 @@ - [ 1831710 ] PyFileCloser throws NullPointerException on shutdown - [ 1817908 ] Broken link for corner icon in html documentation - [ 1850722 ] socket.py - ClientCookie and ClientForm (and urllib2) + - [ 1841445 ] PythonInterpreter.get(String name, Class javaclass) throws + an NPE if name isn't defined + - [ 1839871 ] dict calls __setitem__ on subclasses in initialization + - [ 1816134 ] str uses its own __eq__ instead of deferring to subclasses + - [ 1796425 ] os.renames missing + - [ 1796415 ] os.removedirs missing + - [ 1814678 ] os.__all__ missing many functions + - [ 1812122 ] NullPointerException when rethrowing an exception + - [ 1830916 ] PyException doesn't store causal Java exception Jython 2.2.1 Identical to 2.2.1 rc2 Modified: branches/Release_2_2maint/jython/src/org/python/core/Py.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/Py.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/core/Py.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -365,7 +365,11 @@ memory_error((OutOfMemoryError)t); } PyJavaInstance exc = new PyJavaInstance(t); - return new PyException(exc.instclass, exc); + PyException pyex = new PyException(exc.instclass, exc); + // Set the cause to the original throwable to preserve + // the exception chain. + pyex.initCause(t); + return pyex; } // Don't allow any constructors. Class only provides static methods. @@ -1088,7 +1092,7 @@ PyException e = Py.JavaError(t); //Add another traceback object to the exception if needed - if (e.traceback.tb_frame != frame) { + if (e.traceback.tb_frame != frame && e.traceback.tb_frame.f_back != null) { e.traceback = new PyTraceback(e.traceback); } } @@ -1099,7 +1103,7 @@ pye.instantiate(); // attach catching frame - if (frame != null && pye.traceback.tb_frame != frame) { + if (frame != null && pye.traceback.tb_frame != frame && pye.traceback.tb_frame.f_back != null) { pye.traceback = new PyTraceback(pye.traceback); } Modified: branches/Release_2_2maint/jython/src/org/python/core/PyDictionary.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PyDictionary.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/core/PyDictionary.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -651,12 +651,12 @@ throw Py.ValueError("dictionary update sequence element #"+cnt+ " has length "+n+"; 2 is required"); } - this.__setitem__(pair.__getitem__(0),pair.__getitem__(1)); + dict___setitem__(pair.__getitem__(0), pair.__getitem__(1)); } } } - for (int i=0; i < kwds.length; i++) { - this.__setitem__(kwds[i],args[nargs+i]); + for(int i = 0; i < kwds.length; i++) { + dict___setitem__(Py.newString(kwds[i]), args[nargs + i]); } } public static PyObject fromkeys(PyObject keys) { Modified: branches/Release_2_2maint/jython/src/org/python/core/PyObject.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PyObject.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/core/PyObject.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -381,15 +381,16 @@ * <code>a.equals(b) == true</code> iff <code>cmp(a,b) == 0</code> **/ public boolean equals(Object ob_other) { - return (ob_other instanceof PyObject) - && _eq((PyObject) ob_other).__nonzero__(); + if(ob_other == this) { + return true; + } + return (ob_other instanceof PyObject) && _eq((PyObject)ob_other).__nonzero__(); } /** - * Equivalent to the standard Python __nonzero__ method. - * Returns whether of not a given <code>PyObject</code> is - * considered true. - **/ + * Equivalent to the standard Python __nonzero__ method. Returns whether of + * not a given <code>PyObject</code> is considered true. + */ public boolean __nonzero__() { return true; } Modified: branches/Release_2_2maint/jython/src/org/python/core/PySequenceList.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PySequenceList.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/core/PySequenceList.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -138,9 +138,11 @@ public boolean equals(Object o) { if(o instanceof PySequenceList) { return list.equals(((PySequenceList)o).list); - } else if (o instanceof List) { + } else if(o instanceof List) { return o.equals(this); - } else return false; + } else { + return super.equals(o); + } } public int hashCode() { Modified: branches/Release_2_2maint/jython/src/org/python/core/PyString.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PyString.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/core/PyString.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -1910,17 +1910,6 @@ return v.toString(); } - public boolean equals(Object other) { - if (!(other instanceof PyString)) - return false; - - PyString o = (PyString)other; - if (interned && o.interned) - return string == o.string; - - return string.equals(o.string); - } - public int __cmp__(PyObject other) { return str___cmp__(other); } Modified: branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -195,27 +195,36 @@ locals.__setitem__(name.intern(), value); } - /** * Get the value of a variable in the local namespace - * - * @param name the name of the variable + * + * @param name + * the name of the variable + * @return the value of the variable, or null if that name isn't assigned */ public PyObject get(String name) { return locals.__finditem__(name.intern()); } /** - * Get the value of a variable in the local namespace Value will be - * returned as an instance of the given Java class. + * Get the value of a variable in the local namespace Value will be returned + * as an instance of the given Java class. * <code>interp.get("foo", Object.class)</code> will return the most * appropriate generic Java object. - * - * @param name the name of the variable - * @param javaclass the class of object to return + * + * @param name + * the name of the variable + * @param javaclass + * the class of object to return + * @return the value of the variable as the given class, or null if that + * name isn't assigned */ public Object get(String name, Class javaclass) { - return Py.tojava(locals.__finditem__(name.intern()), javaclass); + PyObject val = locals.__finditem__(name.intern()); + if(val == null) { + return null; + } + return Py.tojava(val, javaclass); } public void cleanup() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-01-13 09:20:15
|
Revision: 4023 http://jython.svn.sourceforge.net/jython/?rev=4023&view=rev Author: cgroves Date: 2008-01-13 01:20:13 -0800 (Sun, 13 Jan 2008) Log Message: ----------- Merged revisions 4022 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk sans the ThreadStateMapping changes since they just added generics. ........ r4022 | cgroves | 2008-01-13 01:07:10 -0800 (Sun, 13 Jan 2008) | 6 lines Make profilefunc and tracefunc per thread instead of per systemstate to match CPython. From patch #1841378 from paulj_edgewater. Should fix bug #1757127 and bug #1870039 which were both running into this difference in Pydev's debugger. ........ Modified Paths: -------------- branches/Release_2_2maint/jython/src/org/python/core/PyFrame.java branches/Release_2_2maint/jython/src/org/python/core/PySystemState.java branches/Release_2_2maint/jython/src/org/python/core/PyTableCode.java branches/Release_2_2maint/jython/src/org/python/core/PythonTraceFunction.java branches/Release_2_2maint/jython/src/org/python/core/ThreadState.java branches/Release_2_2maint/jython/src/org/python/util/InteractiveInterpreter.java Added Paths: ----------- branches/Release_2_2maint/jython/Lib/test/test_trace_threaded.py Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913,4022 Copied: branches/Release_2_2maint/jython/Lib/test/test_trace_threaded.py (from rev 4022, trunk/jython/Lib/test/test_trace_threaded.py) =================================================================== --- branches/Release_2_2maint/jython/Lib/test/test_trace_threaded.py (rev 0) +++ branches/Release_2_2maint/jython/Lib/test/test_trace_threaded.py 2008-01-13 09:20:13 UTC (rev 4023) @@ -0,0 +1,58 @@ +import sys +import threading +import time +import unittest + +from test import test_support + +class UntracedThread(threading.Thread): + def __init__(self): + threading.Thread.__init__(self) + + def run(self): + sys.settrace(None) + for i in range(10): + self.untracedcall() + + def untracedcall(self): + pass + +class TracedThread(threading.Thread): + def __init__(self, on_trace): + threading.Thread.__init__(self) + self.on_trace = on_trace + + def trace(self, frame, event, arg): + self.on_trace(frame.f_code.co_name) + + def tracedcall(self): + pass + + def run(self): + sys.settrace(self.trace) + for i in range(10): + self.tracedcall() + +class TracePerThreadTest(unittest.TestCase): + def testTracePerThread(self): + called = [] + def ontrace(co_name): + called.append(str(co_name)) + + untraced = UntracedThread() + traced = TracedThread(ontrace) + untraced.start() + traced.start() + untraced.join() + traced.join() + + self.assertEquals(10, called.count('tracedcall'), + "10 tracedcall should be in %s" % called) + self.assert_('untracedcall' not in called, + "untracedcall shouldn't be in %s" % called) + +def test_main(): + test_support.run_unittest(TracePerThreadTest) + +if __name__ == "__main__": + test_main() Modified: branches/Release_2_2maint/jython/src/org/python/core/PyFrame.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PyFrame.java 2008-01-13 09:07:10 UTC (rev 4022) +++ branches/Release_2_2maint/jython/src/org/python/core/PyFrame.java 2008-01-13 09:20:13 UTC (rev 4023) @@ -146,6 +146,13 @@ return f_locals; } + // + // Track the current line number. Called by generated code. + // + // This is not to be confused with the CPython method + // frame_setlineno() which causes the interpreter to jump to + // the given line. + // public void setline(int line) { f_lineno = line; if (tracefunc != null) Modified: branches/Release_2_2maint/jython/src/org/python/core/PySystemState.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PySystemState.java 2008-01-13 09:07:10 UTC (rev 4022) +++ branches/Release_2_2maint/jython/src/org/python/core/PySystemState.java 2008-01-13 09:20:13 UTC (rev 4023) @@ -769,25 +769,22 @@ packageManager.addJarDir(directoryPath, cache); } - public TraceFunction tracefunc = null; - public TraceFunction profilefunc = null; public void settrace(PyObject tracefunc) { - //InterpreterState interp = Py.getThreadState().interp; + ThreadState ts = Py.getThreadState(); if (tracefunc == Py.None) { - this.tracefunc = null; + ts.tracefunc = null; } else { - this.tracefunc = new PythonTraceFunction(tracefunc); + ts.tracefunc = new PythonTraceFunction(tracefunc); } } public void setprofile(PyObject profilefunc) { - //InterpreterState interp = Py.getThreadState().interp; - + ThreadState ts = Py.getThreadState(); if (profilefunc == Py.None) { - this.profilefunc = null; + ts.profilefunc = null; } else { - this.profilefunc = new PythonTraceFunction(profilefunc); + ts.profilefunc = new PythonTraceFunction(profilefunc); } } Modified: branches/Release_2_2maint/jython/src/org/python/core/PyTableCode.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PyTableCode.java 2008-01-13 09:07:10 UTC (rev 4022) +++ branches/Release_2_2maint/jython/src/org/python/core/PyTableCode.java 2008-01-13 09:20:13 UTC (rev 4023) @@ -167,49 +167,14 @@ ts.frame = frame; // Handle trace function for debugging - PySystemState ss = ts.systemState; - if (ss.tracefunc != null) { - // Jython and CPython differ here. CPython actually lays down - // an extra SET_LINENO bytecode for function definition line. - // This is ostensibly so that a tuple unpacking failure in - // argument passing gets the right line number in the - // traceback. It also means that when tracing a function, - // you'll see two 'line' events, one for the def line and then - // immediately after, one for the first line of the function. - // - // Jython on the other hand only lays down a call in the - // generated Java function to set the line number for the first - // line of the function (i.e. not the def line). This - // difference in behavior doesn't seem to affect arg tuple - // unpacking tracebacks, but it does mean that function tracing - // gives slightly different behavior. Is this bad? Until - // someone complains... no. - // - // The second commented out line fixes this but it is probably - // not the right solution. Better would be to fix the code - // generator to lay down two calls to setline() in the - // classfile. This would allow that call to be optimized out - // when using the -O option. I suppose on the other hand we - // could test that flag here and not call the setline below. - // In either case, it probably doesn't make sense to slow down - // function calling even by this miniscule amount until it's - // shown to have a detrimental effect. - // - // Note also that if you were to print out frame.f_lineno in - // the `call' event handler of your trace function, you'd see - // zero instead of the line of the def. That's what the first - // commented line fixes. - // - // 9-Sep-1999 baw - // -// frame.f_lineno = co_firstlineno; - frame.tracefunc = ss.tracefunc.traceCall(frame); - frame.setline(co_firstlineno); + if (ts.tracefunc != null) { + frame.f_lineno = co_firstlineno; + frame.tracefunc = ts.tracefunc.traceCall(frame); } // Handle trace function for profiling - if (ss.profilefunc != null) { - ss.profilefunc.traceCall(frame); + if (ts.profilefunc != null) { + ts.profilefunc.traceCall(frame); } PyObject ret; @@ -239,8 +204,8 @@ if (frame.tracefunc != null) { frame.tracefunc.traceException(frame, e); } - if (ss.profilefunc != null) { - ss.profilefunc.traceException(frame, e); + if (ts.profilefunc != null) { + ts.profilefunc.traceException(frame, e); } //Rethrow the exception to the next stack frame @@ -253,8 +218,8 @@ frame.tracefunc.traceReturn(frame, ret); } // Handle trace function for profiling - if (ss.profilefunc != null) { - ss.profilefunc.traceReturn(frame, ret); + if (ts.profilefunc != null) { + ts.profilefunc.traceReturn(frame, ret); } // Restore previously defined exception Modified: branches/Release_2_2maint/jython/src/org/python/core/PythonTraceFunction.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PythonTraceFunction.java 2008-01-13 09:07:10 UTC (rev 4022) +++ branches/Release_2_2maint/jython/src/org/python/core/PythonTraceFunction.java 2008-01-13 09:20:13 UTC (rev 4023) @@ -24,8 +24,8 @@ ret = tracefunc.__call__(frame, new PyString(label), arg); } catch(PyException exc) { frame.tracefunc = null; - ts.systemState.tracefunc = null; - ts.systemState.profilefunc = null; + ts.tracefunc = null; + ts.profilefunc = null; throw exc; } finally { ts.tracing = false; Modified: branches/Release_2_2maint/jython/src/org/python/core/ThreadState.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/ThreadState.java 2008-01-13 09:07:10 UTC (rev 4022) +++ branches/Release_2_2maint/jython/src/org/python/core/ThreadState.java 2008-01-13 09:20:13 UTC (rev 4023) @@ -28,6 +28,9 @@ public int recursion_depth = 0; + public TraceFunction tracefunc; + public TraceFunction profilefunc; + public PyInstance getInitializingProxy() { if (this.initializingProxies == null || this.initializingProxies.empty()) { Modified: branches/Release_2_2maint/jython/src/org/python/util/InteractiveInterpreter.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/util/InteractiveInterpreter.java 2008-01-13 09:07:10 UTC (rev 4022) +++ branches/Release_2_2maint/jython/src/org/python/util/InteractiveInterpreter.java 2008-01-13 09:20:13 UTC (rev 4023) @@ -118,11 +118,11 @@ **/ public void interrupt(ThreadState ts) { TraceFunction breaker = new BreakTraceFunction(); - TraceFunction oldTrace = ts.systemState.tracefunc; - ts.systemState.tracefunc = breaker; + TraceFunction oldTrace = ts.tracefunc; + ts.tracefunc = breaker; if (ts.frame != null) ts.frame.tracefunc = breaker; - ts.systemState.tracefunc = oldTrace; + ts.tracefunc = oldTrace; //ts.thread.join(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-01-19 23:00:04
|
Revision: 4060 http://jython.svn.sourceforge.net/jython/?rev=4060&view=rev Author: cgroves Date: 2008-01-19 14:59:53 -0800 (Sat, 19 Jan 2008) Log Message: ----------- Merged revisions 4059 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r4059 | cgroves | 2008-01-19 14:52:16 -0800 (Sat, 19 Jan 2008) | 1 line synchronize around registry_init so if two threads start up and use codecs immediately, they both get a valid list of encodings ........ Modified Paths: -------------- branches/Release_2_2maint/jython/src/org/python/core/codecs.java Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913,4022 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913,4022,4059 Modified: branches/Release_2_2maint/jython/src/org/python/core/codecs.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/codecs.java 2008-01-19 22:52:16 UTC (rev 4059) +++ branches/Release_2_2maint/jython/src/org/python/core/codecs.java 2008-01-19 22:59:53 UTC (rev 4060) @@ -80,14 +80,18 @@ private static boolean import_encodings_called = false; + private static final Object IMPORT_LOCK = new Object(); + private static void import_encodings() { - if (!import_encodings_called) { - import_encodings_called = true; - try { - __builtin__.__import__("encodings"); - } catch (PyException exc) { - if (exc.type != Py.ImportError) { - throw exc; + synchronized (IMPORT_LOCK) { + if (!import_encodings_called) { + import_encodings_called = true; + try { + __builtin__.__import__("encodings"); + } catch (PyException exc) { + if (exc.type != Py.ImportError) { + throw exc; + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-02-16 07:36:04
|
Revision: 4133 http://jython.svn.sourceforge.net/jython/?rev=4133&view=rev Author: cgroves Date: 2008-02-15 23:36:02 -0800 (Fri, 15 Feb 2008) Log Message: ----------- Merged revisions 4132 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r4132 | cgroves | 2008-02-15 23:34:24 -0800 (Fri, 15 Feb 2008) | 1 line Make the module the interpreter is running __main__ not main ........ Modified Paths: -------------- branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913,4022,4059 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913,4022,4059,4132 Modified: branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java 2008-02-16 07:34:24 UTC (rev 4132) +++ branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java 2008-02-16 07:36:02 UTC (rev 4133) @@ -53,7 +53,7 @@ * @param dict the dictionary to use */ - // Optional dictionary willl be used for locals namespace + // Optional dictionary will be used for locals namespace public PythonInterpreter(PyObject dict) { this(dict, null); } @@ -66,7 +66,7 @@ if (systemState == null) systemState = new PySystemState(); } - module = new PyModule("main", dict); + module = new PyModule("__main__", dict); this.systemState = systemState; locals = module.__dict__; setState(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-16 02:13:50
|
Revision: 4956 http://jython.svn.sourceforge.net/jython/?rev=4956&view=rev Author: pjenvey Date: 2008-07-15 19:13:48 -0700 (Tue, 15 Jul 2008) Log Message: ----------- Merged revisions 4953,4955 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r4953 | pjenvey | 2008-07-15 18:15:46 -0700 (Tue, 15 Jul 2008) | 1 line restore proto=0 as _realsocket asserts it so ........ r4955 | pjenvey | 2008-07-15 19:11:48 -0700 (Tue, 15 Jul 2008) | 1 line use getClass here incase class becomes a permanent keyword in 2.5 ........ Modified Paths: -------------- branches/Release_2_2maint/jython/Lib/socket.py Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913,4022,4059,4132 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913,4022,4059,4132,4953,4955 Modified: branches/Release_2_2maint/jython/Lib/socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/socket.py 2008-07-16 02:11:48 UTC (rev 4955) +++ branches/Release_2_2maint/jython/Lib/socket.py 2008-07-16 02:13:48 UTC (rev 4956) @@ -494,7 +494,7 @@ else: return _udpsocket() -def getaddrinfo(host, port, family=None, socktype=None, proto=None, flags=None): +def getaddrinfo(host, port, family=None, socktype=None, proto=0, flags=None): try: if not family in [AF_INET, AF_INET6, AF_UNSPEC]: raise NotSupportedError() @@ -510,7 +510,7 @@ results = [] for a in java.net.InetAddress.getAllByName(host): if len([f for f in filter_fns if f(a)]): - family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.class] + family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.getClass()] # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses results.append( (family, socktype, proto, a.getCanonicalHostName(), (a.getHostAddress(), port)) ) return results This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |