[Checkins] SVN: zc.ngi/trunk/ Ignore egg files.
Jim Fulton
jim at zope.com
Thu Jul 8 07:58:30 EDT 2010
Log message for revision 114324:
Ignore egg files.
Changed:
_U zc.ngi/trunk/
U zc.ngi/trunk/README.txt
U zc.ngi/trunk/src/zc/ngi/adapters.py
U zc.ngi/trunk/src/zc/ngi/async.py
U zc.ngi/trunk/src/zc/ngi/async.test
U zc.ngi/trunk/src/zc/ngi/blocking.py
U zc.ngi/trunk/src/zc/ngi/doc/echo_server.py
U zc.ngi/trunk/src/zc/ngi/doc/index.txt
U zc.ngi/trunk/src/zc/ngi/doc/reference.txt
U zc.ngi/trunk/src/zc/ngi/generator.py
U zc.ngi/trunk/src/zc/ngi/interfaces.py
U zc.ngi/trunk/src/zc/ngi/message.py
U zc.ngi/trunk/src/zc/ngi/message.test
U zc.ngi/trunk/src/zc/ngi/old.test
U zc.ngi/trunk/src/zc/ngi/testing.py
U zc.ngi/trunk/src/zc/ngi/testing.test
U zc.ngi/trunk/src/zc/ngi/tests.py
U zc.ngi/trunk/src/zc/ngi/wordcount.py
-=-
Property changes on: zc.ngi/trunk
___________________________________________________________________
Modified: svn:ignore
- develop-eggs
documentation.txt
bin
parts
+ develop-eggs
documentation.txt
bin
parts
*.egg
Modified: zc.ngi/trunk/README.txt
===================================================================
--- zc.ngi/trunk/README.txt 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/README.txt 2010-07-08 11:58:29 UTC (rev 114324)
@@ -19,9 +19,9 @@
Changes
*******
-==================
-1.2.0 (2010-07-??)
-==================
+====================
+2.0.0a1 (2010-07-??)
+====================
New Features:
@@ -40,6 +40,8 @@
connections and with handlers that tend to perform long-lating
computations that would be unacceptable with a single select loop.
+- Renamed IConnection.setHandler to set_handler.
+
- Dropped support for Python 2.4.
Bugs Fixed:
Modified: zc.ngi/trunk/src/zc/ngi/adapters.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/adapters.py 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/adapters.py 2010-07-08 11:58:29 UTC (rev 114324)
@@ -14,6 +14,7 @@
"""NGI connection adapters
"""
import struct
+import warnings
import zc.ngi.generator
class Base(object):
@@ -32,10 +33,20 @@
self.writelines = self.connection.writelines
self.writelines(data)
- def setHandler(self, handler):
+ def set_handler(self, handler):
self.handler = handler
- self.connection.setHandler(self)
+ try:
+ self.connection.set_handler(self)
+ except AttributeError:
+ self.connection.setHandler(self)
+ warnings.warn("setHandler is deprecated. Use set_handler,",
+ DeprecationWarning, stacklevel=2)
+ def setHandler(self, handler):
+ warnings.warn("setHandler is deprecated. Use set_handler,",
+ DeprecationWarning, stacklevel=2)
+ self.set_handler(handler)
+
def handle_input(self, connection, data):
handle_input = self.handler.handle_input
self.handle_input(connection, data)
@@ -67,9 +78,10 @@
want = 4
got = 0
getting_size = True
- def setHandler(self, handler):
+
+ def set_handler(self, handler):
self.input = []
- Base.setHandler(self, handler)
+ Base.set_handler(self, handler)
def handle_input(self, connection, data):
self.got += len(data)
Modified: zc.ngi/trunk/src/zc/ngi/async.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/async.py 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/async.py 2010-07-08 11:58:29 UTC (rev 114324)
@@ -23,6 +23,7 @@
import sys
import threading
import time
+import warnings
import zc.ngi
import zc.ngi.interfaces
@@ -225,7 +226,7 @@
def __nonzero__(self):
return self.__connected
- def setHandler(self, handler):
+ def set_handler(self, handler):
if self.__handler is not None:
raise TypeError("Handler already set")
@@ -247,6 +248,11 @@
self.__closed)
raise
+ def setHandler(self, handler):
+ warnings.warn("setHandler is deprecated. Use set_handler,",
+ DeprecationWarning, stacklevel=2)
+ self.set_handler(handler)
+
def write(self, data):
if __debug__:
self.logger.debug('write %r', data)
@@ -367,7 +373,10 @@
def handle_expt(self):
self.handle_close('socket error')
+ def __hash__(self):
+ return hash(self.socket)
+
class _ServerConnection(_Connection):
zc.ngi.interfaces.implements(zc.ngi.interfaces.IServerConnection)
@@ -632,7 +641,7 @@
self.implementation.notify_select()
def handle_read(self):
- message, addr = self.recvfrom(self.__buffer_size)
+ message, addr = self.socket.recvfrom(self.__buffer_size)
self.__handler(addr, message)
def close(self):
@@ -676,7 +685,7 @@
r, self.__writefd = os.pipe()
asyncore.file_dispatcher.__init__(self, r, map)
- if self.fd != r:
+ if self.socket.fd != r:
# Starting in Python 2.6, the descriptor passed to
# file_dispatcher gets duped and assigned to
# self.fd. This breaks the instantiation semantics and
Modified: zc.ngi/trunk/src/zc/ngi/async.test
===================================================================
--- zc.ngi/trunk/src/zc/ngi/async.test 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/async.test 2010-07-08 11:58:29 UTC (rev 114324)
@@ -124,7 +124,7 @@
>>> event = threading.Event()
>>> class LameClientConnectionHandler:
... def connected(self, connection):
- ... connection.setHandler(self)
+ ... connection.set_handler(self)
... raise ValueError('Broken connector')
... def handle_close(self, conection, reason):
... self.closed = reason
@@ -147,7 +147,7 @@
>>> class LameClientConnectionHandler:
... def connected(self, connection):
- ... connection.setHandler(self)
+ ... connection.set_handler(self)
... connection.write('foo\0')
...
... def handle_input(self, data):
Modified: zc.ngi/trunk/src/zc/ngi/blocking.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/blocking.py 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/blocking.py 2010-07-08 11:58:29 UTC (rev 114324)
@@ -15,8 +15,13 @@
import sys
import threading
import time
+import warnings
import zc.ngi
+import zc.ngi.adapters
+warnings.warn("The blocking module is deprecated.",
+ DeprecationWarning, stacklevel=2)
+
class Timeout(Exception):
"""An operation timed out.
"""
@@ -25,29 +30,17 @@
"""An attempt to connect timed out.
"""
-class RequestConnection:
+class RequestConnection(zc.ngi.adapters.Base):
def __init__(self, connection, connector):
self.connection = connection
self.connector = connector
- def write(self, data):
- self.write = self.connection.write
- self.write(data)
-
- def writelines(self, data):
- self.writelines = self.connection.writelines
- self.writelines(data)
-
def close(self):
self.connector.closed = True
self.connection.close()
self.connector.event.set()
- def setHandler(self, handler):
- self.handler = handler
- self.connection.setHandler(self)
-
def handle_input(self, connection, data):
try:
self.handler.handle_input(self, data)
@@ -82,7 +75,6 @@
raise
return handle_exception
-
class RequestConnector:
exception = closed = connection = result = None
@@ -96,7 +88,7 @@
elif getattr(handler, 'handle_input', None) is None:
raise
else:
- connected = lambda connection: connection.setHandler(handler)
+ connected = lambda connection: connection.set_handler(handler)
self._connected = connected
self.event = event
@@ -163,7 +155,9 @@
self.event.set()
def open(connection_or_address, connector=None, timeout=None):
- if connector is None and hasattr(connection_or_address, 'setHandler'):
+ if connector is None and (hasattr(connection_or_address, 'set_handler')
+ or hasattr(connection_or_address, 'setHandler')
+ ):
# connection_or_address is a connection
connection = connection_or_address
else:
@@ -271,7 +265,7 @@
self._data = ''
self._outputfile = outputfile
self._outputfile._exception = None
- connection.setHandler(self)
+ connection.set_handler(self)
def invalid_method(*args, **kw):
raise IOError("Invalid operation on output file")
Modified: zc.ngi/trunk/src/zc/ngi/doc/echo_server.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/doc/echo_server.py 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/doc/echo_server.py 2010-07-08 11:58:29 UTC (rev 114324)
@@ -15,7 +15,7 @@
print 'oops', exception
def echo_server(connection):
- connection.setHandler(Echo())
+ connection.set_handler(Echo())
def main(args=None):
if args is None:
Modified: zc.ngi/trunk/src/zc/ngi/doc/index.txt
===================================================================
--- zc.ngi/trunk/src/zc/ngi/doc/index.txt 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/doc/index.txt 2010-07-08 11:58:29 UTC (rev 114324)
@@ -304,6 +304,8 @@
handler, it is blocked from handling other network events until the
handler returns.
+.. _async_threads:
+
``zc.ngi.async`` implementations and threading
----------------------------------------------
Modified: zc.ngi/trunk/src/zc/ngi/doc/reference.txt
===================================================================
--- zc.ngi/trunk/src/zc/ngi/doc/reference.txt 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/doc/reference.txt 2010-07-08 11:58:29 UTC (rev 114324)
@@ -99,7 +99,7 @@
connection = zc.ngi.testing.Connection()
My default, test connections have handlers that write data to
- standard output. You can change their handlers using setHandler.
+ standard output. You can change their handlers using set_handler.
.. attribute:: peer
@@ -135,17 +135,5 @@
<zc.ngi.interfaces.IListener.address>` attribute. This is mainly
useful for testing,
-The async implementation manages thread for performing network IO.
-This thread is started implicitly when an :class:`implementation
-<zc.ngi.interfaces.IImplementation>` method is called. It may be
-started explicitly using the :func:`start_thread` function.
-
-.. function:: start_thread(daemon=True)
-
- If the async thread hasn't started yet, then start the thread using
- the given daemon mode.
-
- For long-running applications, such as servers, using a
- non-daemonic thread will keep the process going even after the main
- thread completes, freeing the application programmer from needing
- to maintain the main thread.
+The ``zc.ngi.async`` modules provides a number of threading modes. See
+:ref:`async_threads`.
Modified: zc.ngi/trunk/src/zc/ngi/generator.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/generator.py 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/generator.py 2010-07-08 11:58:29 UTC (rev 114324)
@@ -11,6 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
+import warnings
import zc.ngi.interfaces
def handler(func=None, connection_adapter=None):
@@ -47,7 +48,8 @@
ConnectionHandler(self.func(inst, connection), connection)
)
- connected = __call__
+ def connected(self, connection):
+ self(connection)
def failed_connect(self, reason):
raise zc.ngi.interfaces.ConnectionFailed(reason)
@@ -62,7 +64,12 @@
return
self.gen = gen
- connection.setHandler(self)
+ try:
+ connection.set_handler(self)
+ except AttributeError:
+ self.connection.setHandler(self)
+ warnings.warn("setHandler is deprecated. Use set_handler,",
+ DeprecationWarning, stacklevel=2)
def handle_input(self, connection, data):
try:
Modified: zc.ngi/trunk/src/zc/ngi/interfaces.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/interfaces.py 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/interfaces.py 2010-07-08 11:58:29 UTC (rev 114324)
@@ -32,12 +32,12 @@
def connect(address, handler):
"""Try to make a connection to the given address
- The handler is an IClientConnectHandler. The handler
- connected method will be called with an IConnection object
- if and when the connection succeeds or failed_connect method
+ The handler is an ``IClientConnectHandler``. The handler
+ ``connected`` method will be called with an ``IConnection`` object
+ if and when the connection succeeds or ``failed_connect`` method
will be called if the connection fails.
- This method os thread safe. It may be called by any thread at
+ This method is thread safe. It may be called by any thread at
any time.
"""
@@ -46,9 +46,9 @@
When a connection is received, call the handler.
- An IListener object is returned.
+ An ``IListener`` object is returned.
- This method os thread safe. It may be called by any thread at
+ This method is thread safe. It may be called by any thread at
any time.
"""
@@ -64,9 +64,9 @@
When a message is received, call the handler with the message.
- An IUDPListener object is returned.
+ An ``IUDPListener`` object is returned.
- This method os thread safe. It may be called by any thread at
+ This method is thread safe. It may be called by any thread at
any time.
"""
@@ -87,16 +87,18 @@
False otherwise.
"""
- def setHandler(handler):
- """Set the IConnectionHandler for a connection.
+ def set_handler(handler):
+ """Set the ``IConnectionHandler`` for a connection.
- This method can only be called in direct response to an
- implementation call to a IConnectionHandler,
- IClientConnectHandler, or IServer.
+ This method may be called multiple times, but it should only
+ be called in direct response to an implementation call to a
+ ``IConnectionHandler``, ``IClientConnectHandler``, or
+ ``IServer``.
Any failure of a handler call must be caught and logged. If
- an exception is raised by a call to hande_input or
- handle_exception, the connection must be closed.
+ an exception is raised by a call to ``hande_input`` or
+ ``handle_exception``, the connection must be closed by the
+ implementation.
"""
def write(data):
@@ -104,24 +106,24 @@
The write call is non-blocking.
- This method os thread safe. It may be called by any thread at
+ This method is thread safe. It may be called by any thread at
any time.
"""
def writelines(data):
"""Output an iterable of strings to the connection.
- The writelines call is non-blocking. Note, that the data may
+ The ``writelines`` call is non-blocking. Note, that the data may
not have been consumed when the method returns.
- This method os thread safe. It may be called by any thread at
+ This method is thread safe. It may be called by any thread at
any time.
"""
def close():
"""Close the connection
- This method os thread safe. It may be called by any thread at
+ This method is thread safe. It may be called by any thread at
any time.
"""
@@ -173,9 +175,9 @@
"""Recieve a report of an exception encountered by a connection
This method is used to recieve exceptions from an NGI
- implementation. Typically, this will be due to an error
- encounted processing data passed to the connection write or
- writelines methods.
+ implementation. This will only be due to an error
+ encounted processing data passed to the connection
+ ``writelines`` methods.
"""
class IClientConnectHandler(Interface):
@@ -200,6 +202,9 @@
"""Handle server connections
This is an application interface.
+
+ A server is just a callable that takes a connection and set's it's
+ handler.
"""
def __call__(connection):
@@ -211,6 +216,9 @@
"""Handle udp messages
This is an application interface.
+
+ A UDP handler is a callable that takes a client address and an
+ 8-bit string message.
"""
def __call__(addr, data):
Modified: zc.ngi/trunk/src/zc/ngi/message.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/message.py 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/message.py 2010-07-08 11:58:29 UTC (rev 114324)
@@ -12,11 +12,10 @@
#
##############################################################################
"""Sample client that sends a single message and waits for a reply
-
-$Id$
"""
import threading
+import warnings
class CouldNotConnect(Exception):
"""Could not connect to a server
@@ -35,7 +34,7 @@
self.input = ''
def connected(self, connection):
- connection.setHandler(self)
+ connection.set_handler(self)
connection.write(self.message)
def failed_connect(self, reason):
Modified: zc.ngi/trunk/src/zc/ngi/message.test
===================================================================
--- zc.ngi/trunk/src/zc/ngi/message.test 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/message.test 2010-07-08 11:58:29 UTC (rev 114324)
@@ -10,7 +10,7 @@
...
... def __init__(self, connection):
... self.input = ''
- ... connection.setHandler(self)
+ ... connection.set_handler(self)
...
... def handle_input(self, connection, data):
... self.input += data
Modified: zc.ngi/trunk/src/zc/ngi/old.test
===================================================================
--- zc.ngi/trunk/src/zc/ngi/old.test 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/old.test 2010-07-08 11:58:29 UTC (rev 114324)
@@ -86,7 +86,7 @@
... for s in self.strings:
... connection.write(s + '\n')
... self.input = ''
- ... connection.setHandler(self)
+ ... connection.set_handler(self)
...
... def failed_connect(self, reason):
... print 'failed connect:', reason
@@ -209,7 +209,7 @@
>>> def bad():
... yield 2
>>> connection = zc.ngi.testing.Connection()
- >>> connection.setHandler(zc.ngi.testing.PrintingHandler(connection))
+ >>> connection.set_handler(zc.ngi.testing.PrintingHandler(connection))
>>> connection.writelines(bad())
-> EXCEPTION TypeError Got a non-string result from iterable
@@ -227,7 +227,7 @@
... def __init__(self, connection):
... print 'server connected'
... self.input = ''
- ... connection.setHandler(self)
+ ... connection.set_handler(self)
...
... def handle_input(self, connection, data):
... print 'server got input:', repr(data)
Modified: zc.ngi/trunk/src/zc/ngi/testing.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/testing.py 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/testing.py 2010-07-08 11:58:29 UTC (rev 114324)
@@ -16,6 +16,7 @@
import sys
import traceback
+import warnings
import zc.ngi
import zc.ngi.interfaces
@@ -24,7 +25,7 @@
class PrintingHandler:
def __init__(self, connection):
- connection.setHandler(self)
+ connection.set_handler(self)
def handle_input(self, connection, data):
data = repr(data)
@@ -108,7 +109,7 @@
raise TypeError("Connection closed")
self.write = write
- def setHandler(self, handler):
+ def set_handler(self, handler):
self.handler = handler
if self.exception:
exception = self.exception
@@ -123,6 +124,11 @@
if self.closed and isinstance(self.closed, str):
self._callHandler('handle_close', self.closed)
+ def setHandler(self, handler):
+ warnings.warn("setHandler is deprecated. Use set_handler,",
+ DeprecationWarning, stacklevel=2)
+ self.set_handler(handler)
+
def test_input(self, data):
if self.handler is not None:
self._callHandler('handle_input', data)
Modified: zc.ngi/trunk/src/zc/ngi/testing.test
===================================================================
--- zc.ngi/trunk/src/zc/ngi/testing.test 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/testing.test 2010-07-08 11:58:29 UTC (rev 114324)
@@ -11,7 +11,7 @@
... self.state = 'i'
... self.who = who
... self.connection = connection
- ... connection.setHandler(self)
+ ... connection.set_handler(self)
...
... def handle_input(self, connection, data):
... print self.who, self.state, 'got:', data
Modified: zc.ngi/trunk/src/zc/ngi/tests.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/tests.py 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/tests.py 2010-07-08 11:58:29 UTC (rev 114324)
@@ -11,6 +11,8 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
+from __future__ import with_statement
+
import doctest
import logging
import manuel.capture
@@ -26,13 +28,26 @@
import zc.ngi.testing
import zc.ngi.wordcount
+def blocking_warns():
+ """
+ >>> assert_(len(blocking_warnings) == 1)
+ >>> assert_(blocking_warnings[-1].category is DeprecationWarning)
+ >>> print blocking_warnings[-1].message
+ The blocking module is deprecated.
+ """
+
if sys.version_info >= (2, 6):
# silence blocking deprecation warning
- with warnings.catch_warnings(record=True):
+ with warnings.catch_warnings(record=True) as blocking_warnings:
+ warnings.simplefilter('default')
# omg, without record=True, warnings aren't actually caught.
# Who thinks up this stuff?
import zc.ngi.blocking
+else:
+ del blocking_warns
+
+
def test_async_cannot_connect():
"""Let's make sure that the connector handles connection failures correctly
@@ -378,6 +393,7 @@
>>> conn = zc.ngi.testing.Connection()
>>> with warnings.catch_warnings(record=True) as caught:
+ ... warnings.simplefilter('default')
... conn.setHandler(Handler())
... assert_(len(caught) == 1, len(caught))
... assert_(caught[-1].category is DeprecationWarning)
@@ -394,6 +410,7 @@
... def __init__(self, c):
... global server_caught
... with warnings.catch_warnings(record=True) as caught:
+ ... warnings.simplefilter('default')
... c.setHandler(self)
... server_caught = caught
... server_event.set()
@@ -405,6 +422,7 @@
... def connected(self, c):
... global client_caught
... with warnings.catch_warnings(record=True) as caught:
+ ... warnings.simplefilter('default')
... c.setHandler(self)
... client_caught = caught
... client_event.set()
@@ -432,6 +450,7 @@
>>> import zc.ngi.adapters
>>> with warnings.catch_warnings(record=True) as caught:
+ ... warnings.simplefilter('default')
... conn = zc.ngi.adapters.Lines(zc.ngi.testing.Connection())
... conn.setHandler(Handler())
... assert_(len(caught) == 1)
@@ -446,6 +465,7 @@
... old_handler = h
>>> with warnings.catch_warnings(record=True) as caught:
+ ... warnings.simplefilter('default')
... conn = zc.ngi.adapters.Lines(OldConn())
... handler = Handler()
... conn.set_handler(handler)
Modified: zc.ngi/trunk/src/zc/ngi/wordcount.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/wordcount.py 2010-07-08 11:12:56 UTC (rev 114323)
+++ zc.ngi/trunk/src/zc/ngi/wordcount.py 2010-07-08 11:58:29 UTC (rev 114324)
@@ -43,7 +43,7 @@
if __debug__:
logger.debug("Server(%r)", connection)
self.input = ''
- connection.setHandler(self)
+ connection.set_handler(self)
def handle_input(self, connection, data):
if __debug__:
@@ -182,7 +182,7 @@
if __debug__:
logger.debug("connected(%r)", connection)
connection.write(self.docs[0]+'\0')
- connection.setHandler(self)
+ connection.set_handler(self)
def failed_connect(self, reason):
print 'Failed to connect:', reason
More information about the checkins
mailing list