当前位置: 首页>>代码示例>>Python>>正文


Python policies.WrappingFactory方法代码示例

本文整理汇总了Python中twisted.protocols.policies.WrappingFactory方法的典型用法代码示例。如果您正苦于以下问题:Python policies.WrappingFactory方法的具体用法?Python policies.WrappingFactory怎么用?Python policies.WrappingFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.protocols.policies的用法示例。


在下文中一共展示了policies.WrappingFactory方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: loopbackUNIX

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
def loopbackUNIX(server, client, noisy=True):
    """Run session between server and client protocol instances over UNIX socket."""
    path = tempfile.mktemp()
    from twisted.internet import reactor
    f = policies.WrappingFactory(protocol.Factory())
    serverWrapper = _FireOnClose(f, server)
    f.noisy = noisy
    f.buildProtocol = lambda addr: serverWrapper
    serverPort = reactor.listenUNIX(path, f)
    clientF = LoopbackClientFactory(client)
    clientF.noisy = noisy
    reactor.connectUNIX(path, clientF)
    d = clientF.deferred
    d.addCallback(lambda x: serverWrapper.deferred)
    d.addCallback(lambda x: serverPort.stopListening())
    return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:loopback.py

示例2: test_breakReferenceCycle

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
def test_breakReferenceCycle(self):
        """
        L{policies.ProtocolWrapper.connectionLost} sets C{wrappedProtocol} to
        C{None} in order to break reference cycle between wrapper and wrapped
        protocols.
        :return:
        """
        wrapper = policies.ProtocolWrapper(policies.WrappingFactory(Server()),
                                           protocol.Protocol())
        transport = StringTransportWithDisconnection()
        transport.protocol = wrapper
        wrapper.makeConnection(transport)

        self.assertIsNotNone(wrapper.wrappedProtocol)
        transport.loseConnection()
        self.assertIsNone(wrapper.wrappedProtocol) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:18,代码来源:test_policies.py

示例3: setUp

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
def setUp(self):
        self.agent = None # for twisted.web.client.Agent test
        self.cleanupServerConnections = 0
        r = resource.Resource()
        r.putChild(b"file", Data(b"0123456789", "text/html"))
        r.putChild(b"redirect", Redirect(b"/file"))
        self.infiniteRedirectResource = CountingRedirect(b"/infiniteRedirect")
        r.putChild(b"infiniteRedirect", self.infiniteRedirectResource)
        r.putChild(b"wait", ForeverTakingResource())
        r.putChild(b"write-then-wait", ForeverTakingResource(write=True))
        r.putChild(b"never-read", ForeverTakingNoReadingResource())
        r.putChild(b"error", ErrorResource())
        r.putChild(b"nolength", NoLengthResource())
        r.putChild(b"host", HostHeaderResource())
        r.putChild(b"payload", PayloadResource())
        r.putChild(b"broken", BrokenDownloadResource())
        r.putChild(b"cookiemirror", CookieMirrorResource())
        r.putChild(b'delay1', DelayResource(1))
        r.putChild(b'delay2', DelayResource(2))

        self.afterFoundGetCounter = CountingResource()
        r.putChild(b"afterFoundGetCounter", self.afterFoundGetCounter)
        r.putChild(b"afterFoundGetRedirect", Redirect(b"/afterFoundGetCounter"))

        miscasedHead = Data(b"miscased-head GET response content", "major/minor")
        miscasedHead.render_Head = lambda request: b"miscased-head content"
        r.putChild(b"miscased-head", miscasedHead)

        self.extendedRedirect = ExtendedRedirect(b'/extendedRedirect')
        r.putChild(b"extendedRedirect", self.extendedRedirect)
        self.site = server.Site(r, timeout=None)
        self.wrapper = WrappingFactory(self.site)
        self.port = self._listen(self.wrapper)
        self.portno = self.port.getHost().port 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:36,代码来源:test_webclient.py

