本文整理匯總了Python中twisted.internet.endpoints.UNIXServerEndpoint方法的典型用法代碼示例。如果您正苦於以下問題:Python endpoints.UNIXServerEndpoint方法的具體用法?Python endpoints.UNIXServerEndpoint怎麽用?Python endpoints.UNIXServerEndpoint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.internet.endpoints
的用法示例。
在下文中一共展示了endpoints.UNIXServerEndpoint方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: createServerEndpoint
# 需要導入模塊: from twisted.internet import endpoints [as 別名]
# 或者: from twisted.internet.endpoints import UNIXServerEndpoint [as 別名]
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)
示例2: test_unix
# 需要導入模塊: from twisted.internet import endpoints [as 別名]
# 或者: from twisted.internet.endpoints import UNIXServerEndpoint [as 別名]
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)
示例3: createServerEndpoint
# 需要導入模塊: from twisted.internet import endpoints [as 別名]
# 或者: from twisted.internet.endpoints import UNIXServerEndpoint [as 別名]
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)
示例4: test_unix
# 需要導入模塊: from twisted.internet import endpoints [as 別名]
# 或者: from twisted.internet.endpoints import UNIXServerEndpoint [as 別名]
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)
示例5: server
# 需要導入模塊: from twisted.internet import endpoints [as 別名]
# 或者: from twisted.internet.endpoints import UNIXServerEndpoint [as 別名]
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)
示例6: startService
# 需要導入模塊: from twisted.internet import endpoints [as 別名]
# 或者: from twisted.internet.endpoints import UNIXServerEndpoint [as 別名]
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__
)
示例7: test_serviceDeprecatedDefault
# 需要導入模塊: from twisted.internet import endpoints [as 別名]
# 或者: from twisted.internet.endpoints import UNIXServerEndpoint [as 別名]
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)
示例8: _makeTFTPService
# 需要導入模塊: from twisted.internet import endpoints [as 別名]
# 或者: from twisted.internet.endpoints import UNIXServerEndpoint [as 別名]
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
示例9: start
# 需要導入模塊: from twisted.internet import endpoints [as 別名]
# 或者: from twisted.internet.endpoints import UNIXServerEndpoint [as 別名]
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)
示例10: connect
# 需要導入模塊: from twisted.internet import endpoints [as 別名]
# 或者: from twisted.internet.endpoints import UNIXServerEndpoint [as 別名]
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.