• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python endpoints.serverFromString函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twisted.internet.endpoints.serverFromString函数的典型用法代码示例。如果您正苦于以下问题:Python serverFromString函数的具体用法?Python serverFromString怎么用?Python serverFromString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了serverFromString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

def main():
    config = ConfigParser.ConfigParser()
    config.read(os.path.expanduser('~/.b07'))
    api = b07.api.API(reactor,
                      config.get('ingress', 'email'),
                      config.get('ingress', 'password'))
    

    http_root = Redirect('https://localhost:{}/'.format(config.get('server', 'https_port')))
    http_factory = Site(http_root)
    http_endpoint = endpoints.serverFromString(reactor,
                                               'tcp:{}'.format(config.get('server', 'http_port')))
    http_endpoint.listen(http_factory)

    https_root = File(os.path.expanduser(config.get('server', 'web_root')))
    https_root.indexNames = ['index.html']
    https_factory = Site(https_root)
    https_endpoint = endpoints.serverFromString(reactor,
                                                'ssl:{}:privateKey={}:certKey={}'.format(config.get('server', 'https_port'),
                                                                                         os.path.expanduser(config.get('server', 'ssl_key')),
                                                                                         os.path.expanduser(config.get('server', 'ssl_cert'))))
    https_endpoint.listen(https_factory)

    wsfactory = Factory()
    wsfactory.protocol = WebSocketProtocol
    wss_endpoint = endpoints.serverFromString(reactor,
                                              'ssl:{}:privateKey={}:certKey={}'.format(config.get('server', 'wss_port'),
                                                                                       os.path.expanduser(config.get('server', 'ssl_key')),
                                                                                       os.path.expanduser(config.get('server', 'ssl_cert'))))
    wss_endpoint.listen(txws.WebSocketFactory(wsfactory))



    reactor.run()
开发者ID:drhinehart,项目名称:b07bot,代码行数:34,代码来源:server.py


示例2: main

def main():
        
    log.startLogging(sys.stdout)

    startPort = 3000

    lastServerEndpoint = 'tcp:interface=127.0.0.1:%s' % startPort
    torAgent = TorAgent(reactor)
    serverEndpoint = serverFromString(reactor, lastServerEndpoint)
    connectDeferred = serverEndpoint.listen(AgentProxyFactory(torAgent))

    endpoint = []
    agent = []
    for x in range(10):
        endpoint = clientFromString(reactor, "tcp:127.0.0.1:%s" % (startPort + x))
        proxyAgent = ProxyAgent(endpoint)
        serverEndpoint = serverFromString(reactor, "tcp:interface=127.0.0.1:%s" % (startPort + x + 1))
        
        connectDeferred = serverEndpoint.listen(AgentProxyFactory(proxyAgent))


    # XXX
    def clientConnectionFailed(factory, reason):
        log.err(reason)
        log.err("httpTorProxy: clientConnectionFailed")

    connectDeferred.addErrback(clientConnectionFailed)


    reactor.run()
开发者ID:EricSchles,项目名称:txtorhttpproxy,代码行数:30,代码来源:proxyProxy.py


