[CalendarServer-changes] [9074] CalendarServer/branches/users/glyph/ipv6-client/twext/internet/ adaptendpoint.py
source_changes at macosforge.org
source_changes at macosforge.org
Fri Apr 13 11:45:33 PDT 2012
Revision: 9074
http://trac.macosforge.org/projects/calendarserver/changeset/9074
Author: glyph at apple.com
Date: 2012-04-13 11:45:33 -0700 (Fri, 13 Apr 2012)
Log Message:
-----------
Eliminate an unnecessary class.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/ipv6-client/twext/internet/adaptendpoint.py
Modified: CalendarServer/branches/users/glyph/ipv6-client/twext/internet/adaptendpoint.py
===================================================================
--- CalendarServer/branches/users/glyph/ipv6-client/twext/internet/adaptendpoint.py 2012-04-13 18:45:27 UTC (rev 9073)
+++ CalendarServer/branches/users/glyph/ipv6-client/twext/internet/adaptendpoint.py 2012-04-13 18:45:33 UTC (rev 9074)
@@ -26,16 +26,27 @@
from twisted.internet.protocol import Factory
from twisted.python import log
-from twisted.python.util import FancyEqMixin
+__all__ = [
+ "connect"
+]
+
class _WrappedProtocol(object):
"""
- A wrapped protocol.
+ A protocol providing a thin wrapper that relays the connectionLost
+ notification.
"""
def __init__(self, wrapped, wrapper):
+ """
+ @param wrapped: the wrapped L{IProtocol} provider, to which all methods
+ will be relayed.
+
+ @param wrapper: The L{LegacyClientFactoryWrapper} that holds the
+ relevant L{ClientFactory}.
+ """
self._wrapped = wrapped
self._wrapper = wrapper
@@ -48,51 +59,20 @@
def connectionLost(self, reason):
+ """
+ When the connection is lost, return the connection.
+ """
try:
self._wrapped.connectionLost(reason)
except:
log.err()
- self._wrapper.callClientConnectionLost(reason)
+ self._wrapper.legacyFactory.clientConnectionLost(self._wrapper, reason)
-class LegacyConnector(FancyEqMixin, object):
- """
- Legacy L{IConnector} interface implementation for stuff that uses endpoints.
- """
+class LegacyClientFactoryWrapper(Factory):
implements(IConnector)
- compareAttributes = tuple(["wrapper"])
-
-
- def __init__(self, wrapper):
- self.wrapper = wrapper
-
-
- def getDestination(self):
- """
- I don't know, endpoints don't have a destination.
- """
- return self.wrapper.endpoint
-
-
- def connect(self):
- self.wrapper.startAttempt()
-
-
- def stopConnecting(self):
- if self.wrapper._outstandingAttempt is None:
- raise RuntimeError("no connection attempt in progress")
- self.wrapper.disconnect()
-
-
- def disconnect(self):
- self.wrapper.disconnect()
-
-
-
-class LegacyClientFactoryWrapper(Factory):
-
def __init__(self, legacyFactory, endpoint):
self.currentlyConnecting = False
self.legacyFactory = legacyFactory
@@ -101,14 +81,32 @@
self._outstandingAttempt = None
+ def getDestination(self):
+ """
+ Implement L{IConnector.getDestination}.
+
+ @return: the endpoint being connected to as the destination.
+ """
+ return self.endpoint
+
+
def buildProtocol(self, addr):
+ """
+ Implement L{Factory.buildProtocol} to return a wrapper protocol that
+ will capture C{connectionLost} notifications.
+
+ @return: a L{Protocol}.
+ """
return _WrappedProtocol(self.legacyFactory.buildProtocol(addr), self)
- def startAttempt(self):
+ def connect(self):
+ """
+ Implement L{IConnector.connect} to connect the endpoint.
+ """
if self._outstandingAttempt is not None:
raise RuntimeError("connection already in progress")
- self.callStartedConnecting()
+ self.legacyFactory.startedConnecting(self)
d = self._outstandingAttempt = self.endpoint.connect(self)
@d.addBoth
def attemptDone(result):
@@ -117,35 +115,37 @@
def rememberProto(proto):
self._connectedProtocol = proto
return proto
- d.addCallbacks(rememberProto, self.callClientConnectionFailed)
+ def callClientConnectionFailed(reason):
+ self.legacyFactory.clientConnectionFailed(self, reason)
+ d.addCallbacks(rememberProto, callClientConnectionFailed)
- def callStartedConnecting(self):
- self.legacyFactory.startedConnecting(LegacyConnector(self))
-
-
- def callClientConnectionLost(self, reason):
- self.legacyFactory.clientConnectionLost(LegacyConnector(self), reason)
-
-
- def callClientConnectionFailed(self, reason):
- self.legacyFactory.clientConnectionFailed(LegacyConnector(self), reason)
-
-
def disconnect(self):
+ """
+ Implement L{IConnector.disconnect}.
+ """
if self._connectedProtocol is not None:
self._connectedProtocol.transport.loseConnection()
elif self._outstandingAttempt is not None:
self._outstandingAttempt.cancel()
+ def stopConnecting(self):
+ """
+ Implement L{IConnector.stopConnecting}.
+ """
+ if self._outstandingAttempt is None:
+ raise RuntimeError("no connection attempt in progress")
+ self.disconnect()
+
+
def connect(endpoint, clientFactory):
"""
Connect a L{twisted.internet.protocol.ClientFactory} using the given
L{twisted.internet.interfaces.IStreamClientEndpoint}.
"""
wrap = LegacyClientFactoryWrapper(clientFactory, endpoint)
- wrap.startAttempt()
- return LegacyConnector(wrap)
+ wrap.connect()
+ return wrap
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120413/6923e5ec/attachment-0001.html>
More information about the calendarserver-changes
mailing list