twisted.internet.protocol.Factory - python examples

Here are the examples of the python api twisted.internet.protocol.Factory taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

37 Examples 7

3 View Complete Implementation : pop3testserver.py
Copyright MIT License
Author : adde88
def main():

    if len(sys.argv) < 2:
        printMessage("POP3 with no messages")
    else:
        args = sys.argv[1:]

        for arg in args:
            processArg(arg)

    f = Factory()
    f.protocol = POP3TestServer
    reactor.listenTCP(PORT, f)
    reactor.run()

3 View Complete Implementation : test_pop3.py
Copyright MIT License
Author : adde88
    def setUp(self):
        self.factory = internet.protocol.Factory()
        self.factory.domains = {}
        self.factory.domains['baz.com'] = DummyDomain()
        self.factory.domains['baz.com'].addUser('hello')
        self.factory.domains['baz.com'].addMessage('hello', self.message)

3 View Complete Implementation : test_pop3.py
Copyright MIT License
Author : adde88
    def testAuthListing(self):
        p = DummyPOP3()
        p.factory = internet.protocol.Factory()
        p.factory.challengers = {'Auth1': None, 'secondAuth': None, 'authLast': None}
        client = LineSendingProtocol([
            "AUTH",
            "QUIT",
        ])

        d = loopback.loopbackAsync(p, client)
        return d.addCallback(self._cbTestAuthListing, client)

3 View Complete Implementation : loopback.py
Copyright MIT License
Author : adde88
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

3 View Complete Implementation : loopback.py
Copyright MIT License
Author : adde88
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

3 View Complete Implementation : test_factories.py
Copyright MIT License
Author : adde88
    def testStopTrying(self):
        f = Factory()
        f.protocol = In
        f.connections = 0
        f.allMessages = []
        f.goal = 2
        f.d = defer.Deferred()

        c = ReconnectingClientFactory()
        c.initialDelay = c.delay = 0.2
        c.protocol = Out
        c.howManyTimes = 2

        port = self.port = reactor.listenTCP(0, f)
        PORT = port.getHost().port
        reactor.connectTCP('127.0.0.1', PORT, c)

        f.d.addCallback(self._testStopTrying_1, f, c)
        return f.d

3 View Complete Implementation : queue.py
Copyright Apache License 2.0
Author : apple
    def workerListenerFactory(self):
        """
        Factory that listens for connections from workers.
        """
        f = Factory()
        f.buildProtocol = lambda addr: ConnectionFromWorker(self)
        return f

3 View Complete Implementation : test_gaiendpoint.py
Copyright Apache License 2.0
Author : apple
    def test_simpleSuccess(self):
        """
        If C{getaddrinfo} gives one L{GAIEndpoint.connect}.
        """
        gaiendpoint = self.makeEndpoint()
        protos = []
        f = Factory()
        f.protocol = Protocol
        gaiendpoint.connect(f).addCallback(protos.append)
        WHO_CARES = 0
        WHAT_EVER = ""
        self.gaiResult(AF_INET, SOCK_STREAM, WHO_CARES, WHAT_EVER,
                       ("1.2.3.4", 4321))
        self.clock.advance(1.0)
        attempt = self.fakeRealEndpoints[0]._attempt
        attempt.callback(self.fakeRealEndpoints[0]._factory.buildProtocol(None))
        self.astertEqual(len(protos), 1)

3 View Complete Implementation : delivery.py
Copyright Apache License 2.0
Author : apple
    @inlineCallbacks
    def _submitRequest(self, ssl, host, port, request):
        from twisted.internet import reactor
        f = Factory()
        f.protocol = HTTPClientProtocol
        if ssl:
            ep = GAIEndpoint(reactor, host, port, _configuredClientContextFactory(host))
        else:
            ep = GAIEndpoint(reactor, host, port)
        proto = (yield ep.connect(f))

        response = (yield proto.submitRequest(request))

        returnValue(response)

3 View Complete Implementation : server.py
Copyright GNU General Public License v3.0
Author : CPChain
    def __init__(self):
        self.trans = None

        self.factory = protocol.Factory()
        self.factory.protocol = SSLServerProtocol
        self.factory.protocol.proxy_db = ProxyDB()
        self.factory.protocol.port_conf = {
            'file': config.proxy.server_file_port,
            'stream_ws': config.proxy.server_stream_ws_port,
            'stream_restful': config.proxy.server_stream_restful_port
        }

        self.port = config.proxy.server_port

        server_root = join_with_rc(config.proxy.server_root)
        os.makedirs(server_root, exist_ok=True)