示例3: __init__

 def __init__(self, reactor, cap_table, http_endpoint, ws_endpoint, root_cap, title):
     # Constants
     self.__http_endpoint_string = str(http_endpoint)
     self.__http_endpoint = endpoints.serverFromString(reactor, self.__http_endpoint_string)
     self.__ws_endpoint = endpoints.serverFromString(reactor, str(ws_endpoint))
     self.__visit_path = _make_cap_url(root_cap)
     
     wcommon = WebServiceCommon(
         reactor=reactor,
         title=title,
         ws_endpoint_string=ws_endpoint)
     # TODO: Create poller actually for the given reactor w/o redundancy -- perhaps there should be a one-poller-per-reactor map
     subscription_context = SubscriptionContext(reactor=reactor, poller=the_poller)
     
     def resource_factory(entry_point):
         # TODO: If not an IWebEntryPoint, return a generic result
         return IWebEntryPoint(entry_point).get_entry_point_resource(wcommon=wcommon)  # pylint: disable=redundant-keyword-arg
     
     server_root = CapAccessResource(cap_table=cap_table, resource_factory=resource_factory)
     _put_root_static(wcommon, server_root)
     
     if UNIQUE_PUBLIC_CAP in cap_table:
         # TODO: consider factoring out "generate URL for cap"
         server_root.putChild('', Redirect(_make_cap_url(UNIQUE_PUBLIC_CAP)))
         
     self.__ws_protocol = txws.WebSocketFactory(
         FactoryWithArgs.forProtocol(OurStreamProtocol, cap_table, subscription_context))
     self.__site = _SiteWithHeaders(server_root)
     
     self.__ws_port_obj = None
     self.__http_port_obj = None
开发者ID:thefinn93,项目名称:shinysdr,代码行数:31,代码来源:app.py


示例4: coerce_to_server_endpoint

def coerce_to_server_endpoint(reactor, ep_descr):
    """Given a string, attempt to produce a server endpoint.

    If the string describes an endpoint directly, we use that; otherwise,
    assume it's an attempt to provide a TCP endpoint and try variations on
    that in the hope that one is parseable.

    Parameters
    ----------
    reactor : `implements twisted.internet.interfaces.IReactorCore`
        Twisted reactor to use in constructing endpoint.
    ep_descr : `str`
        String describing the desired endpoint.
    """
    try:
        # Maybe this already is a valid endpoint.
        return serverFromString(reactor, ep_descr)
    except (ValueError, TypeError):
        pass
    try:
        # Assume it just needs "tcp:" prepended.
        return serverFromString(reactor, f"tcp:{ep_descr}")
    except (ValueError, TypeError):
        # At this point, we'll give up, and go back to the original bad parse.
        serverFromString(reactor, ep_descr)
开发者ID:jdswinbank,项目名称:Comet,代码行数:25,代码来源:endpoint.py


示例5: postOptions

    def postOptions(self):
        strport = self['strport']
        factoryIdentifier = self['factory-identifier']
        if strport is None or factoryIdentifier is None:
            self.opt_help()

        store = self.parent.parent.getStore()
        storeID = int(factoryIdentifier)
        try:
            factory = store.getItemByID(storeID)
        except KeyError:
            print "%d does not identify an item." % (storeID,)
            raise SystemExit(1)
        else:
            if not IProtocolFactoryFactory.providedBy(factory):
                print "%d does not identify a factory." % (storeID,)
                raise SystemExit(1)
            else:
                description = self.decodeCommandLine(strport)
                try:
                    serverFromString(reactor, description.encode('ascii'))
                except ValueError:
                    print "%r is not a valid port description." % (strport,)
                    raise SystemExit(1)
                port = StringEndpointPort(
                    store=store, description=description, factory=factory)
                installOn(port, store)
                print "Created."
        raise SystemExit(0)
开发者ID:fusionapp,项目名称:mantissa,代码行数:29,代码来源:port.py


示例6: main

    def main(self, reactor, options):
        certificates_path = FilePath(options["certificates-directory"])
        ca = Certificate.loadPEM(
            certificates_path.child(b"cluster.crt").getContent())
        # This is a hack; from_path should be more
        # flexible. https://clusterhq.atlassian.net/browse/FLOC-1865
        control_credential = ControlCredential.from_path(
            certificates_path, b"service")

        top_service = MultiService()
        persistence = ConfigurationPersistenceService(
            reactor, options["data-path"])
        persistence.setServiceParent(top_service)
        cluster_state = ClusterStateService(reactor)
        cluster_state.setServiceParent(top_service)
        api_service = create_api_service(
            persistence, cluster_state, serverFromString(
                reactor, options["port"]),
            rest_api_context_factory(ca, control_credential))
        api_service.setServiceParent(top_service)
        amp_service = ControlAMPService(
            reactor, cluster_state, persistence, serverFromString(
                reactor, options["agent-port"]),
            amp_server_context_factory(ca, control_credential))
        amp_service.setServiceParent(top_service)
        return main_for_service(reactor, top_service)
