当前位置: 首页>>代码示例>>Python>>正文


Python endpoints.TCP4ServerEndpoint方法代码示例

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


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

示例1: createServerEndpoint

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def createServerEndpoint(self, reactor, factory, **listenArgs):
        """
        Create an L{TCP4ServerEndpoint} and return the values needed to verify
        its behaviour.

        @param reactor: A fake L{IReactorTCP} that L{TCP4ServerEndpoint} can
            call L{IReactorTCP.listenTCP} 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{IReactorTCP.listenTCP}.
        """
        address = IPv4Address("TCP", "0.0.0.0", 0)

        if listenArgs is None:
            listenArgs = {}

        return (endpoints.TCP4ServerEndpoint(reactor,
                                             address.port,
                                             **listenArgs),
                (address.port, factory,
                 listenArgs.get('backlog', 50),
                 listenArgs.get('interface', '')),
                address) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_endpoints.py

示例2: test_service

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_strports.py

示例3: connectableEndpoint

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def connectableEndpoint(debug=False):
    """
    Create an endpoint that can be fired on demand.

    @param debug: A flag; whether to dump output from the established
        connection to stdout.
    @type debug: L{bool}

    @return: A client endpoint, and an object that will cause one of the
        L{Deferred}s returned by that client endpoint.
    @rtype: 2-L{tuple} of (L{IStreamClientEndpoint}, L{ConnectionCompleter})
    """
    reactor = MemoryReactorClock()
    clientEndpoint = TCP4ClientEndpoint(reactor, "0.0.0.0", 4321)
    serverEndpoint = TCP4ServerEndpoint(reactor, 4321)
    serverEndpoint.listen(Factory.forProtocol(Protocol))
    return clientEndpoint, ConnectionCompleter(reactor) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:iosim.py

示例4: main

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def main():
    """ start up twisted reactor """
    parser = argparse.ArgumentParser(description='VMWare metrics exporter for Prometheus')
    parser.add_argument('-c', '--config', dest='config_file',
                        default=None, help="configuration file")
    parser.add_argument('-p', '--port', dest='port', type=int,
                        default=9272, help="HTTP port to expose metrics")

    args = parser.parse_args()

    # Start up the server to expose the metrics.
    root = VMWareMetricsResource()
    root.configure(args)
    root.putChild(b'metrics', VMWareMetricsResource())
    root.putChild(b'healthz', VMWareMetricsResource())

    factory = Site(root)
    log("Starting web server on port {}".format(args.port))
    endpoint = endpoints.TCP4ServerEndpoint(reactor, args.port)
    endpoint.listen(factory)
    reactor.run() 
开发者ID:rverchere,项目名称:vmware_exporter,代码行数:23,代码来源:vmware_exporter.py

示例5: test_service

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [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) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:test_strports.py

示例6: sni_endpoint

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def sni_endpoint():
    """
    Builds a TxSNI TLSEndpoint populated with the default certificates. These
    are built from cert_builder.py, and have the following certs in the SNI
    map:

    - DEFAULT.pem, which contains a SAN for 'localhost'.
    - http2bin.org.pem, which contains a SAN for 'http2bin.org'
    """
    base_endpoint = endpoints.TCP4ServerEndpoint(
        reactor=reactor,
        port=0,
        interface='127.0.0.1',
    )
    path = FilePath(CERT_DIR)
    mapping = SNIMap(HostDirectoryMap(path))
    wrapper_endpoint = TLSEndpoint(base_endpoint, mapping)
    return wrapper_endpoint 
开发者ID:glyph,项目名称:txsni,代码行数:20,代码来源:test_txsni.py

示例7: start_gui

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def start_gui(interface4, port, mockdevices):
  import calvinextras
  import inspect
  import os.path
  from twisted.web.server import Site
  from twisted.web.static import File
  from twisted.internet import endpoints, reactor
  from calvin.utilities import calvinconfig

  # find installation path of calvinextras package
  extras_path = os.path.dirname(inspect.getfile(calvinextras))
  # build path to gui files
  gui_path = os.path.join(extras_path, "CalvinGUI", "Build", "GUI")
  gui_config_path =  os.path.join(extras_path, "CalvinGUI", "calvin.conf")
  if mockdevices:
      # Patch config
      _conf = calvinconfig.get()
      delta_config = _conf.config_at_path(gui_config_path)
      _conf.update_config(delta_config)
  # Add endpoint to twisted reactor
  resource = File(gui_path)
  factory = Site(resource)
  endpoint = endpoints.TCP4ServerEndpoint(reactor, interface=interface4, port=port)
  endpoint.listen(factory)
  _log.info("Calvin GUI server listening on http://{}:{}".format(interface4, port)) 
开发者ID:EricssonResearch,项目名称:calvin-base,代码行数:27,代码来源:csruntime.py

示例8: main

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def main(argv=None):
    """ start up twisted reactor """
    parser = argparse.ArgumentParser(description='VMWare metrics exporter for Prometheus')
    parser.add_argument('-c', '--config', dest='config_file',
                        default=None, help="configuration file")
    parser.add_argument('-p', '--port', dest='port', type=int,
                        default=9272, help="HTTP port to expose metrics")
    parser.add_argument('-l', '--loglevel', dest='loglevel',
                        default="INFO", help="Set application loglevel INFO, DEBUG")

    args = parser.parse_args(argv or sys.argv[1:])

    numeric_level = getattr(logging, args.loglevel.upper(), None)
    if not isinstance(numeric_level, int):
        raise ValueError("Invalid log level: {level}".format(level=args.loglevel))
    logging.basicConfig(level=numeric_level, format='%(asctime)s %(levelname)s:%(message)s')

    reactor.suggestThreadPoolSize(25)

    factory = Site(registerEndpoints(args))
    logging.info("Starting web server on port {port}".format(port=args.port))
    endpoint = endpoints.TCP4ServerEndpoint(reactor, args.port)
    endpoint.listen(factory)
    reactor.run() 
