[Checkins] SVN: zc.ngi/branches/jim-dev/src/zc/ngi/ checkpoint
Jim Fulton
jim at zope.com
Thu Sep 3 07:02:59 EDT 2009
Log message for revision 103499:
checkpoint
Changed:
U zc.ngi/branches/jim-dev/src/zc/ngi/blocking.py
U zc.ngi/branches/jim-dev/src/zc/ngi/doc/index.txt
-=-
Modified: zc.ngi/branches/jim-dev/src/zc/ngi/blocking.py
===================================================================
--- zc.ngi/branches/jim-dev/src/zc/ngi/blocking.py 2009-09-03 07:37:40 UTC (rev 103498)
+++ zc.ngi/branches/jim-dev/src/zc/ngi/blocking.py 2009-09-03 11:02:59 UTC (rev 103499)
@@ -53,41 +53,58 @@
def setHandler(self, handler):
self.handler = handler
- self.handleInput = handler.handleInput
- self.handle_exception = handler.handle_exception
self.connection.setHandler(self)
+ def handle_input(self, connection, data):
+ self.handle_input = self.handler.hande_input
+ self.hande_input(connection, data)
+
def handle_close(self, connection, reason):
self.connector.closed = reason
self.connector.event.set()
+ def handle_exception(self, connection, exception):
+ try:
+ self.handler.handle_exception(connection, exception)
+ except:
+ self.connector.exception = exception
+ raise
+
class RequestConnector:
- failed = closed = connection = None
+ exception = closed = connection = None
def __init__(self, handler, event):
- self.handler
- self.event
+ try:
+ connected = handler.connected
+ except AttributeError:
+ if callable(handler):
+ connected = handler
+ elif getattr(handler, 'handle_input', None) is None:
+ raise
+ else:
+ connected = lambda connection: connection.setHandler(handler)
+ self._connected = connected
+ self.event = event
+
def connected(self, connection):
self.connection = connection
- connection = RequestConnection(connection, self)
- self.handler.connected(connection)
+ self._connected(RequestConnection(connection, self))
- def failed_connection(self, reason):
- self.failed = reason
+ def failed_connect(self, reason):
+ self.exception = ConnectionFailed(reason)
self.event.set()
-def request(address, connection_handler, connect=None, timeout=None):
- if connect is None:
- connect = zc.ngi.implementation.connect
+def request(connect, address, connection_handler, timeout=None):
event = threading.Event()
connector = RequestConnector(connection_handler, event)
+ connect(address, connector)
event.wait(timeout)
if connector.closed is not None:
return connector.closed
- if connector.failed is not None:
- raise ConnectionFailed(connector.failed)
+ if connector.exception:
+ raise connector.exception
if connector.connection is None:
raise ConnectionTimeout
raise Timeout
Modified: zc.ngi/branches/jim-dev/src/zc/ngi/doc/index.txt
===================================================================
--- zc.ngi/branches/jim-dev/src/zc/ngi/doc/index.txt 2009-09-03 07:37:40 UTC (rev 103498)
+++ zc.ngi/branches/jim-dev/src/zc/ngi/doc/index.txt 2009-09-03 11:02:59 UTC (rev 103499)
@@ -475,6 +475,9 @@
>>> import zc.ngi.blocking
>>> zc.ngi.blocking.request(zc.ngi.testing.connect, 'xxx', WCClient)
+ Traceback (most recent call last):
+ ...
+ ConnectionFailed: no such server
The request function takes a connector, an address, and a connect
handler. In the example above, we used the ``zc.ngi.testing``
@@ -485,10 +488,10 @@
-connecting
request
threading
udp
+adapters
----------------------
Notes:
@@ -503,3 +506,6 @@
- Can we implement application connection retry logic wo threads?
Should we? Testing would be easier if the implementation provided
it. If conectors took a delay argument, then it would be easier to test.
+- exception hamdling needs more thought
+ - what exceptions get reported
+ - where?
More information about the checkins
mailing list