开发者ID:Kaffa-MY,项目名称:flocker,代码行数:26,代码来源:script.py


示例7: __init__

 def __init__(self, relayport, transitport, advertise_version,
              db_url=":memory:", blur_usage=None):
     service.MultiService.__init__(self)
     self._blur_usage = blur_usage
     self.db = get_db(db_url)
     welcome = {
         "current_version": __version__,
         # adding .motd will cause all clients to display the message,
         # then keep running normally
         #"motd": "Welcome to the public relay.\nPlease enjoy this service.",
         #
         # adding .error will cause all clients to fail, with this message
         #"error": "This server has been disabled, see URL for details.",
         }
     if advertise_version:
         welcome["current_version"] = advertise_version
     self.root = Root()
     site = PrivacyEnhancedSite(self.root)
     if blur_usage:
         site.logRequests = False
     r = endpoints.serverFromString(reactor, relayport)
     self.relayport_service = ServerEndpointService(r, site)
     self.relayport_service.setServiceParent(self)
     self.relay = Relay(self.db, welcome, blur_usage) # accessible from tests
     self.root.putChild(b"wormhole-relay", self.relay)
     if transitport:
         self.transit = Transit(self.db, blur_usage)
         self.transit.setServiceParent(self) # for the timer
         t = endpoints.serverFromString(reactor, transitport)
         self.transport_service = ServerEndpointService(t, self.transit)
         self.transport_service.setServiceParent(self)
开发者ID:joejoeknight,项目名称:magic-wormhole,代码行数:31,代码来源:server.py


示例8: __init__

 def __init__(self, reactor, cap_table, read_only_dbs, writable_db, http_endpoint, ws_endpoint, root_cap, title, flowgraph_for_debug):
     # Constants
     self.__http_endpoint_string = http_endpoint
     self.__http_endpoint = endpoints.serverFromString(reactor, http_endpoint)
     self.__ws_endpoint = endpoints.serverFromString(reactor, ws_endpoint)
     self.__visit_path = _make_cap_url(root_cap)
     
     wcommon = WebServiceCommon(ws_endpoint_string=ws_endpoint)
     
     def BoundSessionResource(session):
         return SessionResource(session, wcommon, reactor, title, read_only_dbs, writable_db, flowgraph_for_debug)
     
     server_root = CapAccessResource(cap_table=cap_table, resource_ctor=BoundSessionResource)
     _put_root_static(server_root)
     
     if UNIQUE_PUBLIC_CAP in cap_table:
         # TODO: consider factoring out "generate URL for cap"
         server_root.putChild('', Redirect(_make_cap_url(UNIQUE_PUBLIC_CAP)))
         
     self.__ws_protocol = txws.WebSocketFactory(
         FactoryWithArgs.forProtocol(OurStreamProtocol, cap_table))
     self.__site = _SiteWithHeaders(server_root)
     
     self.__ws_port_obj = None
     self.__http_port_obj = None
开发者ID:bitglue,项目名称:shinysdr,代码行数:25,代码来源:app.py


示例9: main

def main():
    options = docopt.docopt(__doc__)
    port = int(options['<port>'])
    rate = float(options['<rate>'])
    label = options['<label>']

    endpoints.serverFromString(reactor, "tcp:%d" % port).listen(SampleFactory(rate, label))
    reactor.run()
开发者ID:JeffRoy,项目名称:ooi_port_agent,代码行数:8,代码来源:rsn_simulator.py


