Python twisted.protocols.policies.ProtocolWrapper() Examples

The following are 30 code examples of twisted.protocols.policies.ProtocolWrapper(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module twisted.protocols.policies , or try the search function .
Example #1
Source File: test_tcp.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def connectionMade(self):
        policies.ProtocolWrapper.connectionMade(self)
        self.factory.onConnect.callback(None) 
Example #2
Source File: test_policies.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_protocolLogPrefixFallback(self):
        """
        If the wrapped protocol doesn't have a L{logPrefix} method,
        L{ProtocolWrapper.logPrefix} falls back to the protocol class name.
        """
        class NoProtocol(object):
            pass

        server = Server()
        server.protocol = NoProtocol
        factory = policies.WrappingFactory(server)
        protocol = factory.buildProtocol(
            address.IPv4Address('TCP', '127.0.0.1', 35))
        self.assertEqual("NoProtocol (ProtocolWrapper)",
                         protocol.logPrefix()) 
Example #3
Source File: test_policies.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_getHost(self):
        """
        L{policies.ProtocolWrapper.getHost} calls C{getHost} on the underlying
        transport.
        """
        wrapper = self._getWrapper()
        self.assertEqual(wrapper.getHost(), wrapper.transport.getHost()) 
Example #4
Source File: test_policies.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_getPeer(self):
        """
        L{policies.ProtocolWrapper.getPeer} calls C{getPeer} on the underlying
        transport.
        """
        wrapper = self._getWrapper()
        self.assertEqual(wrapper.getPeer(), wrapper.transport.getPeer()) 
Example #5
Source File: test_policies.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_registerProducer(self):
        """
        L{policies.ProtocolWrapper.registerProducer} calls C{registerProducer}
        on the underlying transport.
        """
        wrapper = self._getWrapper()
        producer = object()
        wrapper.registerProducer(producer, True)
        self.assertIs(wrapper.transport.producer, producer)
        self.assertTrue(wrapper.transport.streaming) 
Example #6
Source File: test_policies.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_unregisterProducer(self):
        """
        L{policies.ProtocolWrapper.unregisterProducer} calls
        C{unregisterProducer} on the underlying transport.
        """
        wrapper = self._getWrapper()
        producer = object()
        wrapper.registerProducer(producer, True)
        wrapper.unregisterProducer()
        self.assertIsNone(wrapper.transport.producer)
        self.assertIsNone(wrapper.transport.streaming) 
Example #7
Source File: test_policies.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_stopConsuming(self):
        """
        L{policies.ProtocolWrapper.stopConsuming} calls C{stopConsuming} on
        the underlying transport.
        """
        wrapper = self._getWrapper()
        result = []
        wrapper.transport.stopConsuming = lambda: result.append(True)
        wrapper.stopConsuming()
        self.assertEqual(result, [True]) 
Example #8
Source File: loopback.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def __init__(self, protocol, factory):
        policies.ProtocolWrapper.__init__(self, protocol, factory)
        self.deferred = defer.Deferred() 
Example #9
Source File: loopback.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def connectionLost(self, reason):
        policies.ProtocolWrapper.connectionLost(self, reason)
        self.deferred.callback(None) 
Example #10
Source File: _inspectro.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def __init__(self, *args):
        policies.ProtocolWrapper.__init__(self, *args)
        self.inLog = []
        self.outLog = [] 
Example #11
Source File: _inspectro.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def write(self, data):
        if self.logging:
            self.outLog.append((time.time(), data))
            if self.logViewer:
                self.logViewer.updateOut(self.outLog[-1])
        policies.ProtocolWrapper.write(self, data) 
Example #12
Source File: _inspectro.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def dataReceived(self, data):
        if self.logging:
            self.inLog.append((time.time(), data))
            if self.logViewer:
                self.logViewer.updateIn(self.inLog[-1])
        policies.ProtocolWrapper.dataReceived(self, data) 
Example #13
Source File: test_policies.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_protocolLogPrefix(self):
        """
        L{ProtocolWrapper.logPrefix} is customized to mention both the original
        protocol and the wrapper.
        """
        server = Server()
        factory = policies.WrappingFactory(server)
        protocol = factory.buildProtocol(
            address.IPv4Address('TCP', '127.0.0.1', 35))
        self.assertEqual("EchoProtocol (ProtocolWrapper)",
                         protocol.logPrefix()) 
Example #14
Source File: test_tcp.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def connectionLost(self, reason):
        policies.ProtocolWrapper.connectionLost(self, reason)
        self.factory.onDisconnect.callback(None) 
Example #15
Source File: test_tcp.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def connectionLost(self, reason):
        policies.ProtocolWrapper.connectionLost(self, reason)
        self.factory.deferred.callback(None) 
Example #16
Source File: test_policies.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def test_transportInterfaces(self):
        """
        The transport wrapper passed to the wrapped protocol's
        C{makeConnection} provides the same interfaces as are provided by the
        original transport.
        """
        class IStubTransport(Interface):
            pass

        class StubTransport:
            implements(IStubTransport)

        # Looking up what ProtocolWrapper implements also mutates the class.
        # It adds __implemented__ and __providedBy__ attributes to it.  These
        # prevent __getattr__ from causing the IStubTransport.providedBy call
        # below from returning True.  If, by accident, nothing else causes
        # these attributes to be added to ProtocolWrapper, the test will pass,
        # but the interface will only be provided until something does trigger
        # their addition.  So we just trigger it right now to be sure.
        implementedBy(policies.ProtocolWrapper)

        proto = protocol.Protocol()
        wrapper = policies.ProtocolWrapper(policies.WrappingFactory(None), proto)

        wrapper.makeConnection(StubTransport())
        self.assertTrue(IStubTransport.providedBy(proto.transport)) 
Example #17
Source File: loopback.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, protocol, factory):
        policies.ProtocolWrapper.__init__(self, protocol, factory)
        self.deferred = defer.Deferred() 
