本文整理汇总了Python中twisted.application.internet.StreamServerEndpointService方法的典型用法代码示例。如果您正苦于以下问题:Python internet.StreamServerEndpointService方法的具体用法?Python internet.StreamServerEndpointService怎么用?Python internet.StreamServerEndpointService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.application.internet
的用法示例。
在下文中一共展示了internet.StreamServerEndpointService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: service
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def service(description, factory, reactor=None):
"""
Return the service corresponding to a description.
@param description: The description of the listening port, in the syntax
described by L{twisted.internet.endpoints.serverFromString}.
@type description: C{str}
@param factory: The protocol factory which will build protocols for
connections to this service.
@type factory: L{twisted.internet.interfaces.IProtocolFactory}
@rtype: C{twisted.application.service.IService}
@return: the service corresponding to a description of a reliable stream
server.
@see: L{twisted.internet.endpoints.serverFromString}
"""
if reactor is None:
from twisted.internet import reactor
svc = StreamServerEndpointService(
endpoints.serverFromString(reactor, description), factory)
svc._raiseSynchronously = True
return svc
示例2: test_sshPort
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def test_sshPort(self):
"""
L{manhole_tap.makeService} will make a SSH service on the port
defined by C{--sshPort}. It will not make a telnet service.
"""
# Why the sshKeyDir and sshKeySize params? To prevent it stomping over
# (or using!) the user's private key, we just make a super small one
# which will never be used in a temp directory.
self.options.parseOptions(["--sshKeyDir", self.mktemp(),
"--sshKeySize", "512",
"--sshPort", "tcp:223"])
service = manhole_tap.makeService(self.options)
self.assertIsInstance(service, MultiService)
self.assertEqual(len(service.services), 1)
self.assertIsInstance(service.services[0], StreamServerEndpointService)
self.assertIsInstance(service.services[0].factory,
manhole_ssh.ConchFactory)
self.assertEqual(service.services[0].endpoint._port, 223)
示例3: test_service
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def test_service(self):
"""
L{strports.service} returns a L{StreamServerEndpointService}
constructed with an endpoint produced from
L{endpoint.serverFromString}, using the same syntax.
"""
reactor = object() # the cake is a lie
aFactory = Factory()
aGoodPort = 1337
svc = strports.service(
'tcp:' + str(aGoodPort), aFactory, reactor=reactor)
self.assertIsInstance(svc, internet.StreamServerEndpointService)
# See twisted.application.test.test_internet.EndpointServiceTests.
# test_synchronousRaiseRaisesSynchronously
self.assertTrue(svc._raiseSynchronously)
self.assertIsInstance(svc.endpoint, TCP4ServerEndpoint)
# Maybe we should implement equality for endpoints.
self.assertEqual(svc.endpoint._port, aGoodPort)
self.assertIs(svc.factory, aFactory)
self.assertIs(svc.endpoint._reactor, reactor)
示例4: test_service
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def test_service(self):
"""
L{strports.service} returns a L{StreamServerEndpointService}
constructed with an endpoint produced from
L{endpoint.serverFromString}, using the same syntax.
"""
reactor = object() # the cake is a lie
aFactory = Factory()
aGoodPort = 1337
svc = strports.service(
'tcp:'+str(aGoodPort), aFactory, reactor=reactor)
self.assertIsInstance(svc, internet.StreamServerEndpointService)
# See twisted.application.test.test_internet.TestEndpointService.
# test_synchronousRaiseRaisesSynchronously
self.assertEquals(svc._raiseSynchronously, True)
self.assertIsInstance(svc.endpoint, TCP4ServerEndpoint)
# Maybe we should implement equality for endpoints.
self.assertEquals(svc.endpoint._port, aGoodPort)
self.assertIdentical(svc.factory, aFactory)
self.assertIdentical(svc.endpoint._reactor, reactor)
示例5: test_makeService
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def test_makeService(self):
"""
The service gets set up with a router and factory.
"""
opt = tap.Options()
opt.parseOptions([])
s = tap.makeService(opt)
self.assertIsInstance(s, internet.StreamServerEndpointService)
self.assertEqual('127.0.0.1', s.endpoint._interface)
self.assertEqual(5347, s.endpoint._port)
factory = s.factory
self.assertIsInstance(factory, component.XMPPComponentServerFactory)
self.assertIsInstance(factory.router, component.Router)
self.assertEqual('secret', factory.secret)
self.assertFalse(factory.logTraffic)
示例6: test_telnetPort
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def test_telnetPort(self):
"""
L{manhole_tap.makeService} will make a telnet service on the port
defined by C{--telnetPort}. It will not make a SSH service.
"""
self.options.parseOptions(["--telnetPort", "tcp:222"])
service = manhole_tap.makeService(self.options)
self.assertIsInstance(service, MultiService)
self.assertEqual(len(service.services), 1)
self.assertIsInstance(service.services[0], StreamServerEndpointService)
self.assertIsInstance(service.services[0].factory.protocol,
manhole_tap.makeTelnetProtocol)
self.assertEqual(service.services[0].endpoint._port, 222)
示例7: __init__
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def __init__(self, reactor, cluster_state, configuration_service, endpoint,
context_factory):
"""
:param reactor: See ``ControlServiceLocator.__init__``.
:param ClusterStateService cluster_state: Object that records known
cluster state.
:param ConfigurationPersistenceService configuration_service:
Persistence service for desired cluster configuration.
:param endpoint: Endpoint to listen on.
:param context_factory: TLS context factory.
"""
self._connections = set()
self._reactor = reactor
self._connections_pending_update = set()
self._current_pending_update_delayed_call = None
self._current_command = {}
self._last_received_generation = defaultdict(
lambda: _ConfigAndStateGeneration()
)
self._configuration_generation_tracker = GenerationTracker(100)
self._state_generation_tracker = GenerationTracker(100)
self.cluster_state = cluster_state
self.configuration_service = configuration_service
self.endpoint_service = StreamServerEndpointService(
endpoint,
TLSMemoryBIOFactory(
context_factory,
False,
ServerFactory.forProtocol(lambda: ControlAMP(reactor, self))
)
)
# When configuration changes, notify all connected clients:
self.configuration_service.register(self._schedule_broadcast_update)
示例8: create_api_service
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def create_api_service(persistence_service, cluster_state_service, endpoint,
context_factory, clock=reactor):
"""
Create a Twisted Service that serves the API on the given endpoint.
:param ConfigurationPersistenceService persistence_service: Service
for retrieving and setting desired configuration.
:param ClusterStateService cluster_state_service: Service that
knows about the current state of the cluster.
:param endpoint: Twisted endpoint to listen on.
:param context_factory: TLS context factory.
:param IReactorTime clock: The clock to use for time. By default
global reactor.
:return: Service that will listen on the endpoint using HTTP API server.
"""
api_root = Resource()
user = ConfigurationAPIUserV1(persistence_service, cluster_state_service,
clock)
api_root.putChild('v1', user.app.resource())
api_root._v1_user = user # For unit testing purposes, alas
return StreamServerEndpointService(
endpoint,
TLSMemoryBIOFactory(
context_factory,
False,
Site(api_root)
)
)
示例9: test_start_service
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def test_start_service(self):
"""
Starting the service listens with a factory that creates
``ControlAMP`` instances pointing at the service.
"""
service = build_control_amp_service(self)
initial = service.endpoint_service.running
service.startService()
control_factory = service.endpoint_service.factory.wrappedFactory
protocol = control_factory.buildProtocol(None)
self.assertEqual(
(initial, service.endpoint_service.running,
service.endpoint_service.__class__,
protocol.__class__, protocol.control_amp_service),
(False, True, StreamServerEndpointService, ControlAMP, service))
示例10: main
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def main(self, reactor, options):
# We can use /etc/flocker/agent.yml and /etc/flocker/node.crt to load
# some information we need:
agent_config = get_configuration(options)
control_host = agent_config['control-service']['hostname']
certificates_path = options["agent-config"].parent()
control_port = options["rest-api-port"]
flocker_client = FlockerClient(reactor, control_host, control_port,
certificates_path.child(b"cluster.crt"),
certificates_path.child(b"plugin.crt"),
certificates_path.child(b"plugin.key"))
self._create_listening_directory(PLUGIN_PATH.parent())
# Get the node UUID, and then start up:
# Retry on *all* errors.
getting_id = retry_failure(
reactor=reactor,
function=flocker_client.this_node_uuid,
steps=backoff()
)
def run_service(node_id):
endpoint = serverFromString(
reactor, "unix:{}:mode=600".format(PLUGIN_PATH.path))
service = StreamServerEndpointService(endpoint, Site(
VolumePlugin(reactor, flocker_client, node_id).app.resource()))
return main_for_service(reactor, service)
getting_id.addCallback(run_service)
return getting_id
示例11: test_basic
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def test_basic(self):
"""
L{tap.makeService} returns a L{StreamServerEndpointService} instance
running on TCP port 22, and the linked protocol factory is an instance
of L{OpenSSHFactory}.
"""
config = tap.Options()
service = tap.makeService(config)
self.assertIsInstance(service, StreamServerEndpointService)
self.assertEqual(service.endpoint._port, 22)
self.assertIsInstance(service.factory, OpenSSHFactory)
示例12: __init__
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def __init__(self, basedir, reactor):
service.MultiService.__init__(self)
self._basedir = basedir
self._reactor = reactor
root = Root()
site = server.Site(root)
ep = endpoints.serverFromString(reactor, "tcp:8220")
internet.StreamServerEndpointService(ep, site).setServiceParent(self)
self._jm = journal.JournalManager(self._save_state)
root.putChild(b"", static.Data("root", "text/plain"))
root.putChild(b"list-invitations", Status(self._list_invitations))
root.putChild(b"invite", Action(self._invite)) # {petname:}
root.putChild(b"accept", Action(self._accept)) # {petname:, code:}
self._state_fn = os.path.join(self._basedir, "state.json")
self._state = State.from_filename(self._state_fn)
self._wormholes = {}
for iid, invitation_state in self._state.get_all_invitations().items():
def _dispatch(event, *args, **kwargs):
self._dispatch_wormhole_event(iid, event, *args, **kwargs)
w = wormhole.journaled_from_data(invitation_state["wormhole"],
reactor=self._reactor,
journal=self._jm,
event_handler=self,
event_handler_args=(iid,))
self._wormholes[iid] = w
w.setServiceParent(self)
示例13: _setup_relay
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def _setup_relay(self, error, advertise_version=None):
self.sp = service.MultiService()
self.sp.startService()
# need to talk to twisted team about only using unicode in
# endpoints.serverFromString
db = create_channel_db(":memory:")
self._usage_db = create_usage_db(":memory:")
self._rendezvous = make_server(
db,
advertise_version=advertise_version,
signal_error=error,
usage_db=self._usage_db)
ep = endpoints.TCP4ServerEndpoint(reactor, 0, interface="127.0.0.1")
site = make_web_server(self._rendezvous, log_requests=False)
# self._lp = yield ep.listen(site)
s = MyInternetService(ep, site)
s.setServiceParent(self.sp)
self.rdv_ws_port = yield s.getPort()
self._relay_server = s
# self._rendezvous = s._rendezvous
self.relayurl = u"ws://127.0.0.1:%d/v1" % self.rdv_ws_port
# ws://127.0.0.1:%d/wormhole-relay/ws
self.transitport = allocate_tcp_port()
ep = endpoints.serverFromString(
reactor, "tcp:%d:interface=127.0.0.1" % self.transitport)
self._transit_server = f = Transit(
blur_usage=None, log_file=None, usage_db=None)
internet.StreamServerEndpointService(ep, f).setServiceParent(self.sp)
self.transit = u"tcp:127.0.0.1:%d" % self.transitport
示例14: test_makeService
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def test_makeService(self):
"""
The service gets set up with a router and factory.
"""
opt = tap.Options()
opt.parseOptions([])
s = tap.makeService(opt)
self.assertIsInstance(s, internet.StreamServerEndpointService)
self.assertEquals('127.0.0.1', s.endpoint._interface)
self.assertEquals(5347, s.endpoint._port)
factory = s.factory
self.assertIsInstance(factory, component.XMPPComponentServerFactory)
self.assertIsInstance(factory.router, component.Router)
self.assertEquals('secret', factory.secret)
self.assertFalse(factory.logTraffic)
示例15: test_basic
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import StreamServerEndpointService [as 别名]
def test_basic(self):
"""
L{tap.makeService} returns a L{StreamServerEndpointService} instance
running on TCP port 22, and the linked protocol factory is an instance
of L{OpenSSHFactory}.
"""
config = tap.Options()
service = tap.makeService(config)
self.assertIsInstance(service, StreamServerEndpointService)
self.assertEquals(service.endpoint._port, 22)
self.assertIsInstance(service.factory, OpenSSHFactory)