示例10: do_listen

    def do_listen(self, addr):
        if not hasattr(self, "isClient") or not self.isClient:
            self.isClient = False
        else:
            self.error("this is a client, doesn't support listen")
            return

        self._readHistoryFile('.peagunServer')
        serverFromString(reactor, addr).listen(self.connectionManager)
开发者ID:weijiayun,项目名称:Json,代码行数:9,代码来源:PeagunCmd.py


示例11: start

def start():
    game = MultisnakeServer()

    server_update = task.LoopingCall(game.update)
    server_update.start(1.0)

    endpoints.serverFromString(reactor, "tcp:1234").listen(PlayerConnectionFactory(game))

    reactor.run()
开发者ID:nelseric,项目名称:multisnake,代码行数:9,代码来源:network_server.py


示例12: __init__

    def __init__(self, rendezvous_web_port, transit_port,
                 advertise_version, db_url=":memory:", blur_usage=None,
                 signal_error=None):
        service.MultiService.__init__(self)
        self._blur_usage = blur_usage

        db = get_db(db_url)
        welcome = {
            # The primary (python CLI) implementation will emit a message if
            # its version does not match this key. If/when we have
            # distributions which include older version, but we still expect
            # them to be compatible, stop sending this key.
            "current_cli_version": __version__,

            # adding .motd will cause all clients to display the message,
            # then keep running normally
            #"motd": "Welcome to the public relay.\nPlease enjoy this service.",

            # adding .error will cause all clients to fail, with this message
            #"error": "This server has been disabled, see URL for details.",
            }
        if advertise_version:
            welcome["current_cli_version"] = advertise_version
        if signal_error:
            welcome["error"] = signal_error

        rendezvous = Rendezvous(db, welcome, blur_usage)
        rendezvous.setServiceParent(self) # for the pruning timer

        root = Root()
        wsrf = WebSocketRendezvousFactory(None, rendezvous)
        root.putChild(b"v1", WebSocketResource(wsrf))

        site = PrivacyEnhancedSite(root)
        if blur_usage:
            site.logRequests = False

        r = endpoints.serverFromString(reactor, rendezvous_web_port)
        rendezvous_web_service = ServerEndpointService(r, site)
        rendezvous_web_service.setServiceParent(self)

        if transit_port:
            transit = Transit(db, blur_usage)
            transit.setServiceParent(self) # for the timer
            t = endpoints.serverFromString(reactor, transit_port)
            transit_service = ServerEndpointService(t, transit)
            transit_service.setServiceParent(self)

        # make some things accessible for tests
        self._db = db
        self._rendezvous = rendezvous
        self._root = root
        self._rendezvous_web_service = rendezvous_web_service
        self._rendezvous_websocket = wsrf
        if transit_port:
            self._transit = transit
            self._transit_service = transit_service
开发者ID:derwolfe,项目名称:magic-wormhole,代码行数:57,代码来源:server.py


示例13: born

 def born(self, data):
     """Method initiate TCL and UDP listeners."""
     lc = LoopingCall(get_metrics, None)
     lc.start(2)
     reactor.listenUDP(self.UDP_PORT, NotificationUDPProcessor())
     reactor.listenMulticast(self.MULTICAST_PORT,
                             MunticastNotificationProcessor(self.MULTICAST_IP), # add multicast 'born' processing
                             listenMultiple=True)
     endpoints.serverFromString(reactor, "tcp:21999").listen(EchoFactory())
开发者ID:adyachok,项目名称:distributed-systems-study,代码行数:9,代码来源:host_fsm.py


示例14: serve_forever

def serve_forever(port=9999):
    """Process incoming requests from the given socket.

    :param port: The port to listen on
    :type port: int
    """
    endpoints.serverFromString(reactor, "tcp:{}".format(port)).listen(
        MemcachedProtocolFactory()
    )
    reactor.run()
开发者ID:etscrivner,项目名称:pymemcache,代码行数:10,代码来源:server.py


