Python twisted.internet.endpoints.UNIXServerEndpoint() Examples
The following are 13
code examples of twisted.internet.endpoints.UNIXServerEndpoint().
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.endpoints
, 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 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 #2
Source File: test_endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_unix(self): """ When passed a UNIX strports description, L{endpoint.serverFromString} returns a L{UNIXServerEndpoint} instance initialized with the values from the string. """ reactor = object() endpoint = endpoints.serverFromString( reactor, "unix:/var/foo/bar:backlog=7:mode=0123:lockfile=1") self.assertIsInstance(endpoint, endpoints.UNIXServerEndpoint) self.assertIs(endpoint._reactor, reactor) self.assertEqual(endpoint._address, "/var/foo/bar") self.assertEqual(endpoint._backlog, 7) self.assertEqual(endpoint._mode, 0o123) self.assertTrue(endpoint._wantPID)
Example #3
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 #4
Source File: test_endpoints.py From learn_python3_spider with MIT License | 6 votes |
def test_unix(self): """ When passed a UNIX strports description, L{endpoint.serverFromString} returns a L{UNIXServerEndpoint} instance initialized with the values from the string. """ reactor = object() endpoint = endpoints.serverFromString( reactor, "unix:/var/foo/bar:backlog=7:mode=0123:lockfile=1") self.assertIsInstance(endpoint, endpoints.UNIXServerEndpoint) self.assertIs(endpoint._reactor, reactor) self.assertEqual(endpoint._address, "/var/foo/bar") self.assertEqual(endpoint._backlog, 7) self.assertEqual(endpoint._mode, 0o123) self.assertTrue(endpoint._wantPID)
Example #5
Source File: test_endpoints.py From python-for-android with Apache License 2.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', 0666), listenArgs.get('wantPID', 0)), address)
Example #6
Source File: test_endpoints.py From python-for-android with Apache License 2.0 | 6 votes |
def test_unix(self): """ When passed a UNIX strports description, L{endpoint.serverFromString} returns a L{UNIXServerEndpoint} instance initialized with the values from the string. """ reactor = object() endpoint = endpoints.serverFromString( reactor, "unix:/var/foo/bar:backlog=7:mode=0123:lockfile=1") self.assertIsInstance(endpoint, endpoints.UNIXServerEndpoint) self.assertIdentical(endpoint._reactor, reactor) self.assertEquals(endpoint._address, "/var/foo/bar") self.assertEquals(endpoint._backlog, 7) self.assertEquals(endpoint._mode, 0123) self.assertEquals(endpoint._wantPID, True)
Example #7
Source File: test_unix.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def server(self, reactor): """ Construct a UNIX server endpoint. """ # self.mktemp() often returns a path which is too long to be used. path = mktemp(suffix='.sock', dir='.') return UNIXServerEndpoint(reactor, path)
Example #8
Source File: socketfile.py From ccs-twistedextensions with Apache License 2.0 | 5 votes |
def startService(self): from twisted.internet import reactor endpoint = endpoints.UNIXServerEndpoint( reactor, self.address, backlog=self.backlog, wantPID=1 ) self.myPort = yield endpoint.listen(self.protocolFactory) # intercept doRead() to set numberAccepts self.myPort.realDoRead = self.myPort.doRead self.myPort.doRead = maxAcceptDoRead.__get__( self.myPort, self.myPort.__class__ )
Example #9
Source File: test_unix.py From learn_python3_spider with MIT License | 5 votes |
def server(self, reactor): """ Construct a UNIX server endpoint. """ # self.mktemp() often returns a path which is too long to be used. path = mktemp(suffix='.sock', dir='.') return UNIXServerEndpoint(reactor, path)
Example #10
Source File: test_strports.py From python-for-android with Apache License 2.0 | 5 votes |
def test_serviceDeprecatedDefault(self): """ L{strports.service} still accepts a 'default' argument, which will affect the parsing of 'default' (i.e. 'not containing a colon') endpoint descriptions, but this behavior is deprecated. """ svc = strports.service("8080", None, "unix") self.assertIsInstance(svc.endpoint, UNIXServerEndpoint) warnings = self.flushWarnings([self.test_serviceDeprecatedDefault]) self.assertEquals(warnings[0]['category'], DeprecationWarning) self.assertEquals( warnings[0]['message'], "The 'default' parameter was deprecated in Twisted 10.2.0. " "Use qualified endpoint descriptions; for example, 'tcp:8080'.") self.assertEquals(len(warnings), 1) # Almost the same case, but slightly tricky - explicitly passing the old # default value, None, also must trigger a deprecation warning. svc = strports.service("tcp:8080", None, None) self.assertIsInstance(svc.endpoint, TCP4ServerEndpoint) warnings = self.flushWarnings([self.test_serviceDeprecatedDefault]) self.assertEquals(warnings[0]['category'], DeprecationWarning) self.assertEquals( warnings[0]['message'], "The 'default' parameter was deprecated in Twisted 10.2.0.") self.assertEquals(len(warnings), 1)
Example #11
Source File: plugin.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def _makeTFTPService(self, tftp_root, tftp_port, rpc_service): """Create the dynamic TFTP service.""" from provisioningserver.rackdservices.tftp import TFTPService tftp_service = TFTPService( resource_root=tftp_root, port=tftp_port, client_service=rpc_service ) tftp_service.setName("tftp") # *** EXPERIMENTAL *** # https://code.launchpad.net/~allenap/maas/tftp-offload/+merge/312146 # If the TFTP port has been set to zero, use the experimental offload # service. Otherwise stick to the normal in-process TFTP service. if tftp_port == 0: from provisioningserver.path import get_maas_data_path from provisioningserver.rackdservices import tftp_offload from twisted.internet.endpoints import UNIXServerEndpoint tftp_offload_socket = get_maas_data_path("tftp-offload.sock") tftp_offload_endpoint = UNIXServerEndpoint( reactor, tftp_offload_socket, wantPID=False ) tftp_offload_service = tftp_offload.TFTPOffloadService( reactor, tftp_offload_endpoint, tftp_service.backend ) tftp_offload_service.setName("tftp-offload") return tftp_offload_service # *** /EXPERIMENTAL *** return tftp_service
Example #12
Source File: fixtures.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def start(self): # Shutdown the RPC service, switch endpoints, then start again. self.rpc.stopService().wait(10) # Ensure there's a shared-secret. self.secret = security.get_shared_secret() # The RPC service uses a list to manage endpoints, but let's check # those assumptions. assert isinstance(self.rpc.endpoints, list) # Patch a fake UNIX endpoint in to the RPC service. endpoint = endpoints.UNIXServerEndpoint(reactor, self.sockfile) self.monkey.add_patch(self.rpc, "endpoints", [[endpoint]]) # The RPC service uses a defaultdict(set) to manage connections, but # let's check those assumptions. assert isinstance(self.rpc.connections, defaultdict) assert self.rpc.connections.default_factory is set # Patch a fake connections dict into place for this fixture's lifetime. self.monkey.add_patch(self.rpc, "connections", defaultdict(set)) # Modify the state of the service. self.monkey.patch() # Start the service back up again. self.rpc.startService().wait(10)
Example #13
Source File: __init__.py From maas with GNU Affero General Public License v3.0 | 4 votes |
def connect(self, cluster, region): """Wire up a connection between cluster and region. Uses a UNIX socket to very rapidly connect the two ends. :type cluster: `twisted.internet.interfaces.IProtocol` :type region: `twisted.internet.interfaces.IProtocol` """ # Wire up the region and cluster protocols via the sockfile. sockfile = path.join(self.sockdir.path, next(self.socknames)) class RegionFactory(Factory): def buildProtocol(self, addr): return region # `doUpdate` has already been called, but with no connections the # mocked `_fetch_rpc_info` caused no `maas_url` to be set on the # RPC service. Set the `maas_url` to the one set on the fixture. self.rpc_service.maas_url = self.maas_url endpoint_region = endpoints.UNIXServerEndpoint(reactor, sockfile) port = yield endpoint_region.listen(RegionFactory()) endpoint_cluster = endpoints.UNIXClientEndpoint(reactor, sockfile) client = yield endpoints.connectProtocol(endpoint_cluster, cluster) # Wait for the client to be fully connected. Because onReady will have # been capped-off by now (see ClusterClient.connectionMade) this will # not raise any exceptions. In some ways this is convenient because it # allows the resulting issues to be encountered within test code. yield client.ready.get() @inlineCallbacks def shutdown(): # We need to make sure that everything is shutdown correctly. TLS # seems to make this even more important: it complains loudly if # connections are not closed cleanly. An interesting article to # read now is Jono Lange's "How to Disconnect in Twisted, Really" # <http://mumak.net/stuff/twisted-disconnect.html>. yield port.loseConnection() yield port.deferred if region.transport is not None: yield region.transport.loseConnection() yield region.onConnectionLost if client.transport is not None: yield client.transport.loseConnection() yield client.onConnectionLost # Fixtures don't wait for deferred work in clean-up tasks (or anywhere # else), so we can't use `self.addCleanup(shutdown)` here. We need to # get the user to add `shutdown` to the clean-up tasks for the *test*, # on the assumption they're using a test framework that accommodates # deferred work (like testtools with `MAASTwistedRunTest`). returnValue(shutdown) # An iterable of names for new dynamically-created AMP protocol factories.