Example #18
Source File: loopback.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def connectionLost(self, reason):
        policies.ProtocolWrapper.connectionLost(self, reason)
        self.deferred.callback(None) 
Example #19
Source File: _inspectro.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args):
        policies.ProtocolWrapper.__init__(self, *args)
        self.inLog = []
        self.outLog = [] 
Example #20
Source File: _inspectro.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def write(self, data):
        if self.logging:
            self.outLog.append((time.time(), data))
            if self.logViewer:
                self.logViewer.updateOut(self.outLog[-1])
        policies.ProtocolWrapper.write(self, data) 
Example #21
Source File: _inspectro.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def dataReceived(self, data):
        if self.logging:
            self.inLog.append((time.time(), data))
            if self.logViewer:
                self.logViewer.updateIn(self.inLog[-1])
        policies.ProtocolWrapper.dataReceived(self, data) 
Example #22
Source File: test_tcp.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def connectionMade(self):
        policies.ProtocolWrapper.connectionMade(self)
        self.factory.onConnect.callback(None) 
Example #23
Source File: test_tcp.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def connectionLost(self, reason):
        policies.ProtocolWrapper.connectionLost(self, reason)
        self.factory.onDisconnect.callback(None) 
Example #24
Source File: test_tcp.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def connectionLost(self, reason):
        policies.ProtocolWrapper.connectionLost(self, reason)
        self.factory.deferred.callback(None) 
Example #25
Source File: test_policies.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_registerProducer(self):
        """
        L{policies.ProtocolWrapper.registerProducer} calls C{registerProducer}
        on the underlying transport.
        """
        wrapper = self._getWrapper()
        producer = object()
        wrapper.registerProducer(producer, True)
        self.assertIs(wrapper.transport.producer, producer)
        self.assertTrue(wrapper.transport.streaming) 
Example #26
Source File: loopback.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, protocol, factory):
        policies.ProtocolWrapper.__init__(self, protocol, factory)
        self.deferred = defer.Deferred() 
Example #27
Source File: loopback.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def connectionLost(self, reason):
        policies.ProtocolWrapper.connectionLost(self, reason)
        self.deferred.callback(None) 
Example #28
Source File: _wrapper.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, factory, wrappedProtocol):
        policies.ProtocolWrapper.__init__(self, factory, wrappedProtocol)
        self._proxyInfo = None
        self._parser = None 
Example #29
Source File: test_tcp.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, factory, wrappedProtocol):
        policies.ProtocolWrapper.__init__(self, factory, wrappedProtocol) 
Example #30
Source File: test_tcp.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def connectionLost(self, reason):
        policies.ProtocolWrapper.connectionLost(self, reason)
        self.factory.onDisconnect.callback(None)