Python twisted.internet.interfaces.IStreamServerEndpoint() Examples
The following are 26
code examples of twisted.internet.interfaces.IStreamServerEndpoint().
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.internet.interfaces
, or try the search function
.
Example #1
Source File: test_endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_typeFromPlugin(self): """ L{endpoints.serverFromString} looks up plugins of type L{IStreamServerEndpoint} and constructs endpoints from them. """ # Set up a plugin which will only be accessible for the duration of # this test. addFakePlugin(self) # Plugin is set up: now actually test. notAReactor = object() fakeEndpoint = endpoints.serverFromString( notAReactor, "fake:hello:world:yes=no:up=down") from twisted.plugins.fakeendpoint import fake self.assertIs(fakeEndpoint.parser, fake) self.assertEqual(fakeEndpoint.args, (notAReactor, 'hello', 'world')) self.assertEqual(fakeEndpoint.kwargs, dict(yes='no', up='down'))
Example #2
Source File: test_endpoints.py From learn_python3_spider with MIT License | 6 votes |
def createServerEndpoint(self, reactor, factory, **listenArgs): """ Create an L{SSL4ServerEndpoint} and return the tools to verify its behaviour. @param factory: The thing that we expect to be passed to our L{IStreamServerEndpoint.listen} implementation. @param reactor: A fake L{IReactorSSL} that L{SSL4ServerEndpoint} can call L{IReactorSSL.listenSSL} on. @param listenArgs: Optional dictionary of arguments to L{IReactorSSL.listenSSL}. """ address = IPv4Address("TCP", "0.0.0.0", 0) return (endpoints.SSL4ServerEndpoint(reactor, address.port, self.serverSSLContext, **listenArgs), (address.port, factory, self.serverSSLContext, listenArgs.get('backlog', 50), listenArgs.get('interface', '')), address)
Example #3
Source File: test_endpoints.py From learn_python3_spider with MIT License | 6 votes |
def createServerEndpoint(self, reactor, factory, **listenArgs): """ Create a L{TCP6ServerEndpoint} and return the values needed to verify its behaviour. @param reactor: A fake L{IReactorTCP} that L{TCP6ServerEndpoint} can call L{IReactorTCP.listenTCP} on. @param factory: The thing that we expect to be passed to our L{IStreamServerEndpoint.listen} implementation. @param listenArgs: Optional dictionary of arguments to L{IReactorTCP.listenTCP}. """ interface = listenArgs.get('interface', '::') address = IPv6Address("TCP", interface, 0) if listenArgs is None: listenArgs = {} return (endpoints.TCP6ServerEndpoint(reactor, address.port, **listenArgs), (address.port, factory, listenArgs.get('backlog', 50), interface), address)
Example #4
Source File: test_endpoints.py From learn_python3_spider with MIT License | 6 votes |
def createServerEndpoint(self, reactor, factory, **listenArgs): """ Create an L{TCP4ServerEndpoint} and return the values needed to verify its behaviour. @param reactor: A fake L{IReactorTCP} that L{TCP4ServerEndpoint} can call L{IReactorTCP.listenTCP} on. @param factory: The thing that we expect to be passed to our L{IStreamServerEndpoint.listen} implementation. @param listenArgs: Optional dictionary of arguments to L{IReactorTCP.listenTCP}. """ address = IPv4Address("TCP", "0.0.0.0", 0) if listenArgs is None: listenArgs = {} return (endpoints.TCP4ServerEndpoint(reactor, address.port, **listenArgs), (address.port, factory, listenArgs.get('backlog', 50), listenArgs.get('interface', '')), address)
Example #5
Source File: endpoints.py From learn_python3_spider with MIT License | 6 votes |
def listen(self, factory): """ Implement L{IStreamServerEndpoint.listen} to start listening on, and then close, C{self._fileno}. """ if self._used: return defer.fail(error.AlreadyListened()) self._used = True try: self._setNonBlocking(self.fileno) port = self.reactor.adoptStreamPort( self.fileno, self.addressFamily, factory) self._close(self.fileno) except: return defer.fail() return defer.succeed(port)
Example #6
Source File: test_endpoints.py From learn_python3_spider with MIT License | 6 votes |
def createServerEndpoint(self, reactor, factory, **listenArgs): """ Create an L{UNIXServerEndpoint} and return the tools to verify its behaviour. @param reactor: A fake L{IReactorUNIX} that L{UNIXServerEndpoint} can call L{IReactorUNIX.listenUNIX} on. @param factory: The thing that we expect to be passed to our L{IStreamServerEndpoint.listen} implementation. @param listenArgs: Optional dictionary of arguments to L{IReactorUNIX.listenUNIX}. """ address = UNIXAddress(self.mktemp()) return (endpoints.UNIXServerEndpoint(reactor, address.name, **listenArgs), (address.name, factory, listenArgs.get('backlog', 50), listenArgs.get('mode', 0o666), listenArgs.get('wantPID', 0)), address)
Example #7
Source File: test_endpoints.py From learn_python3_spider with MIT License | 6 votes |
def test_typeFromPlugin(self): """ L{endpoints.serverFromString} looks up plugins of type L{IStreamServerEndpoint} and constructs endpoints from them. """ # Set up a plugin which will only be accessible for the duration of # this test. addFakePlugin(self) # Plugin is set up: now actually test. notAReactor = object() fakeEndpoint = endpoints.serverFromString( notAReactor, "fake:hello:world:yes=no:up=down") from twisted.plugins.fakeendpoint import fake self.assertIs(fakeEndpoint.parser, fake) self.assertEqual(fakeEndpoint.args, (notAReactor, 'hello', 'world')) self.assertEqual(fakeEndpoint.kwargs, dict(yes='no', up='down'))
Example #8
Source File: test_endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def createServerEndpoint(self, reactor, factory, **listenArgs): """ Create an L{UNIXServerEndpoint} and return the tools to verify its behaviour. @param reactor: A fake L{IReactorUNIX} that L{UNIXServerEndpoint} can call L{IReactorUNIX.listenUNIX} on. @param factory: The thing that we expect to be passed to our L{IStreamServerEndpoint.listen} implementation. @param listenArgs: Optional dictionary of arguments to L{IReactorUNIX.listenUNIX}. """ address = UNIXAddress(self.mktemp()) return (endpoints.UNIXServerEndpoint(reactor, address.name, **listenArgs), (address.name, factory, listenArgs.get('backlog', 50), listenArgs.get('mode', 0o666), listenArgs.get('wantPID', 0)), address)
Example #9
Source File: test_endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def createServerEndpoint(self, reactor, factory, **listenArgs): """ Create an L{SSL4ServerEndpoint} and return the tools to verify its behaviour. @param factory: The thing that we expect to be passed to our L{IStreamServerEndpoint.listen} implementation. @param reactor: A fake L{IReactorSSL} that L{SSL4ServerEndpoint} can call L{IReactorSSL.listenSSL} on. @param listenArgs: Optional dictionary of arguments to L{IReactorSSL.listenSSL}. """ address = IPv4Address("TCP", "0.0.0.0", 0) return (endpoints.SSL4ServerEndpoint(reactor, address.port, self.serverSSLContext, **listenArgs), (address.port, factory, self.serverSSLContext, listenArgs.get('backlog', 50), listenArgs.get('interface', '')), address)
Example #10
Source File: test_endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def createServerEndpoint(self, reactor, factory, **listenArgs): """ Create a L{TCP6ServerEndpoint} and return the values needed to verify its behaviour. @param reactor: A fake L{IReactorTCP} that L{TCP6ServerEndpoint} can call L{IReactorTCP.listenTCP} on. @param factory: The thing that we expect to be passed to our L{IStreamServerEndpoint.listen} implementation. @param listenArgs: Optional dictionary of arguments to L{IReactorTCP.listenTCP}. """ interface = listenArgs.get('interface', '::') address = IPv6Address("TCP", interface, 0) if listenArgs is None: listenArgs = {} return (endpoints.TCP6ServerEndpoint(reactor, address.port, **listenArgs), (address.port, factory, listenArgs.get('backlog', 50), interface), address)
Example #11
Source File: test_endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def createServerEndpoint(self, reactor, factory, **listenArgs): """ Create an L{TCP4ServerEndpoint} and return the values needed to verify its behaviour. @param reactor: A fake L{IReactorTCP} that L{TCP4ServerEndpoint} can call L{IReactorTCP.listenTCP} on. @param factory: The thing that we expect to be passed to our L{IStreamServerEndpoint.listen} implementation. @param listenArgs: Optional dictionary of arguments to L{IReactorTCP.listenTCP}. """ address = IPv4Address("TCP", "0.0.0.0", 0) if listenArgs is None: listenArgs = {} return (endpoints.TCP4ServerEndpoint(reactor, address.port, **listenArgs), (address.port, factory, listenArgs.get('backlog', 50), listenArgs.get('interface', '')), address)
Example #12
Source File: endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def listen(self, factory): """ Implement L{IStreamServerEndpoint.listen} to start listening on, and then close, C{self._fileno}. """ if self._used: return defer.fail(error.AlreadyListened()) self._used = True try: self._setNonBlocking(self.fileno) port = self.reactor.adoptStreamPort( self.fileno, self.addressFamily, factory) self._close(self.fileno) except: return defer.fail() return defer.succeed(port)
Example #13
Source File: endpoints.py From learn_python3_spider with MIT License | 5 votes |
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen on a UNIX socket. """ return defer.execute(self._reactor.listenUNIX, self._address, protocolFactory, backlog=self._backlog, mode=self._mode, wantPID=self._wantPID)
Example #14
Source File: endpoints.py From python-for-android with Apache License 2.0 | 5 votes |
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen on a TCP socket """ return defer.execute(self._reactor.listenTCP, self._port, protocolFactory, backlog=self._backlog, interface=self._interface)
Example #15
Source File: test_manager.py From magic-wormhole with MIT License | 5 votes |
def make_manager(leader=True): h = Holder() h.send = mock.Mock() alsoProvides(h.send, ISend) if leader: side = LEADER else: side = FOLLOWER h.key = b"\x00" * 32 h.relay = None h.reactor = object() h.clock = Clock() h.eq = EventualQueue(h.clock) term = mock.Mock(side_effect=lambda: True) # one write per Eventual tick def term_factory(): return term h.coop = Cooperator(terminationPredicateFactory=term_factory, scheduler=h.eq.eventually) h.inbound = mock.Mock() h.Inbound = mock.Mock(return_value=h.inbound) h.outbound = mock.Mock() h.Outbound = mock.Mock(return_value=h.outbound) h.sc0 = mock.Mock() alsoProvides(h.sc0, ISubChannel) h.SubChannel = mock.Mock(return_value=h.sc0) h.listen_ep = mock.Mock() alsoProvides(h.listen_ep, IStreamServerEndpoint) with mock.patch("wormhole._dilation.manager.Inbound", h.Inbound), \ mock.patch("wormhole._dilation.manager.Outbound", h.Outbound), \ mock.patch("wormhole._dilation.manager.SubChannel", h.SubChannel), \ mock.patch("wormhole._dilation.manager.SubchannelListenerEndpoint", return_value=h.listen_ep): m = Manager(h.send, side, h.relay, h.reactor, h.eq, h.coop) h.hostaddr = m._host_addr m.got_dilation_key(h.key) return m, h
Example #16
Source File: endpoints.py From python-for-android with Apache License 2.0 | 5 votes |
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen for SSL on a TCP socket. """ return defer.execute(self._reactor.listenSSL, self._port, protocolFactory, contextFactory=self._sslContextFactory, backlog=self._backlog, interface=self._interface)
Example #17
Source File: endpoints.py From python-for-android with Apache License 2.0 | 5 votes |
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen on a UNIX socket. """ return defer.execute(self._reactor.listenUNIX, self._address, protocolFactory, backlog=self._backlog, mode=self._mode, wantPID=self._wantPID)
Example #18
Source File: test_regionservice.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_init_sets_appropriate_instance_attributes(self): service = RegionService(sentinel.ipcWorker) self.assertThat(service, IsInstance(Service)) self.assertThat(service.connections, IsInstance(defaultdict)) self.assertThat(service.connections.default_factory, Is(set)) self.assertThat( service.endpoints, AllMatch(AllMatch(Provides(IStreamServerEndpoint))), ) self.assertThat(service.factory, IsInstance(Factory)) self.assertThat(service.factory.protocol, Equals(RegionServer)) self.assertThat(service.events.connected, IsInstance(events.Event)) self.assertThat(service.events.disconnected, IsInstance(events.Event))
Example #19
Source File: endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def listen(self, stdioProtocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen on stdin/stdout """ return defer.execute(self._stdio, stdioProtocolFactory.buildProtocol(PipeAddress()), reactor=self._reactor)
Example #20
Source File: endpoints.py From learn_python3_spider with MIT License | 5 votes |
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen for SSL on a TCP socket. """ return defer.execute(self._reactor.listenSSL, self._port, protocolFactory, contextFactory=self._sslContextFactory, backlog=self._backlog, interface=self._interface)
Example #21
Source File: endpoints.py From learn_python3_spider with MIT License | 5 votes |
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen on a TCP socket """ return defer.execute(self._reactor.listenTCP, self._port, protocolFactory, backlog=self._backlog, interface=self._interface)
Example #22
Source File: endpoints.py From learn_python3_spider with MIT License | 5 votes |
def listen(self, stdioProtocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen on stdin/stdout """ return defer.execute(self._stdio, stdioProtocolFactory.buildProtocol(PipeAddress()), reactor=self._reactor)
Example #23
Source File: endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen on a UNIX socket. """ return defer.execute(self._reactor.listenUNIX, self._address, protocolFactory, backlog=self._backlog, mode=self._mode, wantPID=self._wantPID)
Example #24
Source File: endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen for SSL on a TCP socket. """ return defer.execute(self._reactor.listenSSL, self._port, protocolFactory, contextFactory=self._sslContextFactory, backlog=self._backlog, interface=self._interface)
Example #25
Source File: endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen on a TCP socket """ return defer.execute(self._reactor.listenTCP, self._port, protocolFactory, backlog=self._backlog, interface=self._interface)
Example #26
Source File: endpoints.py From python-for-android with Apache License 2.0 | 4 votes |
def serverFromString(reactor, description): """ Construct a stream server endpoint from an endpoint description string. The format for server endpoint descriptions is a simple string. It is a prefix naming the type of endpoint, then a colon, then the arguments for that endpoint. For example, you can call it like this to create an endpoint that will listen on TCP port 80:: serverFromString(reactor, "tcp:80") Additional arguments may be specified as keywords, separated with colons. For example, you can specify the interface for a TCP server endpoint to bind to like this:: serverFromString(reactor, "tcp:80:interface=127.0.0.1") SSL server endpoints may be specified with the 'ssl' prefix, and the private key and certificate files may be specified by the C{privateKey} and C{certKey} arguments:: serverFromString(reactor, "ssl:443:privateKey=key.pem:certKey=crt.pem") If a private key file name (C{privateKey}) isn't provided, a "server.pem" file is assumed to exist which contains the private key. If the certificate file name (C{certKey}) isn't provided, the private key file is assumed to contain the certificate as well. You may escape colons in arguments with a backslash, which you will need to use if you want to specify a full pathname argument on Windows:: serverFromString(reactor, "ssl:443:privateKey=C\\:/key.pem:certKey=C\\:/cert.pem") finally, the 'unix' prefix may be used to specify a filesystem UNIX socket, optionally with a 'mode' argument to specify the mode of the socket file created by C{listen}:: serverFromString(reactor, "unix:/var/run/finger") serverFromString(reactor, "unix:/var/run/finger:mode=660") This function is also extensible; new endpoint types may be registered as L{IStreamServerEndpointStringParser} plugins. See that interface for more information. @param reactor: The server endpoint will be constructed with this reactor. @param description: The strports description to parse. @return: A new endpoint which can be used to listen with the parameters given by by C{description}. @rtype: L{IStreamServerEndpoint<twisted.internet.interfaces.IStreamServerEndpoint>} @raise ValueError: when the 'description' string cannot be parsed. @since: 10.2 """ return _serverFromStringLegacy(reactor, description, _NO_DEFAULT)