本文整理汇总了Python中twisted.application.internet.StreamServerEndpointService类的典型用法代码示例。如果您正苦于以下问题:Python StreamServerEndpointService类的具体用法?Python StreamServerEndpointService怎么用?Python StreamServerEndpointService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StreamServerEndpointService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeService
def makeService(options):
"""
Construct a Pantheon SSH service.
"""
from twisted.internet import reactor
factory = SSHFactory()
key = options["host-key"]
factory.privateKeys = {key.sshType(): key}
factory.publicKeys = {key.sshType(): key.public()}
realm = PantheonRealm(
reactor,
options['auth-host'], options['auth-port'],
options['client-key'].path, options['client-cert'].path)
checker = PantheonHTTPChecker(
reactor,
options['auth-host'], options['auth-port'],
options['client-key'].path, options['client-cert'].path)
factory.portal = Portal(realm, [checker])
service = MultiService()
for endpoint in options["listen"]:
child = StreamServerEndpointService(endpoint, factory)
child.setServiceParent(service)
return service
示例2: service
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
示例3: setup
def setup(self):
# initialize storage
# doing it here because it's needed by the server factory
storage.init(self.config['database'])
# TODO from configuration
stor_class = self.config['storage']['class']
klass = getattr(storage, stor_class)
self.storage = klass(*self.config['storage']['params'])
self.keyring = keyring.Keyring(storage.MySQLNetworkStorage(), self.config['fingerprint'], self.network, self.servername, disable_cache=True)
token_auth = auth.AuthKontalkChecker(self.config['fingerprint'], self.keyring)
# upload endpoint
portal = Portal(FileUploadRealm(self), [token_auth])
resource = HTTPSAuthSessionWrapper(portal, auth.KontalkCertificate)
self.putChild('upload', resource)
# download endpoint
portal = Portal(FileDownloadRealm(self), [token_auth])
resource = HTTPSAuthSessionWrapper(portal, auth.KontalkCertificate)
self.putChild('download', resource)
# http service
self.factory = server.Site(self)
sslFactory = MyOpenSSLCertificateOptions(self.config['ssl_key'], self.config['ssl_cert'], self._sslVerify)
endpoint = SSL4ServerEndpoint(reactor, self.config['bind'][1], sslFactory, interface=str(self.config['bind'][0]))
svc = StreamServerEndpointService(endpoint, self.factory)
svc._raiseSynchronously = True
return svc
示例4: makeBroadcasterService
def makeBroadcasterService(endpoint, local_ivo, test_interval, whitelist):
"""Create a VOEvent receiver service.
The receiver service accepts VOEvent messages submitted to the broker by
authors.
Parameters
----------
endpoint : implements `twisted.internet.interfaces.IStreamServerEndpoint`
The endpoint to which the service will listen.
local_ivo : `str`
IVOA identifier for the subscriber.
test_interval: `int`
The interval in seconds between test events to be broadcast. If ``0``,
no test events will be sent.
whitelist : `list` of `ipaddress.IPv4Network` or `ipaddress.IPv6Network`
Only addresses which fall in a network included in the whitelist are
permitted to subscribe.
"""
factory = VOEventBroadcasterFactory(local_ivo, test_interval)
if log.LEVEL >= log.Levels.INFO:
factory.noisy = False
whitelisting_factory = WhitelistingFactory(factory, whitelist,
"subscription")
if log.LEVEL >= log.Levels.INFO:
whitelisting_factory.noisy = False
service = StreamServerEndpointService(endpoint, whitelisting_factory)
# Shut down, rather than simply logging an error, if we can't bind.
service._raiseSynchronously = True
return service
示例5: setup
def setup(self):
# initialize storage
# doing it here because it's needed by the c2s server factory
storage.init(self.config['database'])
self.presencedb = storage.MySQLPresenceStorage()
try:
stanza_expire = self.config['stanza_expire']
except KeyError:
stanza_expire = 0
self.stanzadb = storage.MySQLStanzaStorage(stanza_expire)
try:
validation_expire = self.config['registration']['expire']
except KeyError:
validation_expire = 0
self.validationdb = storage.MySQLUserValidationStorage(validation_expire)
self.keyring = keyring.Keyring(storage.MySQLNetworkStorage(), self.config['fingerprint'], self.network, self.servername)
authrealm = auth.SASLRealm("Kontalk")
authportal = portal.Portal(authrealm, [auth.AuthKontalkChecker(self.config['fingerprint'], self.keyring, self._verify_fingerprint)])
self.sfactory = XMPPServerFactory(authportal, self, self.network, self.servername)
self.sfactory.logTraffic = self.config['debug']
if 'ssl_key' in self.config and 'ssl_cert' in self.config:
self.sfactory.loadPEM(self.config['ssl_cert'], self.config['ssl_key'])
services = []
if 'plain' in self.config['bind']:
plain_svc = strports.service('tcp:' + str(self.config['bind']['plain'][1]) +
':interface=' + str(self.config['bind']['plain'][0]), self.sfactory)
services.append(plain_svc)
if 'ssl' in self.config['bind']:
ssl_svc = internet.SSLServer(port=int(self.config['bind']['ssl'][1]),
interface=str(self.config['bind']['ssl'][0]),
factory=self.sfactory,
contextFactory=self.sfactory.getSSLContext())
services.append(ssl_svc)
if 'tls' in self.config['bind']:
cert = OpenPGPCertificate(open(self.config['pgp_cert']).read())
key = OpenPGPPrivateKey(open(self.config['pgp_key']).read())
cred = auth.OpenPGPKontalkCredentials(cert, key, str(self.config['pgp_keyring']))
cred.verify_peer = True
tls_svc = StreamServerEndpointService(
tls.TLSServerEndpoint(reactor=reactor,
port=int(self.config['bind']['tls'][1]),
interface=str(self.config['bind']['tls'][0]),
credentials=cred),
self.sfactory)
tls_svc._raiseSynchronously = True
services.append(tls_svc)
return services
示例6: __init__
def __init__(self, res):
'''
Initialization of UPnP server
'''
self.resource = res
# self.resource = static.File(
# '/home/babe/Projets/eclipse/onDemand/src/web/')
edp = endpoints.serverFromString(reactor, b'tcp:0')
StreamServerEndpointService.__init__(
self, edp, server.Site(self.resource))
self._choosenPort = None
示例7: __init__
def __init__(self, device):
'''
Initialization of UPnP server
'''
self.upnp = UPnP(device)
self.device = device
self.upnp.parent = self
self.site = server.Site(self.upnp)
edp = endpoints.serverFromString(reactor, "tcp:0")
StreamServerEndpointService.__init__(self, edp, self.site)
self._choosenPort = None
示例8: __init__
def __init__(self, config):
SimarglClient.__init__(self, config)
from twisted.internet import reactor
self.factory = SimarglServerFactory(self)
StreamServerEndpointService.__init__(
self,
TCP4ServerEndpoint(reactor, int(config.get('port', 9666)), interface=config.get('host')),
self.factory
)
示例9: GoApiWorker
class GoApiWorker(BaseWorker):
class CONFIG_CLASS(BaseWorker.CONFIG_CLASS):
worker_name = ConfigText(
"Name of this Go API worker.", required=True, static=True)
twisted_endpoint = ConfigServerEndpoint(
"Twisted endpoint to listen on.", required=True, static=True)
web_path = ConfigText(
"The path to serve this resource on.", required=True, static=True)
health_path = ConfigText(
"The path to server the health resource on.", default='/health/',
static=True)
redis_manager = ConfigDict(
"Redis client configuration.", default={}, static=True)
riak_manager = ConfigDict(
"Riak client configuration.", default={}, static=True)
_web_service = None
def _rpc_resource_for_user(self, username):
rpc = GoApiServer(username, self.vumi_api)
addIntrospection(rpc)
return rpc
def get_health_response(self):
return "OK"
@inlineCallbacks
def setup_worker(self):
config = self.get_static_config()
self.vumi_api = yield VumiApi.from_config_async({
'redis_manager': config.redis_manager,
'riak_manager': config.riak_manager,
})
self.realm = GoUserRealm(self._rpc_resource_for_user)
site = build_web_site({
config.web_path: GoUserAuthSessionWrapper(
self.realm, self.vumi_api),
config.health_path: httprpc.HttpRpcHealthResource(self),
})
self._web_service = StreamServerEndpointService(
config.twisted_endpoint, site)
self._web_service.startService()
@inlineCallbacks
def teardown_worker(self):
if self._web_service is not None:
yield self._web_service.stopService()
def setup_connectors(self):
pass
示例10: startService
def startService(self):
MultiService.startService(self)
staticPath = FilePath(__file__).sibling("static")
root = NoListDirFile(staticPath.path)
root.putChild('api', SockJSResource(
Factory.forProtocol(DaneDoctorProtocol))
)
webService = StreamServerEndpointService(
serverFromString(self._reactor, "tcp:8080"),
Site(root)
)
webService.setServiceParent(self)
示例11: __init__
def __init__(self, device):
'''
Initialization of UPnP server
'''
self.upnp = UPnP(device)
self.devices = [device]
device.parent = self
self.upnp.parent = self
self.site = server.Site(self.upnp)
edp = endpoints.serverFromString(reactor, "tcp:0")
StreamServerEndpointService.__init__(self, edp, self.site)
self._choosenPort = None
for service in device.services:
service.control_resource = TwistedWebResource(service.app)
service.event_resource = ServiceEventResource(service)
service.resource = ServiceResource(service)
示例12: __init__
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.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)
示例13: setUp
def setUp(self):
"""
Construct a stub server, a stub factory, and a
L{StreamServerEndpointService} to test.
"""
self.fakeServer = FakeServer()
self.factory = Factory()
self.svc = StreamServerEndpointService(self.fakeServer, self.factory)
示例14: service
def service(description, factory, default=_DEFAULT, 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.server}.
@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}
@type default: C{str} or C{None}
@param default: Do not use this parameter. It has been deprecated since
Twisted 10.2.0.
@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
if default is _DEFAULT:
default = None
else:
message = "The 'default' parameter was deprecated in Twisted 10.2.0."
if default is not None:
message += (
" Use qualified endpoint descriptions; for example, "
"'tcp:%s'." % (description,))
warnings.warn(
message=message, category=DeprecationWarning, stacklevel=2)
svc = StreamServerEndpointService(
endpoints._serverFromStringLegacy(reactor, description, default),
factory)
svc._raiseSynchronously = True
return svc
示例15: makeReceiverService
def makeReceiverService(endpoint, local_ivo, validators, handlers, whitelist):
"""Create a VOEvent receiver service.
The receiver service accepts VOEvent messages submitted to the broker by
authors.
Parameters
----------
endpoint : implements `twisted.internet.interfaces.IStreamServerEndpoint`
The endpoint to which the service will listen.
local_ivo : `str`
IVOA identifier for the subscriber.
validators : `list` of implementers of `~comet.icomet.IValidator`.
Validators which will be applied to incoming events. Events which fail
validation will be rejected.
handlers : `list` of implementers of `~comet.icomet.IHandler`.
Handlers to which events which pass validation will be passed.
whitelist : `list` of `ipaddress.IPv4Network` or `ipaddress.IPv6Network`
Submissions are only accepted from addresses which fall in a network
included in the whitelist.
Warnings
--------
Although a non-TCP endpoint can be specified (a Unix domain socket, for
example), the whitelist won't be applied to it correctly (indeed, it will
probably break horribly).
"""
factory = VOEventReceiverFactory(local_ivo=local_ivo,
validators=validators,
handlers=handlers)
if log.LEVEL >= log.Levels.INFO:
factory.noisy = False
whitelisting_factory = WhitelistingFactory(factory, whitelist, "submission")
if log.LEVEL >= log.Levels.INFO:
whitelisting_factory.noisy = False
service = StreamServerEndpointService(endpoint, whitelisting_factory)
# Shut down, rather than simply logging an error, if we can't bind.
service._raiseSynchronously = True
return service