示例15: start_server

def start_server():
    factory = KnowledgeFactory()

    endpoints.serverFromString(
        reactor, "tcp:%s" % config.SERVER_PORT).listen(factory)

    logging.info("server started on port %d", config.SERVER_PORT)
    reactor.run()
    reactor.callLater(100, reactor.stop)
    logging.info("server execution ended")
开发者ID:andreea-lucau,项目名称:talk-twisted-to-me,代码行数:10,代码来源:server.py


示例16: main

def main(amqp_host, max_vms, intf):
	#_install_sig_handlers()

	virt_ip = netifaces.ifaddresses('virbr2')[2][0]['addr']
	endpoints.serverFromString(reactor, "tcp:55555:interface={}".format(virt_ip)).listen(GuestCommsFactory())

	slave = Slave.instance(amqp_host, max_vms, intf)
	reactor.callWhenRunning(slave.start)
	reactor.addSystemEventTrigger("during", "shutdown", Slave.instance().stop)
	reactor.run()
开发者ID:optiv-labs,项目名称:talus,代码行数:10,代码来源:__init__.py


示例17: create_endpoint_services

def create_endpoint_services(reactor, parent, listen_endpoints, factory):
    for listen_endpoint in listen_endpoints:

        # work around http://twistedmatrix.com/trac/ticket/8422
        if sys.version_info.major < 3:
            endpoint = endpoints.serverFromString(reactor, listen_endpoint.encode('utf-8'))
        else:
            endpoint = endpoints.serverFromString(reactor, listen_endpoint)

        service = internet.StreamServerEndpointService(endpoint, factory)
        # FIXME: Use addService on parent ?
        service.setServiceParent(parent)
开发者ID:Mato-Z,项目名称:cowrie,代码行数:12,代码来源:utils.py


示例18: main

def main():
    bind_address = "0.0.0.0"
    gateway_port = 5001
    logger.debug("start gateway server(%s:%d)" % (bind_address, gateway_port))

    # reactor.listenTCP(gateway_port, GatewayFactory(), 100, bind_address)
    endpoints.serverFromString(reactor, "tcp:%d" % gateway_port).listen(GatewayFactory())

    try:
        reactor.run()
    except KeyboardInterrupt:
        logger.error("stop gateway server")
开发者ID:zzragida,项目名称:PythonExamples,代码行数:12,代码来源:server.py


示例19: start_http

def start_http():
    #http in reactor
    root = Resource()
    root.putChild("register", RegisterHTTP())
    root.putChild("data", ICBCHTTP())

    endpoints.serverFromString(reactor, "tcp:8000").listen(server.Site(root))
    #tcp in reactor
    ICBCEndpoint = endpoints.serverFromString(reactor, "tcp:8800")
    ICBCEndpoint.listen(ICBCFactory())
    #start the reactor
    reactor.run(installSignalHandlers=0)
开发者ID:lq08025107,项目名称:pyspider,代码行数:12,代码来源:HTTPServer.py


示例20: startService

 def startService(self):
     if self.port_s is not None:
         endpoint = serverFromString(reactor, self.port_s)
         d = endpoint.listen(self.site)
         d.addCallback(self.register_port, 'app')
     if self.authInfoEndpointStr is not None:
         authInfoApp = AuthInfoApp()
         self.authInfoApp = authInfoApp
         authInfoSite = Site(authInfoApp.app.resource())
         endpoint = serverFromString(reactor, self.authInfoEndpointStr)
         d2 = endpoint.listen(authInfoSite)
         d2.addCallback(self.register_port, 'authInfoSite')
开发者ID:dizzy,项目名称:txcasproxy,代码行数:12,代码来源:service.py



注:本文中的twisted.internet.endpoints.serverFromString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python epollreactor.install函数代码示例发布时间:2022-05-27
下一篇:
Python endpoints.connectProtocol函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap