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


Python Factory.forProtocol方法代码示例

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


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

示例1: proxy

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
def proxy(upstream, endpoint, header):
    """
    Establish a new connection to ``endpoint`` and begin proxying between that
    connection and ``upstream``.

    :param IProtocol upstream: A connected protocol.  All data received by
        this protocol from this point on will be sent along to another newly
        established connection.

    :param IStreamClientEndpoint endpoint: An endpoint to use to establish a
        new connection.  All data received over this connection will be sent
        along to the upstream connection.

    :param bytes header: Some extra data to write to the new downstream
        connection before proxying begins.
    """
    def failed(reason):
        upstream.transport.resumeProducing()
        upstream.transport.abortConnection()
        return reason

    upstream.transport.pauseProducing()

    peer = upstream.transport.getPeer()
    action = start_action(
        action_type=u"grid-router:proxy",
        **{u"from": (peer.host, peer.port)}
    )
    with action.context():
        d = DeferredContext(endpoint.connect(Factory.forProtocol(_Proxy)))
        d.addCallbacks(
            lambda downstream: DeferredContext(downstream.take_over(upstream, header)),
            failed,
        )
        return d.addActionFinish()
开发者ID:LeastAuthority,项目名称:leastauthority.com,代码行数:37,代码来源:_router.py

示例2: init

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
def init():
    """
    Init reactor and events.
    """
    reactor.listenTCP(PORT+1, CeltyFactory())
    reactor.listenTCP(PORT, SockJSFactory(Factory.forProtocol(CeltyProtocol)))
    i("Started twisted server at {}:{}", "localhost", PORT)
开发者ID:ShadowPrince,项目名称:celty,代码行数:9,代码来源:__init__.py

示例3: test_websocket_with_map

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
    def test_websocket_with_map(self):
        """
        Speaking WebSocket when the connection is made will make UniSocket
        create a new WebSocket protocol and send the data to it.
        """
        t = StringTransport()

        class MyFakeWebSocket(Protocol):
            """
            A fake WebSocket factory which just echos data back.
            """
            def dataReceived(self, data):
                self.transport.write(data)

        fake_websocket = Factory.forProtocol(MyFakeWebSocket)
        websocket_map = OrderedDict({u"baz": None})
        websocket_map["ws"] = fake_websocket

        f = UniSocketServerFactory(websocket_factory_map=websocket_map)
        p = f.buildProtocol(None)

        p.makeConnection(t)
        t.protocol = p

        self.assertTrue(t.connected)
        p.dataReceived(b'GET /ws HTTP/1.1\r\nConnection: close\r\n\r\n')

        self.assertTrue(t.connected)
        self.assertEqual(t.value(),
                         b'GET /ws HTTP/1.1\r\nConnection: close\r\n\r\n')
开发者ID:schoonc,项目名称:crossbar,代码行数:32,代码来源:test_unisocket.py

示例4: test_rawsocket_with_factory

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
    def test_rawsocket_with_factory(self):
        """
        Speaking RawSocket when the connection is made will make UniSocket
        create a new RawSocket protocol and send the data to it.
        """
        t = StringTransport()

        class MyFakeRawSocket(Protocol):
            """
            A fake RawSocket factory which just echos data back.
            """
            def dataReceived(self, data):
                self.transport.write(data)

        fake_rawsocket = Factory.forProtocol(MyFakeRawSocket)
        f = UniSocketServerFactory(rawsocket_factory=fake_rawsocket)
        p = f.buildProtocol(None)

        p.makeConnection(t)
        t.protocol = p

        self.assertTrue(t.connected)
        p.dataReceived(b'\x7F0000000')
        p.dataReceived(b'moredata')

        self.assertTrue(t.connected)
        self.assertEqual(t.value(), b'\x7F0000000moredata')
开发者ID:schoonc,项目名称:crossbar,代码行数:29,代码来源:test_unisocket.py

示例5: main

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
def main():
    log.startLogging(sys.stdout)
    print "main"
    endpoint = get_endpoint()
    endpoint.connect(Factory.forProtocol(Echo))
    print "running reactor"
    reactor.run()
开发者ID:lahwran,项目名称:twisted_tls_test,代码行数:9,代码来源:client.py

示例6: test_unix_already_listening

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
    def test_unix_already_listening(self):
        """
        A config with type = "unix" will create an endpoint for a UNIX socket
        at the given path, and delete it if required.
        """
        path = FilePath("/tmp").child(uuid4().hex).path
        self.addCleanup(os.remove, path)

        # Something is already there
        FilePath(path).setContent(b"")

        reactor = SelectReactor()
        config = {
            "type": "unix",
            "path": path
        }

        endpoint = create_listening_endpoint_from_config(config, self.cbdir,
                                                         reactor, self.log)
        self.assertTrue(isinstance(endpoint, UNIXServerEndpoint))

        factory = Factory.forProtocol(Echo)
        endpoint.listen(factory)

        self.assertIn(
            factory,
            [getattr(x, "factory", None) for x in reactor.getReaders()])