示例4: loopbackTCP

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
def loopbackTCP(server, client, port=0, noisy=True):
    """Run session between server and client protocol instances over TCP."""
    from twisted.internet import reactor
    f = policies.WrappingFactory(protocol.Factory())
    serverWrapper = _FireOnClose(f, server)
    f.noisy = noisy
    f.buildProtocol = lambda addr: serverWrapper
    serverPort = reactor.listenTCP(port, f, interface='127.0.0.1')
    clientF = LoopbackClientFactory(client)
    clientF.noisy = noisy
    reactor.connectTCP('127.0.0.1', serverPort.getHost().port, clientF)
    d = clientF.deferred
    d.addCallback(lambda x: serverWrapper.deferred)
    d.addCallback(lambda x: serverPort.stopListening())
    return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:loopback.py

示例5: __init__

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
def __init__(self, wrappedFactory):
        policies.WrappingFactory.__init__(self, wrappedFactory)
        self.onConnect = defer.Deferred()
        self.onDisconnect = defer.Deferred() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:6,代码来源:test_tcp.py

示例6: test_transportInterfaces

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
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

        @implementer(IStubTransport)
        class StubTransport:
            pass

        # 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)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:29,代码来源:test_policies.py

示例7: test_factoryLogPrefix

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
def test_factoryLogPrefix(self):
        """
        L{WrappingFactory.logPrefix} is customized to mention both the original
        factory and the wrapping factory.
        """
        server = Server()
        factory = policies.WrappingFactory(server)
        self.assertEqual("Server (WrappingFactory)", factory.logPrefix()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_policies.py

示例8: test_factoryLogPrefixFallback

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
def test_factoryLogPrefixFallback(self):
        """
        If the wrapped factory doesn't have a L{logPrefix} method,
        L{WrappingFactory.logPrefix} falls back to the factory class name.
        """
        class NoFactory(object):
            pass

        server = NoFactory()
        factory = policies.WrappingFactory(server)
        self.assertEqual("NoFactory (WrappingFactory)", factory.logPrefix()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_policies.py

示例9: test_protocolLogPrefix

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
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()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_policies.py

示例10: test_protocolLogPrefixFallback

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
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()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:test_policies.py

示例11: test_startedConnecting

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
def test_startedConnecting(self):
        """
        L{policies.WrappingFactory.startedConnecting} calls
        C{startedConnecting} on the underlying factory.
        """
        result = []
        class Factory(object):
            def startedConnecting(self, connector):
                result.append(connector)

        wrapper = policies.WrappingFactory(Factory())
        connector = object()
        wrapper.startedConnecting(connector)
        self.assertEqual(result, [connector]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_policies.py

示例12: test_clientConnectionLost

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
def test_clientConnectionLost(self):
        """
        L{policies.WrappingFactory.clientConnectionLost} calls
        C{clientConnectionLost} on the underlying factory.
        """
        result = []
        class Factory(object):
            def clientConnectionLost(self, connector, reason):
                result.append((connector, reason))

        wrapper = policies.WrappingFactory(Factory())
        connector = object()
        reason = object()
        wrapper.clientConnectionLost(connector, reason)
        self.assertEqual(result, [(connector, reason)]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:test_policies.py

示例13: test_clientConnectionFailed

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
def test_clientConnectionFailed(self):
        """
        L{policies.WrappingFactory.clientConnectionFailed} calls
        C{clientConnectionFailed} on the underlying factory.
        """
        result = []
        class Factory(object):
            def clientConnectionFailed(self, connector, reason):
                result.append((connector, reason))

        wrapper = policies.WrappingFactory(Factory())
        connector = object()
        reason = object()
        wrapper.clientConnectionFailed(connector, reason)
        self.assertEqual(result, [(connector, reason)]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:test_policies.py

示例14: startFactory

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import WrappingFactory [as 别名]
def startFactory(self):
        policies.WrappingFactory.startFactory(self)
        self.deferred.callback(None) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:5,代码来源:test_policies.py


注:本文中的twisted.protocols.policies.WrappingFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。