开发者ID:pryorda,项目名称:vmware_exporter,代码行数:26,代码来源:vmware_exporter.py

示例9: _init_manhole

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def _init_manhole(self, cfg):
        port = cfg['port']
        user, passwd = cfg['user'], cfg['passwd']
        sshFactory = manhole.getManholeFactory(
            {'core': self}, user, passwd)
        endpoint = TCP4ServerEndpoint(reactor, port)
        endpoint.listen(sshFactory)

        log.info('Started manhole in PORT {0!s}'.format(port)) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:11,代码来源:service.py

示例10: server

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def server(self, reactor):
        """
        Create a server-side TCP endpoint.
        """
        return TCP4ServerEndpoint(reactor, 0, interface=self.interface) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:test_tcp.py

示例11: test_tcp

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def test_tcp(self):
        """
        When passed a TCP strports description, L{endpoints.serverFromString}
        returns a L{TCP4ServerEndpoint} instance initialized with the values
        from the string.
        """
        reactor = object()
        server = endpoints.serverFromString(
            reactor, "tcp:1234:backlog=12:interface=10.0.0.1")
        self.assertIsInstance(server, endpoints.TCP4ServerEndpoint)
        self.assertIs(server._reactor, reactor)
        self.assertEqual(server._port, 1234)
        self.assertEqual(server._backlog, 12)
        self.assertEqual(server._interface, "10.0.0.1") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_endpoints.py

示例12: _getEndpoints

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def _getEndpoints(self, reactor, service):
        """
        Return a list of endpoints for the specified service, constructing
        defaults if necessary.

        If no endpoints were configured for the service and the protocol
        was not explicitly disabled with a I{--no-*} option, a default
        endpoint for the service is created.

        @type reactor: L{IReactorTCP <twisted.internet.interfaces.IReactorTCP>}
            provider
        @param reactor: If any endpoints are created, the reactor with
            which they are created.

        @type service: L{bytes}
        @param service: The type of service for which to retrieve endpoints,
            either C{b'pop3'} or C{b'smtp'}.

        @rtype: L{list} of L{IStreamServerEndpoint
            <twisted.internet.interfaces.IStreamServerEndpoint>} provider
        @return: The endpoints for the specified service as configured by the
            command line parameters.
        """
        if self[service]:
            # If there are any services set up, just return those.
            return self[service]
        elif self['no-' + service]:
            # If there are no services, but the service was explicitly disabled,
            # return nothing.
            return []
        else:
            # Otherwise, return the old default service.
            return [
                endpoints.TCP4ServerEndpoint(
                    reactor, self._protoDefaults[service])] 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:37,代码来源:tap.py

示例13: _endpointTest

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def _endpointTest(self, service):
        """
        Use L{Options} to parse a single service configuration parameter and
        verify that an endpoint of the correct type is added to the list for
        that service.
        """
        options = Options()
        options.parseOptions(['--' + service, 'tcp:1234'])
        self.assertEqual(len(options[service]), 1)
        self.assertIsInstance(
            options[service][0], endpoints.TCP4ServerEndpoint) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_options.py

示例14: test_returns_service

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def test_returns_service(self):
        """
        ``create_api_service`` returns an object providing ``IService``.
        """
        reactor = MemoryReactor()
        endpoint = TCP4ServerEndpoint(reactor, 6789)
        verifyObject(IService, create_api_service(
            ConfigurationPersistenceService(reactor, FilePath(self.mktemp())),
            ClusterStateService(reactor), endpoint, ClientContextFactory())) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:11,代码来源:test_httpapi.py

示例15: startService

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ServerEndpoint [as 别名]
def startService(self):
        """
        Register ourselves with the database and establish all outgoing
        connections to other servers in the cluster.
        """
        @inlineCallbacks
        def startup(txn):
            endpoint = TCP4ServerEndpoint(self.reactor, self.ampPort)
            # If this fails, the failure mode is going to be ugly, just like
            # all conflicted-port failures.  But, at least it won't proceed.
            self._listeningPort = yield endpoint.listen(self.peerFactory())
            self.ampPort = self._listeningPort.getHost().port
            yield Lock.exclusive(NodeInfo.table).on(txn)
            nodes = yield self.activeNodes(txn)
            selves = [node for node in nodes
                      if ((node.hostname == self.hostname) and
                          (node.port == self.ampPort))]
            if selves:
                self.thisProcess = selves[0]
                nodes.remove(self.thisProcess)
                yield self.thisProcess.update(pid=self.pid,
                                              time=datetime.now())
            else:
                self.thisProcess = yield NodeInfo.create(
                    txn, hostname=self.hostname, port=self.ampPort,
                    pid=self.pid, time=datetime.now()
                )

            for node in nodes:
                self._startConnectingTo(node)

        self._startingUp = inTransaction(self.transactionFactory, startup)

        @self._startingUp.addBoth
        def done(result):
            self._startingUp = None
            super(PeerConnectionPool, self).startService()
            self._lostWorkCheckLoop()
            return result 
开发者ID:apple,项目名称:ccs-twistedextensions,代码行数:41,代码来源:queue.py


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