From: <zy...@us...> - 2009-02-24 04:58:03
|
Revision: 6044 http://jython.svn.sourceforge.net/jython/?rev=6044&view=rev Author: zyasoft Date: 2009-02-24 04:57:56 +0000 (Tue, 24 Feb 2009) Log Message: ----------- Merged revisions 5950-5951,5953-5957,5959,5961,5965-5966,5971-5976,5978-5979,5981-5983,5992,6001,6003,6006-6014,6023,6031-6037,6039-6040 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5950 | zyasoft | 2009-01-20 11:28:03 -0700 (Tue, 20 Jan 2009) | 4 lines Added os.getcwdu. This fixes #1219 (necessary for Django 1.0.2 support), but not the larger question of better Unicode handling in the os module, specifically around os.path. ........ r5951 | leosoto | 2009-01-20 12:29:17 -0700 (Tue, 20 Jan 2009) | 1 line Use the new getcwdu on POSIXHandler, to avoid unnecesary conversions from unicode to bytestring. Also added getcwdu to os.__all__ ........ r5953 | cgroves | 2009-01-21 13:47:19 -0700 (Wed, 21 Jan 2009) | 1 line Break out the compile method for use in subclasses ........ r5954 | cgroves | 2009-01-21 14:26:50 -0700 (Wed, 21 Jan 2009) | 1 line Turn includeJavaStackInExceptions on by default as it was always done in previous versions. ........ r5955 | cgroves | 2009-01-21 16:32:55 -0700 (Wed, 21 Jan 2009) | 8 lines Add a jython initializer service. If META-INF/services/org.python.core.JythonInitializer is on the classpath, the class named in that file will be instantiated and used in Jython's initialization. This is useful when Jython is initialized by a library outside of your control, but some customization still needs to be done to Jython's environment. I promise not to add a JythonFactory or a JythonFactoryFactory. ........ r5956 | fwierzbicki | 2009-01-21 19:21:08 -0700 (Wed, 21 Jan 2009) | 4 lines Fix for http://bugs.jython.org/issue1239. When jars where added to sys.path, they did not always trigger package caching, leading to unexpected import failures. This is Charlie Grove's fix, which was much better than mine. ........ r5957 | fwierzbicki | 2009-01-21 21:16:47 -0700 (Wed, 21 Jan 2009) | 7 lines Thanks to Marc Downie for this patch that fixes http://bugs.jython.org/issue1230 importing with '*' from java packages does not work with 2.5b1. Also added a test to test_java_integration.py. ........ r5959 | cgroves | 2009-01-22 12:50:18 -0700 (Thu, 22 Jan 2009) | 1 line Expose rich comparision methods on Java classes implementing Comparable ........ r5961 | fwierzbicki | 2009-01-22 18:03:39 -0700 (Thu, 22 Jan 2009) | 3 lines Over-ride pyset in PyTuple so our tuples go back to being immutable. Fixes http://bugs.jython.org/issue1242. ........ r5965 | pjenvey | 2009-01-23 16:40:46 -0700 (Fri, 23 Jan 2009) | 2 lines more java.lang.Strings to regular str instead of unicode ........ r5966 | pjenvey | 2009-01-23 17:17:40 -0700 (Fri, 23 Jan 2009) | 3 lines merge from: http://svn.python.org/projects/python/branches/release25-maint/Lib/platform.py -c 66214 ........ r5971 | cgroves | 2009-01-24 13:10:59 -0700 (Sat, 24 Jan 2009) | 1 line Run the java import * test from a sub-interpreter to allow regrtest to be run with python.cachedir.skip=true ........ r5972 | cgroves | 2009-01-24 13:11:54 -0700 (Sat, 24 Jan 2009) | 1 line Try the current classloader for places where the context classloader isn't set ........ r5973 | cgroves | 2009-01-24 13:17:39 -0700 (Sat, 24 Jan 2009) | 1 line Exclude the xerces service declaration as our jarjar'd version doesn't match the names in the declaration ........ r5974 | cgroves | 2009-01-25 05:15:25 -0700 (Sun, 25 Jan 2009) | 1 line Bring up to the current state of affairs ........ r5975 | cgroves | 2009-01-25 05:19:27 -0700 (Sun, 25 Jan 2009) | 3 lines Use Python's mro to determine an mro for Java classes and interfaces. If the Java class has an mro conflict, resolve it by arbitrarily choosing an interface or class. If an interface or class involved in an mro conflict has had its dict modified, or has its dict modified, raise a TypeError. ........ r5976 | cgroves | 2009-01-25 05:19:58 -0700 (Sun, 25 Jan 2009) | 1 line Test support classes for the last commit ........ r5978 | nriley | 2009-01-25 14:06:04 -0700 (Sun, 25 Jan 2009) | 1 line Typo fix. ........ r5979 | cgroves | 2009-01-25 17:33:21 -0700 (Sun, 25 Jan 2009) | 4 lines Include Python Java subclasses as bases as well as the Java proxy type, as it may have additional methods in its Python. Return the proxyClass directly from getProxyType as we're setting that on Python subclasses now. ........ r5981 | cgroves | 2009-01-25 19:21:05 -0700 (Sun, 25 Jan 2009) | 1 line Defer resolving inner classes till the containing class is fully resolved. Fixes issue #1234. ........ r5982 | cgroves | 2009-01-25 20:10:36 -0700 (Sun, 25 Jan 2009) | 1 line Try to assign to a static field for a given name in __setattr__ on a Java type before filling something in on the dict. Fixes bug #1241 ........ r5983 | cgroves | 2009-01-25 20:36:25 -0700 (Sun, 25 Jan 2009) | 1 line Fix javatests ........ r5992 | amak | 2009-01-28 09:05:59 -0700 (Wed, 28 Jan 2009) | 3 lines Fix and unit test for bug 1244. Problem letting system choose the port for binding UDP socket http://bugs.jython.org/issue1244 ........ r6001 | amak | 2009-01-29 10:59:04 -0700 (Thu, 29 Jan 2009) | 2 lines Re-arranging the socket shutdown methods. TCP client sockets can shutdown their input streams, but this is not appropriate for either TCP server sockets or UDP sockets, which don't have input and output streams. For these latter two types, the shutdown method should have the same effect as the close method, and thus the shutdown method is a no-op for these types. I have documented this difference between cpython and jython on the wiki. This should finally resolve bug 1121: listening socket shutdown expects the wrong kind of socket http://bugs.jython.org/issue1121 ........ r6003 | pjenvey | 2009-01-30 19:20:48 -0700 (Fri, 30 Jan 2009) | 1 line make --version resemble CPython ........ r6006 | amak | 2009-02-02 08:50:25 -0700 (Mon, 02 Feb 2009) | 4 lines Fix for bug 1258. select() semantics differ from CPython, causing pydoc HTTPd to fail http://bugs.jython.org/issue1258 Thanks to Ryan Blair for reporting the bug and providing a patch. ........ r6007 | amak | 2009-02-03 05:01:46 -0700 (Tue, 03 Feb 2009) | 2 lines Committing the latest version of modjy. See the release notes for details. ........ r6008 | pjenvey | 2009-02-03 13:19:57 -0700 (Tue, 03 Feb 2009) | 1 line fix test_version per r6003 ........ r6009 | pjenvey | 2009-02-03 14:25:23 -0700 (Tue, 03 Feb 2009) | 2 lines include PATH for platforms lacking bash in /bin ........ r6010 | leosoto | 2009-02-03 17:51:47 -0700 (Tue, 03 Feb 2009) | 1 line PyObject#reduce_2: Use invoke("iteritems") instead of this.iteritems() to avoid problems with dict subclasses which override iteritems on python code. Fixes #1257 ........ r6011 | amak | 2009-02-04 08:20:56 -0700 (Wed, 04 Feb 2009) | 4 lines Our asyncore is completely broken; see bug 1237. Asnycore does not seem to work in Jython 2.5 (b0 or b1) http://bugs.jython.org/issue1237 Starting again from scratch; Step 1: remove existing module. ........ r6012 | amak | 2009-02-04 08:22:21 -0700 (Wed, 04 Feb 2009) | 1 line Fresh start with asyncore; step 2: copy over asyncore from cpython 2.5.2. ........ r6013 | amak | 2009-02-04 08:27:59 -0700 (Wed, 04 Feb 2009) | 3 lines Fresh start with asycnore; step 3: make necessary changes to cpython 2.5 module to work on jython 2.5. The code in this bug report now works identically to cpython. http://bugs.jython.org/issue1237 ........ r6014 | otmarhumbel | 2009-02-05 11:08:10 -0700 (Thu, 05 Feb 2009) | 1 line added dummy_thread.py and dummy_threading.py ........ r6023 | fwierzbicki | 2009-02-08 18:40:53 -0700 (Sun, 08 Feb 2009) | 2 lines Fix for http://bugs.jython.org/issue1243. Thanks RJ Ryan for suggesting the fix. ........ r6031 | fwierzbicki | 2009-02-15 07:23:28 -0700 (Sun, 15 Feb 2009) | 3 lines Fix potential infinite loop (and wrong slice behavior) -- found with FindBugs ........ r6032 | fwierzbicki | 2009-02-15 11:22:18 -0700 (Sun, 15 Feb 2009) | 2 lines Fixed two infinite recursions found with FindBugs. ........ r6033 | fwierzbicki | 2009-02-15 11:31:27 -0700 (Sun, 15 Feb 2009) | 2 lines Fixed NPE found with FindBugs. ........ r6034 | amak | 2009-02-15 11:35:41 -0700 (Sun, 15 Feb 2009) | 2 lines A new version of modjy, containing some bug fixes kindly contributed by Philip Jenvey; see contained release notes for more information. http://github.com/pjenvey/modjy-pjenvey ........ r6035 | pjenvey | 2009-02-15 16:27:44 -0700 (Sun, 15 Feb 2009) | 3 lines double antlr's conversiontimeout for slower environments, in particular the hudson buildot ........ r6036 | fwierzbicki | 2009-02-16 08:41:50 -0700 (Mon, 16 Feb 2009) | 2 lines Useless double assignment. ........ r6037 | fwierzbicki | 2009-02-16 19:38:09 -0700 (Mon, 16 Feb 2009) | 2 lines Make the public adapters in AstAdapters final. ........ r6039 | amak | 2009-02-18 06:21:13 -0700 (Wed, 18 Feb 2009) | 1 line Updating the zip file for modjy 0.25.3; previously checked in version had the wrong version of modjy.jar in WEB-INF/lib. ........ r6040 | fwierzbicki | 2009-02-19 13:16:18 -0700 (Thu, 19 Feb 2009) | 4 lines Our handling of writes after a seek beyond the end of cStringIO was not consistent with CPython (or even our own use of StringIO). Found while trying to get Mercurial to respond to "hg log". ........ Modified Paths: -------------- branches/pbcvm/CPythonLib.includes branches/pbcvm/Lib/os.py branches/pbcvm/Lib/platform.py branches/pbcvm/Lib/pydoc.py branches/pbcvm/Lib/socket.py branches/pbcvm/Lib/test/test_StringIO_jy.py branches/pbcvm/Lib/test/test_classpathimporter.py branches/pbcvm/Lib/test/test_cmd_line.py branches/pbcvm/Lib/test/test_import_jy.py branches/pbcvm/Lib/test/test_java_integration.py branches/pbcvm/Lib/test/test_java_subclasses.py branches/pbcvm/Lib/test/test_java_visibility.py branches/pbcvm/Lib/test/test_socket.py branches/pbcvm/Lib/test/test_tuple.py branches/pbcvm/build.xml branches/pbcvm/registry branches/pbcvm/src/org/python/antlr/adapter/AstAdapters.java branches/pbcvm/src/org/python/compiler/JavaMaker.java branches/pbcvm/src/org/python/core/AstList.java branches/pbcvm/src/org/python/core/ClasspathPyImporter.java branches/pbcvm/src/org/python/core/Options.java branches/pbcvm/src/org/python/core/Py.java branches/pbcvm/src/org/python/core/PyJavaType.java branches/pbcvm/src/org/python/core/PyNewWrapper.java branches/pbcvm/src/org/python/core/PyObject.java branches/pbcvm/src/org/python/core/PySequence.java branches/pbcvm/src/org/python/core/PySystemState.java branches/pbcvm/src/org/python/core/PyTuple.java branches/pbcvm/src/org/python/core/PyType.java branches/pbcvm/src/org/python/core/SyspathJavaLoader.java branches/pbcvm/src/org/python/core/ThreadStateMapping.java branches/pbcvm/src/org/python/core/imp.java branches/pbcvm/src/org/python/core/packagecache/PackageManager.java branches/pbcvm/src/org/python/core/packagecache/PathPackageManager.java branches/pbcvm/src/org/python/modules/_csv/PyWriter.java branches/pbcvm/src/org/python/modules/cStringIO.java branches/pbcvm/src/org/python/modules/thread/PyLocal.java branches/pbcvm/src/org/python/util/JycompileAntTask.java branches/pbcvm/src/org/python/util/jython.java branches/pbcvm/tests/java/org/python/expose/generate/TypeExposerTest.java branches/pbcvm/tests/java/org/python/tests/Coercions.java branches/pbcvm/tests/java/org/python/tests/Visible.java Added Paths: ----------- branches/pbcvm/Lib/asyncore.py branches/pbcvm/Lib/test/bug1239.jar branches/pbcvm/Lib/test/check_for_initializer_in_syspath.py branches/pbcvm/Lib/test/import_star_from_java.py branches/pbcvm/Lib/test/test_jython_initializer.py branches/pbcvm/extlibs/modjy_0_25_3.zip branches/pbcvm/src/org/python/core/JythonInitializer.java branches/pbcvm/tests/data/ branches/pbcvm/tests/data/initializer/ branches/pbcvm/tests/data/initializer/META-INF/ branches/pbcvm/tests/data/initializer/META-INF/services/ branches/pbcvm/tests/data/initializer/META-INF/services/org.python.core.JythonInitializer branches/pbcvm/tests/data/initializer/SyspathAppendingInitializer.java branches/pbcvm/tests/java/org/python/tests/inbred/ branches/pbcvm/tests/java/org/python/tests/inbred/Metis.java branches/pbcvm/tests/java/org/python/tests/inbred/Zeus.java branches/pbcvm/tests/java/org/python/tests/mro/ branches/pbcvm/tests/java/org/python/tests/mro/ConfusedOnGetitemAdd.java branches/pbcvm/tests/java/org/python/tests/mro/ConfusedOnImport.java branches/pbcvm/tests/java/org/python/tests/mro/FirstAndPost.java branches/pbcvm/tests/java/org/python/tests/mro/FirstAndSecond.java branches/pbcvm/tests/java/org/python/tests/mro/FirstPredefinedGetitem.java branches/pbcvm/tests/java/org/python/tests/mro/GetitemAdder.java branches/pbcvm/tests/java/org/python/tests/mro/PostAndFirst.java branches/pbcvm/tests/java/org/python/tests/mro/PostdefinedGetitem.java branches/pbcvm/tests/java/org/python/tests/mro/SecondAndFirst.java branches/pbcvm/tests/java/org/python/tests/mro/SecondPredefinedGetitem.java Removed Paths: ------------- branches/pbcvm/Lib/asyncore.py branches/pbcvm/extlibs/modjy_0_25_1.zip branches/pbcvm/tests/data/initializer/ branches/pbcvm/tests/data/initializer/META-INF/ branches/pbcvm/tests/data/initializer/META-INF/services/ branches/pbcvm/tests/data/initializer/META-INF/services/org.python.core.JythonInitializer branches/pbcvm/tests/data/initializer/SyspathAppendingInitializer.java branches/pbcvm/tests/java/org/python/tests/inbred/Metis.java branches/pbcvm/tests/java/org/python/tests/inbred/Zeus.java branches/pbcvm/tests/java/org/python/tests/mro/ConfusedOnGetitemAdd.java branches/pbcvm/tests/java/org/python/tests/mro/ConfusedOnImport.java branches/pbcvm/tests/java/org/python/tests/mro/FirstAndPost.java branches/pbcvm/tests/java/org/python/tests/mro/FirstAndSecond.java branches/pbcvm/tests/java/org/python/tests/mro/FirstPredefinedGetitem.java branches/pbcvm/tests/java/org/python/tests/mro/GetitemAdder.java branches/pbcvm/tests/java/org/python/tests/mro/PostAndFirst.java branches/pbcvm/tests/java/org/python/tests/mro/PostdefinedGetitem.java branches/pbcvm/tests/java/org/python/tests/mro/SecondAndFirst.java branches/pbcvm/tests/java/org/python/tests/mro/SecondPredefinedGetitem.java Property Changed: ---------------- branches/pbcvm/ Property changes on: branches/pbcvm ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-5947 + /trunk/jython:1-6043 Modified: branches/pbcvm/CPythonLib.includes =================================================================== --- branches/pbcvm/CPythonLib.includes 2009-02-24 04:37:39 UTC (rev 6043) +++ branches/pbcvm/CPythonLib.includes 2009-02-24 04:57:56 UTC (rev 6044) @@ -52,6 +52,8 @@ DocXMLRPCServer.py dospath.py dumbdbm.py +dummy_thread.py +dummy_threading.py exceptions.py fileinput.py fnmatch.py Deleted: branches/pbcvm/Lib/asyncore.py =================================================================== --- branches/pbcvm/Lib/asyncore.py 2009-02-24 04:37:39 UTC (rev 6043) +++ branches/pbcvm/Lib/asyncore.py 2009-02-24 04:57:56 UTC (rev 6044) @@ -1,561 +0,0 @@ -# -*- Mode: Python -*- -# Id: asyncore.py,v 2.51 2000/09/07 22:29:26 rushing Exp -# Author: Sam Rushing <ru...@ni...> - -# ====================================================================== -# Copyright 1996 by Sam Rushing -# -# All Rights Reserved -# -# Permission to use, copy, modify, and distribute this software and -# its documentation for any purpose and without fee is hereby -# granted, provided that the above copyright notice appear in all -# copies and that both that copyright notice and this permission -# notice appear in supporting documentation, and that the name of Sam -# Rushing not be used in advertising or publicity pertaining to -# distribution of the software without specific, written prior -# permission. -# -# SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN -# NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR -# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, -# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# ====================================================================== - -"""Basic infrastructure for asynchronous socket service clients and servers. - -There are only two ways to have a program on a single processor do "more -than one thing at a time". Multi-threaded programming is the simplest and -most popular way to do it, but there is another very different technique, -that lets you have nearly all the advantages of multi-threading, without -actually using multiple threads. it's really only practical if your program -is largely I/O bound. If your program is CPU bound, then pre-emptive -scheduled threads are probably what you really need. Network servers are -rarely CPU-bound, however. - -If your operating system supports the select() system call in its I/O -library (and nearly all do), then you can use it to juggle multiple -communication channels at once; doing other work while your I/O is taking -place in the "background." Although this strategy can seem strange and -complex, especially at first, it is in many ways easier to understand and -control than multi-threaded programming. The module documented here solves -many of the difficult problems for you, making the task of building -sophisticated high-performance network servers and clients a snap. -""" - -import exceptions -import select -import socket -import sys -import time - -import os -from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \ - ENOTCONN, ESHUTDOWN, EINTR, EISCONN - -try: - socket_map -except NameError: - socket_map = {} - -class ExitNow(exceptions.Exception): - pass - -def read(obj): - try: - obj.handle_read_event() - except ExitNow: - raise - except: - obj.handle_error() - -def write(obj): - try: - obj.handle_write_event() - except ExitNow: - raise - except: - obj.handle_error() - -def readwrite(obj, flags): - try: - if flags & select.POLLIN: - obj.handle_read_event() - if flags & select.POLLOUT: - obj.handle_write_event() - except ExitNow: - raise - except: - obj.handle_error() - -def poll(timeout=0.0, map=None): - if map is None: - map = socket_map - if map: - r = []; w = []; e = [] - for fd, obj in map.items(): - if obj.readable(): - r.append(fd) - if obj.writable(): - w.append(fd) - if [] == r == w == e: - time.sleep(timeout) - else: - try: - r, w, e = select.select(r, w, e, timeout) - except select.error, err: - if err[0] != EINTR: - raise - else: - return - - for fd in r: - obj = map.get(fd) - if obj is None: - continue - read(obj) - - for fd in w: - obj = map.get(fd) - if obj is None: - continue - write(obj) - -def poll2(timeout=0.0, map=None): - import poll - if map is None: - map = socket_map - if timeout is not None: - # timeout is in milliseconds - timeout = int(timeout*1000) - if map: - l = [] - for fd, obj in map.items(): - flags = 0 - if obj.readable(): - flags = poll.POLLIN - if obj.writable(): - flags = flags | poll.POLLOUT - if flags: - l.append((fd, flags)) - r = poll.poll(l, timeout) - for fd, flags in r: - obj = map.get(fd) - if obj is None: - continue - readwrite(obj, flags) - -def poll3(timeout=0.0, map=None): - # Use the poll() support added to the select module in Python 2.0 - if map is None: - map = socket_map - if timeout is not None: - # timeout is in milliseconds - timeout = int(timeout*1000) - pollster = select.poll() - if map: - for fd, obj in map.items(): - flags = 0 - if obj.readable(): - flags = select.POLLIN - if obj.writable(): - flags = flags | select.POLLOUT - if flags: - pollster.register(fd, flags) - try: - r = pollster.poll(timeout) - except select.error, err: - if err[0] != EINTR: - raise - r = [] - for fd, flags in r: - obj = map.get(fd) - if obj is None: - continue - readwrite(obj, flags) - -def loop(timeout=30.0, use_poll=0, map=None): - if map is None: - map = socket_map - - if use_poll: - if hasattr(select, 'poll'): - poll_fun = poll3 - else: - poll_fun = poll2 - else: - poll_fun = poll - - while map: - poll_fun(timeout, map) - -class dispatcher: - - debug = 0 - connected = 0 - accepting = 0 - closing = 0 - addr = None - - def __init__(self, sock=None, map=None): - if sock: - self.set_socket(sock, map) - # I think it should inherit this anyway - self.socket.setblocking(0) - self.connected = 1 - # XXX Does the constructor require that the socket passed - # be connected? - try: - self.addr = sock.getpeername() - except socket.error: - # The addr isn't crucial - pass - else: - self.socket = None - - def __repr__(self): - status = [self.__class__.__module__+"."+self.__class__.__name__] - if self.accepting and self.addr: - status.append('listening') - elif self.connected: - status.append('connected') - if self.addr is not None: - try: - status.append('%s:%d' % self.addr) - except TypeError: - status.append(repr(self.addr)) - # On some systems (RH10) id() can be a negative number. - # work around this. - MAX = 2L*sys.maxint+1 - return '<%s at %#x>' % (' '.join(status), id(self)&MAX) - - def add_channel(self, map=None): - #self.log_info('adding channel %s' % self) - if map is None: - if hasattr(self, '_map'): - map = self._map - del self._map - else: - map = socket_map - if not hasattr(self, '_fileno'): - self._fileno = self.socket.fileno() - map[self._fileno] = self - - def del_channel(self, map=None): - fd = self._fileno - if map is None: - map = socket_map - if map.has_key(fd): - #self.log_info('closing channel %d:%s' % (fd, self)) - del map[fd] - - def create_socket(self, family, type): - self.family_and_type = family, type - self.socket = socket.socket(family, type) - self.socket.setblocking(0) - - def set_socket(self, sock, map=None): - self.socket = sock -## self.__dict__['socket'] = sock - if sock.fileno(): - self.add_channel(map) - else: - self._map = map - - def set_reuse_addr(self): - # try to re-use a server port if possible - try: - self.socket.setsockopt( - socket.SOL_SOCKET, socket.SO_REUSEADDR, - self.socket.getsockopt(socket.SOL_SOCKET, - socket.SO_REUSEADDR) | 1 - ) - except socket.error: - pass - - # ================================================== - # predicates for select() - # these are used as filters for the lists of sockets - # to pass to select(). - # ================================================== - - def readable(self): - return True - - if os.name == 'mac': - # The macintosh will select a listening socket for - # write if you let it. What might this mean? - def writable(self): - return not self.accepting - else: - def writable(self): - return True - - # ================================================== - # socket object methods. - # ================================================== - - def listen(self, num): - self.accepting = 1 - if os.name == 'nt' and num > 5: - num = 1 - ret = self.socket.listen(num) - self.add_channel() - return ret - - def bind(self, addr): - self.addr = addr - return self.socket.bind(addr) - - def connect(self, address): - self.connected = 0 - err = self.socket.connect_ex(address) - # XXX Should interpret Winsock return values - if err in (EINPROGRESS, EALREADY, EWOULDBLOCK): - return - if err in (0, EISCONN): - self.add_channel() - self.addr = address - self.connected = 1 - self.handle_connect() - else: - raise socket.error, err - - def accept(self): - # XXX can return either an address pair or None - try: - conn, addr = self.socket.accept() - self.add_channel() - return conn, addr - except socket.error, why: - if why[0] == EWOULDBLOCK: - pass - else: - raise socket.error, why - - def send(self, data): - try: - result = self.socket.send(data) - return result - except socket.error, why: - if why[0] == EWOULDBLOCK: - return 0 - else: - raise socket.error, why - return 0 - - def recv(self, buffer_size): - try: - data = self.socket.recv(buffer_size) - if not data: - # a closed connection is indicated by signaling - # a read condition, and having recv() return 0. - self.handle_close() - return '' - else: - return data - except socket.error, why: - # winsock sometimes throws ENOTCONN - if why[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN]: - self.handle_close() - return '' - else: - raise socket.error, why - - def close(self): - self.del_channel() - self.socket.close() - - # cheap inheritance, used to pass all other attribute - # references to the underlying socket object. - def __getattr__(self, attr): - return getattr(self.socket, attr) - - # log and log_info may be overridden to provide more sophisticated - # logging and warning methods. In general, log is for 'hit' logging - # and 'log_info' is for informational, warning and error logging. - - def log(self, message): - sys.stderr.write('log: %s\n' % str(message)) - - def log_info(self, message, type='info'): - if __debug__ or type != 'info': - print '%s: %s' % (type, message) - - def handle_read_event(self): - if self.accepting: - # for an accepting socket, getting a read implies - # that we are connected - if not self.connected: - self.connected = 1 - self.handle_accept() - elif not self.connected: - self.handle_connect() - self.connected = 1 - self.handle_read() - else: - self.handle_read() - - def handle_write_event(self): - # getting a write implies that we are connected - if not self.connected: - self.handle_connect() - self.connected = 1 - self.handle_write() - - def handle_expt_event(self): - self.handle_expt() - - def handle_error(self): - nil, t, v, tbinfo = compact_traceback() - - # sometimes a user repr method will crash. - try: - self_repr = repr(self) - except: - self_repr = '<__repr__(self) failed for object at %0x>' % id(self) - - self.log_info( - 'uncaptured python exception, closing channel %s (%s:%s %s)' % ( - self_repr, - t, - v, - tbinfo - ), - 'error' - ) - self.close() - - def handle_expt(self): - self.log_info('unhandled exception', 'warning') - - def handle_read(self): - self.log_info('unhandled read event', 'warning') - - def handle_write(self): - self.log_info('unhandled write event', 'warning') - - def handle_connect(self): - self.log_info('unhandled connect event', 'warning') - - def handle_accept(self): - self.log_info('unhandled accept event', 'warning') - - def handle_close(self): - self.log_info('unhandled close event', 'warning') - self.close() - -# --------------------------------------------------------------------------- -# adds simple buffered output capability, useful for simple clients. -# [for more sophisticated usage use asynchat.async_chat] -# --------------------------------------------------------------------------- - -class dispatcher_with_send(dispatcher): - - def __init__(self, sock=None): - dispatcher.__init__(self, sock) - self.out_buffer = '' - - def initiate_send(self): - num_sent = 0 - num_sent = dispatcher.send(self, self.out_buffer[:512]) - self.out_buffer = self.out_buffer[num_sent:] - - def handle_write(self): - self.initiate_send() - - def writable(self): - return (not self.connected) or len(self.out_buffer) - - def send(self, data): - if self.debug: - self.log_info('sending %s' % repr(data)) - self.out_buffer = self.out_buffer + data - self.initiate_send() - -# --------------------------------------------------------------------------- -# used for debugging. -# --------------------------------------------------------------------------- - -def compact_traceback(): - t, v, tb = sys.exc_info() - tbinfo = [] - assert tb # Must have a traceback - while tb: - tbinfo.append(( - tb.tb_frame.f_code.co_filename, - tb.tb_frame.f_code.co_name, - str(tb.tb_lineno) - )) - tb = tb.tb_next - - # just to be safe - del tb - - file, function, line = tbinfo[-1] - info = ' '.join(['[%s|%s|%s]' % x for x in tbinfo]) - return (file, function, line), t, v, info - -def close_all(map=None): - if map is None: - map = socket_map - for x in map.values(): - x.socket.close() - map.clear() - -# Asynchronous File I/O: -# -# After a little research (reading man pages on various unixen, and -# digging through the linux kernel), I've determined that select() -# isn't meant for doing asynchronous file i/o. -# Heartening, though - reading linux/mm/filemap.c shows that linux -# supports asynchronous read-ahead. So _MOST_ of the time, the data -# will be sitting in memory for us already when we go to read it. -# -# What other OS's (besides NT) support async file i/o? [VMS?] -# -# Regardless, this is useful for pipes, and stdin/stdout... - -if os.name == 'posix': - import fcntl - - class file_wrapper: - # here we override just enough to make a file - # look like a socket for the purposes of asyncore. - - def __init__(self, fd): - self.fd = fd - - def recv(self, *args): - return os.read(self.fd, *args) - - def send(self, *args): - return os.write(self.fd, *args) - - read = recv - write = send - - def close(self): - return os.close(self.fd) - - def fileno(self): - return self.fd - - class file_dispatcher(dispatcher): - - def __init__(self, fd): - dispatcher.__init__(self) - self.connected = 1 - # set it to non-blocking mode - flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0) - flags = flags | os.O_NONBLOCK - fcntl.fcntl(fd, fcntl.F_SETFL, flags) - self.set_file(fd) - - def set_file(self, fd): - self._fileno = fd - self.socket = file_wrapper(fd) - self.add_channel() Copied: branches/pbcvm/Lib/asyncore.py (from rev 6040, trunk/jython/Lib/asyncore.py) =================================================================== --- branches/pbcvm/Lib/asyncore.py (rev 0) +++ branches/pbcvm/Lib/asyncore.py 2009-02-24 04:57:56 UTC (rev 6044) @@ -0,0 +1,551 @@ +# -*- Mode: Python -*- +# Id: asyncore.py,v 2.51 2000/09/07 22:29:26 rushing Exp +# Author: Sam Rushing <ru...@ni...> + +# ====================================================================== +# Copyright 1996 by Sam Rushing +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and +# its documentation for any purpose and without fee is hereby +# granted, provided that the above copyright notice appear in all +# copies and that both that copyright notice and this permission +# notice appear in supporting documentation, and that the name of Sam +# Rushing not be used in advertising or publicity pertaining to +# distribution of the software without specific, written prior +# permission. +# +# SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN +# NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR +# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# ====================================================================== + +"""Basic infrastructure for asynchronous socket service clients and servers. + +There are only two ways to have a program on a single processor do "more +than one thing at a time". Multi-threaded programming is the simplest and +most popular way to do it, but there is another very different technique, +that lets you have nearly all the advantages of multi-threading, without +actually using multiple threads. it's really only practical if your program +is largely I/O bound. If your program is CPU bound, then pre-emptive +scheduled threads are probably what you really need. Network servers are +rarely CPU-bound, however. + +If your operating system supports the select() system call in its I/O +library (and nearly all do), then you can use it to juggle multiple +communication channels at once; doing other work while your I/O is taking +place in the "background." Although this strategy can seem strange and +complex, especially at first, it is in many ways easier to understand and +control than multi-threaded programming. The module documented here solves +many of the difficult problems for you, making the task of building +sophisticated high-performance network servers and clients a snap. +""" + +import select +import socket +import sys +import time + +import os +from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \ + ENOTCONN, ESHUTDOWN, EINTR, EISCONN, errorcode + +try: + socket_map +except NameError: + socket_map = {} + +class ExitNow(Exception): + pass + +def read(obj): + try: + obj.handle_read_event() + except ExitNow: + raise + except: + obj.handle_error() + +def write(obj): + try: + obj.handle_write_event() + except ExitNow: + raise + except: + obj.handle_error() + +def _exception (obj): + try: + obj.handle_expt_event() + except ExitNow: + raise + except: + obj.handle_error() + +def readwrite(obj, flags): + try: + if flags & (select.POLLIN | select.POLLPRI): + obj.handle_read_event() + if flags & select.POLLOUT: + obj.handle_write_event() + if flags & (select.POLLERR | select.POLLHUP | select.POLLNVAL): + obj.handle_expt_event() + except ExitNow: + raise + except: + obj.handle_error() + +def poll(timeout=0.0, map=None): + if map is None: + map = socket_map + if map: + r = []; w = []; e = [] + for fd, obj in map.items(): + is_r = obj.readable() + is_w = obj.writable() + if is_r: + r.append(fd) + if is_w: + w.append(fd) + if is_r or is_w: + e.append(fd) + if [] == r == w == e: + time.sleep(timeout) + else: + try: + r, w, e = select.select(r, w, e, timeout) + except select.error, err: + if err[0] != EINTR: + raise + else: + return + + for fd in r: + obj = map.get(fd) + if obj is None: + continue + read(obj) + + for fd in w: + obj = map.get(fd) + if obj is None: + continue + write(obj) + + for fd in e: + obj = map.get(fd) + if obj is None: + continue + _exception(obj) + +def poll2(timeout=0.0, map=None): + # Use the poll() support added to the select module in Python 2.0 + if map is None: + map = socket_map + if timeout is not None: + # timeout is in milliseconds + timeout = int(timeout*1000) + pollster = select.poll() + if map: + for fd, obj in map.items(): + flags = 0 + if obj.readable(): + flags |= select.POLLIN | select.POLLPRI + if obj.writable(): + flags |= select.POLLOUT + if flags: + # Only check for exceptions if object was either readable + # or writable. + flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL + pollster.register(fd, flags) + try: + r = pollster.poll(timeout) + except select.error, err: + if err[0] != EINTR: + raise + r = [] + for fd, flags in r: + obj = map.get(fd) + if obj is None: + continue + readwrite(obj, flags) + +poll3 = poll2 # Alias for backward compatibility + +def loop(timeout=30.0, use_poll=True, map=None, count=None): + if map is None: + map = socket_map + + if use_poll and hasattr(select, 'poll'): + poll_fun = poll2 + else: + poll_fun = poll + + if count is None: + while map: + poll_fun(timeout, map) + + else: + while map and count > 0: + poll_fun(timeout, map) + count = count - 1 + +class dispatcher: + + debug = False + connected = False + accepting = False + closing = False + addr = None + + def __init__(self, sock=None, map=None): + if map is None: + self._map = socket_map + else: + self._map = map + + if sock: + self.set_socket(sock, map) + # I think it should inherit this anyway + self.socket.setblocking(0) + self.connected = True + # XXX Does the constructor require that the socket passed + # be connected? + try: + self.addr = sock.getpeername() + except socket.error: + # The addr isn't crucial + pass + else: + self.socket = None + + def __repr__(self): + status = [self.__class__.__module__+"."+self.__class__.__name__] + if self.accepting and self.addr: + status.append('listening') + elif self.connected: + status.append('connected') + if self.addr is not None: + try: + status.append('%s:%d' % self.addr) + except TypeError: + status.append(repr(self.addr)) + return '<%s at %#x>' % (' '.join(status), id(self)) + + def add_channel(self, map=None): + #self.log_info('adding channel %s' % self) + if map is None: + map = self._map + map[self._fileno] = self + + def del_channel(self, map=None): + fd = self._fileno + if map is None: + map = self._map + if map.has_key(fd): + #self.log_info('closing channel %d:%s' % (fd, self)) + del map[fd] + self._fileno = None + + def create_socket(self, family, type): + self.family_and_type = family, type + self.socket = socket.socket(family, type) + self.socket.setblocking(0) + self._fileno = self.socket + self.add_channel() + + def set_socket(self, sock, map=None): + self.socket = sock +## self.__dict__['socket'] = sock + self._fileno = sock + self.add_channel(map) + + def set_reuse_addr(self): + # try to re-use a server port if possible + try: + self.socket.setsockopt( + socket.SOL_SOCKET, socket.SO_REUSEADDR, + self.socket.getsockopt(socket.SOL_SOCKET, + socket.SO_REUSEADDR) | 1 + ) + except socket.error: + pass + + # ================================================== + # predicates for select() + # these are used as filters for the lists of sockets + # to pass to select(). + # ================================================== + + def readable(self): + return True + + def writable(self): + return True + + # ================================================== + # socket object methods. + # ================================================== + + def listen(self, num): + self.accepting = True + if os.name == 'nt' and num > 5: + num = 1 + return self.socket.listen(num) + + def bind(self, addr): + self.addr = addr + return self.socket.bind(addr) + + def connect(self, address): + self.connected = False + err = self.socket.connect_ex(address) + # XXX Should interpret Winsock return values + if err in (EINPROGRESS, EALREADY, EWOULDBLOCK): + return + if err in (0, EISCONN): + self.addr = address + self.connected = True + self.handle_connect() + else: + raise socket.error, (err, errorcode[err]) + + def accept(self): + # XXX can return either an address pair or None + try: + conn, addr = self.socket.accept() + return conn, addr + except socket.error, why: + if why[0] == EWOULDBLOCK: + pass + else: + raise + + def send(self, data): + try: + result = self.socket.send(data) + return result + except socket.error, why: + if why[0] == EWOULDBLOCK: + return 0 + else: + raise + return 0 + + def recv(self, buffer_size): + try: + data = self.socket.recv(buffer_size) + if not data: + # a closed connection is indicated by signaling + # a read condition, and having recv() return 0. + self.handle_close() + return '' + else: + return data + except socket.error, why: + # winsock sometimes throws ENOTCONN + if why[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN]: + self.handle_close() + return '' + else: + raise + + def close(self): + self.del_channel() + self.socket.close() + + # cheap inheritance, used to pass all other attribute + # references to the underlying socket object. + def __getattr__(self, attr): + return getattr(self.socket, attr) + + # log and log_info may be overridden to provide more sophisticated + # logging and warning methods. In general, log is for 'hit' logging + # and 'log_info' is for informational, warning and error logging. + + def log(self, message): + sys.stderr.write('log: %s\n' % str(message)) + + def log_info(self, message, type='info'): + if __debug__ or type != 'info': + print '%s: %s' % (type, message) + + def handle_read_event(self): + if self.accepting: + # for an accepting socket, getting a read implies + # that we are connected + if not self.connected: + self.connected = True + self.handle_accept() + elif not self.connected: + self.handle_connect() + self.connected = True + self.handle_read() + else: + self.handle_read() + + def handle_write_event(self): + # getting a write implies that we are connected + if not self.connected: + self.handle_connect() + self.connected = True + self.handle_write() + + def handle_expt_event(self): + self.handle_expt() + + def handle_error(self): + nil, t, v, tbinfo = compact_traceback() + + # sometimes a user repr method will crash. + try: + self_repr = repr(self) + except: + self_repr = '<__repr__(self) failed for object at %0x>' % id(self) + + self.log_info( + 'uncaptured python exception, closing channel %s (%s:%s %s)' % ( + self_repr, + t, + v, + tbinfo + ), + 'error' + ) + self.close() + + def handle_expt(self): + self.log_info('unhandled exception', 'warning') + + def handle_read(self): + self.log_info('unhandled read event', 'warning') + + def handle_write(self): + self.log_info('unhandled write event', 'warning') + + def handle_connect(self): + self.log_info('unhandled connect event', 'warning') + + def handle_accept(self): + self.log_info('unhandled accept event', 'warning') + + def handle_close(self): + self.log_info('unhandled close event', 'warning') + self.close() + +# --------------------------------------------------------------------------- +# adds simple buffered output capability, useful for simple clients. +# [for more sophisticated usage use asynchat.async_chat] +# --------------------------------------------------------------------------- + +class dispatcher_with_send(dispatcher): + + def __init__(self, sock=None, map=None): + dispatcher.__init__(self, sock, map) + self.out_buffer = '' + + def initiate_send(self): + num_sent = 0 + num_sent = dispatcher.send(self, self.out_buffer[:512]) + self.out_buffer = self.out_buffer[num_sent:] + + def handle_write(self): + self.initiate_send() + + def writable(self): + return (not self.connected) or len(self.out_buffer) + + def send(self, data): + if self.debug: + self.log_info('sending %s' % repr(data)) + self.out_buffer = self.out_buffer + data + self.initiate_send() + +# --------------------------------------------------------------------------- +# used for debugging. +# --------------------------------------------------------------------------- + +def compact_traceback(): + t, v, tb = sys.exc_info() + tbinfo = [] + assert tb # Must have a traceback + while tb: + tbinfo.append(( + tb.tb_frame.f_code.co_filename, + tb.tb_frame.f_code.co_name, + str(tb.tb_lineno) + )) + tb = tb.tb_next + + # just to be safe + del tb + + file, function, line = tbinfo[-1] + info = ' '.join(['[%s|%s|%s]' % x for x in tbinfo]) + return (file, function, line), t, v, info + +def close_all(map=None): + if map is None: + map = socket_map + for x in map.values(): + x.socket.close() + map.clear() + +# Asynchronous File I/O: +# +# After a little research (reading man pages on various unixen, and +# digging through the linux kernel), I've determined that select() +# isn't meant for doing asynchronous file i/o. +# Heartening, though - reading linux/mm/filemap.c shows that linux +# supports asynchronous read-ahead. So _MOST_ of the time, the data +# will be sitting in memory for us already when we go to read it. +# +# What other OS's (besides NT) support async file i/o? [VMS?] +# +# Regardless, this is useful for pipes, and stdin/stdout... + +if os.name == 'posix': + import fcntl + + class file_wrapper: + # here we override just enough to make a file + # look like a socket for the purposes of asyncore. + + def __init__(self, fd): + self.fd = fd + + def recv(self, *args): + return os.read(self.fd, *args) + + def send(self, *args): + return os.write(self.fd, *args) + + read = recv + write = send + + def close(self): + os.close(self.fd) + + def fileno(self): + return self.fd + + class file_dispatcher(dispatcher): + + def __init__(self, fd, map=None): + dispatcher.__init__(self, None, map) + self.connected = True + self.set_file(fd) + # set it to non-blocking mode + flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0) + flags = flags | os.O_NONBLOCK + fcntl.fcntl(fd, fcntl.F_SETFL, flags) + + def set_file(self, fd): + self._fileno = fd + self.socket = file_wrapper(fd) + self.add_channel() Modified: branches/pbcvm/Lib/os.py =================================================================== --- branches/pbcvm/Lib/os.py 2009-02-24 04:37:39 UTC (rev 6043) +++ branches/pbcvm/Lib/os.py 2009-02-24 04:57:56 UTC (rev 6044) @@ -30,8 +30,8 @@ 'O_RDWR', 'O_SYNC', 'O_TRUNC', 'O_WRONLY', 'R_OK', 'SEEK_CUR', 'SEEK_END', 'SEEK_SET', 'W_OK', 'X_OK', '_exit', 'access', 'altsep', 'chdir', 'chmod', 'close', 'curdir', 'defpath', - 'environ', 'error', 'fdopen', 'getcwd', 'getegid', 'getenv', - 'geteuid', 'getgid', 'getlogin', 'getlogin', 'getpgrp', + 'environ', 'error', 'fdopen', 'getcwd', 'getcwdu', 'getegid', + 'getenv','geteuid', 'getgid', 'getlogin', 'getlogin', 'getpgrp', 'getpid', 'getppid', 'getuid', 'isatty', 'linesep', 'listdir', 'lseek', 'lstat', 'makedirs', 'mkdir', 'name', 'open', 'pardir', 'path', 'pathsep', 'popen', 'popen2', 'popen3', 'popen4', @@ -83,9 +83,9 @@ """ os_name = sys.registry.getProperty('python.os') if os_name: - return str(os_name) + return asPyString(os_name) - os_name = str(java.lang.System.getProperty('os.name')) + os_name = asPyString(java.lang.System.getProperty('os.name')) os_type = None for type, (patterns, shell_commands) in _os_map.iteritems(): for pattern in patterns: @@ -118,7 +118,7 @@ def isVerbose(self): return False def getCurrentWorkingDirectory(self): - return File(getcwd()) + return File(getcwdu()) def getEnv(self): return ['%s=%s' % (key, val) for key, val in environ.iteritems()] def getInputStream(self): @@ -251,6 +251,13 @@ """ return asPyString(sys.getCurrentWorkingDir()) +def getcwdu(): + """getcwd() -> path + + Return a unicode string representing the current working directory. + """ + return sys.getCurrentWorkingDir() + def chdir(path): """chdir(path) Modified: branches/pbcvm/Lib/platform.py =================================================================== --- branches/pbcvm/Lib/platform.py 2009-02-24 04:37:39 UTC (rev 6043) +++ branches/pbcvm/Lib/platform.py 2009-02-24 04:57:56 UTC (rev 6044) @@ -624,8 +624,9 @@ def _java_getprop(name,default): from java.lang import System + from org.python.core.Py import newString try: - return System.getProperty(name) + return newString(System.getProperty(name)) except: return default @@ -793,7 +794,7 @@ filepath = _abspath(filepath) while os.path.islink(filepath): filepath = os.path.normpath( - os.path.join(filepath,os.readlink(filepath))) + os.path.join(os.path.dirname(filepath),os.readlink(filepath))) return filepath def _syscmd_uname(option,default=''): Modified: branches/pbcvm/Lib/pydoc.py =================================================================== --- branches/pbcvm/Lib/pydoc.py 2009-02-24 04:37:39 UTC (rev 6043) +++ branches/pbcvm/Lib/pydoc.py 2009-02-24 04:57:56 UTC (rev 6044) @@ -1959,13 +1959,17 @@ self.callback = callback self.base.__init__(self, self.address, self.handler) - def serve_until_quit(self): - import select - self.quit = False - while not self.quit: - rd, wr, ex = select.select([self.socket.fileno()], [], [], 1) - if rd: self.handle_request() - + def serve_until_quit(self): + import sys + if sys.platform.startswith('java'): + from select import cpython_compatible_select as select + else: + from select import select + self.quit = False + while not self.quit: + rd, wr, ex = select([self.socket], [], [], 1) + if rd: self.handle_request() + def server_activate(self): self.base.server_activate(self) if self.callback: self.callback(self) @@ -1976,7 +1980,7 @@ try: try: DocServer(port, callback).serve_until_quit() - except (KeyboardInterrupt, select.error): + except (KeyboardInterrupt, select.error): pass finally: if completer: completer() Modified: branches/pbcvm/Lib/socket.py =================================================================== --- branches/pbcvm/Lib/socket.py 2009-02-24 04:37:39 UTC (rev 6043) +++ branches/pbcvm/Lib/socket.py 2009-02-24 04:57:56 UTC (rev 6044) @@ -248,22 +248,6 @@ def close(self): self.jsocket.close() - def shutdownInput(self): - try: - self.jsocket.shutdownInput() - except AttributeError, ax: - pass # Fail silently server sockets - except java.lang.Exception, jlx: - raise _map_exception(jlx) - - def shutdownOutput(self): - try: - self.jsocket.shutdownOutput() - except AttributeError, ax: - pass # Fail silently server sockets - except java.lang.Exception, jlx: - raise _map_exception(jlx) - def getchannel(self): return self.jchannel @@ -340,6 +324,12 @@ else: return self._do_write_nio(buf) + def shutdown(self, how): + if how in (SHUT_RD, SHUT_RDWR): + self.jsocket.shutdownInput() + if how in (SHUT_WR, SHUT_RDWR): + self.jsocket.shutdownOutput() + class _server_socket_impl(_nio_impl): options = { @@ -371,6 +361,13 @@ new_cli_sock = self.jsocket.accept() return _client_socket_impl(new_cli_sock) + def shutdown(self, how): + # This is no-op on java, for server sockets. + # What the user wants to achieve is achieved by calling close() on + # java/jython. But we can't call that here because that would then + # later cause the user explicit close() call to fail + pass + class _datagram_socket_impl(_nio_impl): options = { @@ -384,7 +381,7 @@ def __init__(self, port=None, address=None, reuse_addr=0): self.jchannel = java.nio.channels.DatagramChannel.open() self.jsocket = self.jchannel.socket() - if port: + if port is not None: if address is not None: local_address = java.net.InetSocketAddress(address, port) else: @@ -406,6 +403,13 @@ """ self.jchannel.disconnect() + def shutdown(self, how): + # This is no-op on java, for datagram sockets. + # What the user wants to achieve is achieved by calling close() on + # java/jython. But we can't call that here because that would then + # later cause the user explicit close() call to fail + pass + def _do_send_net(self, byte_array, socket_address, flags): # Need two separate implementations because the java.nio APIs do not support timeouts num_bytes = len(byte_array) @@ -689,6 +693,22 @@ except java.lang.Exception, jlx: raise _map_exception(jlx) + def shutdown(self, how): + assert how in (SHUT_RD, SHUT_WR, SHUT_RDWR) + if not self.sock_impl: + raise error(errno.ENOTCONN, "Transport endpoint is not connected") + try: + self.sock_impl.shutdown(how) + except java.lang.Exception, jlx: + raise _map_exception(jlx) + + def close(self): + try: + if self.sock_impl: + self.sock_impl.close() + except java.lang.Exception, jlx: + raise _map_exception(jlx) + def _config(self): assert self.mode in _permitted_modes if self.sock_impl: @@ -878,15 +898,6 @@ except java.lang.Exception, jlx: raise _map_exception(jlx) - def shutdown(self, how): - if not self.sock_impl: - raise error(errno.ENOTCONN, "Transport endpoint is not connected") - assert how in (SHUT_RD, SHUT_WR, SHUT_RDWR) - if how in (SHUT_RD, SHUT_RDWR): - self.sock_impl.shutdownInput() - if how in (SHUT_WR, SHUT_RDWR): - self.sock_impl.shutdownOutput() - def close(self): try: if self.istream: @@ -1015,13 +1026,6 @@ def __del__(self): self.close() - def close(self): - try: - if self.sock_impl: - self.sock_impl.close() - except java.lang.Exception, jlx: - raise _map_exception(jlx) - _socketmethods = ( 'bind', 'connect', 'connect_ex', 'fileno', 'listen', 'getpeername', 'getsockname', 'getsockopt', 'setsockopt', Copied: branches/pbcvm/Lib/test/bug1239.jar (from rev 6040, trunk/jython/Lib/test/bug1239.jar) =================================================================== (Binary files differ) Copied: branches/pbcvm/Lib/test/check_for_initializer_in_syspath.py (from rev 6040, trunk/jython/Lib/test/check_for_initializer_in_syspath.py) =================================================================== --- branches/pbcvm/Lib/test/check_for_initializer_in_syspath.py (rev 0) +++ branches/pbcvm/Lib/test/check_for_initializer_in_syspath.py 2009-02-24 04:57:56 UTC (rev 6044) @@ -0,0 +1,2 @@ +import sys +assert "/from_SyspathAppendingInitializer_with_love" in sys.path Copied: branches/pbcvm/Lib/test/import_star_from_java.py (from rev 6040, trunk/jython/Lib/test/import_star_from_java.py) =================================================================== --- branches/pbcvm/Lib/te... [truncated message content] |