开发者ID:abhimanyu-siwach,项目名称:crossbar,代码行数:29,代码来源:test_endpoint.py

示例7: setUp

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
 def setUp(self):
     self.receiver = SavingEchoReceiver()
     self.protocol = WebSocketsProtocol(self.receiver)
     self.factory = Factory.forProtocol(lambda: self.protocol)
     self.transport = StringTransportWithDisconnection()
     self.protocol.makeConnection(self.transport)
     self.transport.protocol = self.protocol
开发者ID:codecats,项目名称:kitty,代码行数:9,代码来源:test_websockets.py

示例8: main

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
def main(reactor=reactor):
    arguments = vars(parser.parse_args())
    for description in arguments["endpoint"]:
        endpoint = serverFromString(reactor=reactor, description=description)

        wabbit = Factory.forProtocol(WabbitServer)
        endpoint.listen(wabbit)
    reactor.run()
开发者ID:Magnetic,项目名称:HuntingWabbits,代码行数:10,代码来源:cli.py

示例9: factory

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
 def factory(self):
     """
     :return: A protocol factory for a Foolscap proxy server.
     """
     f = Factory.forProtocol(_FoolscapProxy)
     f.reactor = self._reactor
     f.route_mapping = self.route_mapping
     return f
开发者ID:LeastAuthority,项目名称:leastauthority.com,代码行数:10,代码来源:_router.py

示例10: server_setup

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
def server_setup(port):
    f = SockJSFactory(Factory.forProtocol(TwistedChatConnection))

    reactor.listenTCP(port, f)

    os.system('open static/index_twisted.html')

    reactor.run()
开发者ID:kmjungersen,项目名称:SockJS_Benchmarking,代码行数:10,代码来源:benchmark_twisted.py

示例11: main

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
def main(reactor):
    pemBytes = FilePath(b"ca-private-cert.pem").getContent()
    certificateAuthority = Certificate.loadPEM(pemBytes)
    myCertificate = PrivateCertificate.loadPEM(pemBytes)
    serverEndpoint = SSL4ServerEndpoint(
        reactor, 4321, myCertificate.options(certificateAuthority)
    )
    serverEndpoint.listen(Factory.forProtocol(ReportWhichClient))
    return Deferred()
开发者ID:damouse,项目名称:pdservertemp,代码行数:11,代码来源:whichclient.py

示例12: initClient

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
 def initClient(self):
     """
     Инициализация клиента
     :return : defer.Deferred
     """
     clientEndpoint = clientFromString(self.reactor, b"tcp:host=localhost:port=9879")
     protocolFactory = Factory.forProtocol(AMP)
     saveProtocol = lambda p: self.save('clientProtocol', p)  # given protocol
     return clientEndpoint.connect(protocolFactory).addCallback(saveProtocol)
开发者ID:musius,项目名称:collaboration,代码行数:11,代码来源:baseTest1.py

示例13: initServer

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
 def initServer(self):
     """
     Инициализация сервера
     :return : defer.Deferred
     """
     self.serverEndpoint = serverFromString(self.reactor, b"tcp:9879")
     factory = Factory.forProtocol(lambda: AMP(locator=PongLocator()))
     savePort = lambda p: self.save('serverPort', p)  # given port
     return self.serverEndpoint.listen(factory).addCallback(savePort)
开发者ID:musius,项目名称:collaboration,代码行数:11,代码来源:baseTest1.py

示例14: go

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
 def go(self, reactor):
     """
     
     """
     mgr = MPMManager(reactor)
     endpoint = TCP4ServerEndpoint(reactor, 8123)
     yield endpoint.listen(Factory.forProtocol(
         lambda: SendToSubprocess(mgr)))
     yield Deferred()
开发者ID:markrwilliams,项目名称:WarpedAlloy,代码行数:11,代码来源:warped_alloy.py

示例15: setup_transport

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 别名]
    def setup_transport(self):
        config = self.get_static_config()
        self.client_factory = Factory.forProtocol(self.protocol_class)
        self.client_factory.vumi_transport = self

        prefix = "%s:ussd_codes" % (config.transport_name,)
        self.session_manager = yield SessionManager.from_redis_config(
            config.redis_manager, prefix, config.ussd_session_lifetime)
        self.client_service = self.get_service(
            config.twisted_endpoint, self.client_factory)
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:12,代码来源:truteq.py


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