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


Python endpoints.clientFromString函数代码示例

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


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

示例1: parseStreamServer

    def parseStreamServer(self, reactor, public_port, localPort=None,
                          controlPort=None, hiddenServiceDir=None):
        ''':api:`twisted.internet.interfaces.IStreamServerEndpointStringParser`'''

        public_port = int(public_port)

        if localPort is not None:
            localPort = int(localPort)

        hsd = hiddenServiceDir
        if hsd:
            orig = hsd
            hsd = os.path.expanduser(hsd)
            hsd = os.path.realpath(hsd)
            if orig != hsd:
                log.msg('Using "%s" for hsd' % hsd)

        if controlPort:
            try:
                ep = clientFromString(reactor, "tcp:host=127.0.0.1:port=%d" % int(controlPort))
            except ValueError:
                ep = clientFromString(reactor, "unix:path=%s" % controlPort)
            return TCPHiddenServiceEndpoint.system_tor(reactor, ep,
                                                       public_port,
                                                       hidden_service_dir=hsd,
                                                       local_port=localPort)

        return TCPHiddenServiceEndpoint.global_tor(reactor, public_port,
                                                   hidden_service_dir=hsd,
                                                   local_port=localPort,
                                                   control_port=controlPort)
开发者ID:arlolra,项目名称:txtorcon,代码行数:31,代码来源:endpoints.py

示例2: run_command

def run_command(config):
    c = dispatch_table[config.subCommand]()
    tub = Tub()
    try:
        from twisted.internet import reactor
        from twisted.internet.endpoints import clientFromString
        from foolscap.connections import tor
        CONTROL = os.environ.get("FOOLSCAP_TOR_CONTROL_PORT", "")
        SOCKS = os.environ.get("FOOLSCAP_TOR_SOCKS_PORT", "")
        if CONTROL:
            h = tor.control_endpoint(clientFromString(reactor, CONTROL))
            tub.addConnectionHintHandler("tor", h)
        elif SOCKS:
            h = tor.socks_endpoint(clientFromString(reactor, SOCKS))
            tub.addConnectionHintHandler("tor", h)
        #else:
        #    h = tor.default_socks()
        #    tub.addConnectionHintHandler("tor", h)
    except ImportError:
        pass
    d = defer.succeed(None)
    d.addCallback(lambda _ign: tub.startService())
    d.addCallback(lambda _ign: tub.getReference(config.furl))
    d.addCallback(c.run, config.subOptions) # might provide tub here
    d.addBoth(lambda res: tub.stopService().addCallback(lambda _ign: res))
    return d
开发者ID:warner,项目名称:foolscap,代码行数:26,代码来源:client.py

示例3: get

def get(host, path):
    f = protocol.ClientFactory()
    f.protocol = HTTPGETProtocol
    f.path = path
    f.host = host
    f.deferred = defer.Deferred()
    strport = "tcp:%s:80" % host
    endpoints.clientFromString(reactor, strport).connect(f)
    return f.deferred
开发者ID:bizhan,项目名称:notes,代码行数:9,代码来源:httpget.py

示例4: start

def start():
    """ Client Entrypoint """
    endpoints.clientFromString(reactor, "tcp:localhost:1234").connect(PrintClientFactory())

    # gui = GameWindow()

    # gui_loop = task.LoopingCall(gui.update)
    # gui_loop.start(1.0)

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

示例5: test_parse_client_basic

    def test_parse_client_basic(self):
        from twisted.plugins import autobahn_endpoints

        self.assertTrue(hasattr(autobahn_endpoints, "AutobahnClientParser"))
        from twisted.internet.endpoints import clientFromString, quoteStringArgument
        from twisted.internet import reactor

        ep_string = "autobahn:{0}:url={1}".format(
            quoteStringArgument("tcp:localhost:9000"), quoteStringArgument("ws://localhost:9000")
        )
        # we're just testing that this doesn't fail entirely
        clientFromString(reactor, ep_string)
开发者ID:crossbario,项目名称:autobahn-python,代码行数:12,代码来源:test_endpoint_plugins.py

示例6: _startup

    async def _startup(reactor):
        if cfg.connect.startswith('tcp:') or cfg.connect.startswith('unix:'):
            ep = clientFromString(reactor, cfg.connect)
        else:
            if ':' in cfg.connect:
                ep = clientFromString(reactor, 'tcp:{}'.format(cfg.connect))
            else:
                ep = clientFromString(reactor, 'tcp:localhost:{}'.format(cfg.connect))
        tor = await txtorcon.connect(reactor, ep)

        if cfg.debug_protocol:

            click.echo("Low-level protocol debugging: ", nl=False)
            click.echo(click.style("data we write to Tor, ", fg='blue'), nl=False)
            click.echo(click.style("data from Tor", fg='yellow') + ".")

            def write_wrapper(data):
                tail = data
                while len(tail):
                    head, tail = tail.split('\r\n', 1)
                    click.echo(">>> " + click.style(head, fg='blue'), nl=False)
                click.echo()
                return orig_write(data)
            orig_write = tor.protocol.transport.write
            tor.protocol.transport.write = write_wrapper

            def read_wrapper(data):
                tail = data
                while '\r\n' in tail:
                    head, tail = tail.split('\r\n', 1)
                    if not read_wrapper.write_prefix:
                        click.echo(click.style(head, fg='yellow'))
                        read_wrapper.write_prefix = True
                    else:
                        click.echo("<<< " + click.style(head, fg='yellow'))
                if len(tail):
                    click.echo("<<< " + click.style(tail, fg='yellow'), nl=False)
                    read_wrapper.write_prefix = False
                else:
                    click.echo()
                return orig_read(data)
            read_wrapper.write_prefix = True
            orig_read = tor.protocol.dataReceived
            tor.protocol.dataReceived = read_wrapper


        if cfg.info:
            info = await tor.protocol.get_info('version', 'status/version/current', 'dormant')
            click.echo(
                'Connected to a Tor version "{version}" (status: '
                '{status/version/current}).\n'.format(**info)
            )
        await cmd(reactor, cfg, tor, *args, **kwargs)
开发者ID:meejah,项目名称:carml,代码行数:53,代码来源:cli.py

示例7: connect

def connect(hostname, worker=None, on_connect=None):
    """
    Connect to server using GrideaProtocol, automatically retry if it is
    not yet running.

    :param hostname: `hostname:port` to connect to
    :param worker: optional gridea.GrideaWorker() to make this process a worker
    :param on_connect: optional callback after connection
    """
    class ClientFactory(ReconnectingClientFactory):
        def buildProtocol(self, addr):
            return GrideaProtocol(worker, on_connect)
    clientFromString(reactor, 'tcp:' + hostname).connect(ClientFactory())
开发者ID:jansel,项目名称:gridea,代码行数:13,代码来源:network.py

示例8: _build_endpoint

 def _build_endpoint(cls, endpoint_string=None, encrypted=True, timeout=5, host=None, reactor=None):
     if not reactor:
         from twisted.internet import reactor
     host = host or cls.host
     if endpoint_string:
         endpoint = clientFromString(reactor, endpoint_string)
     else:
         if encrypted:
             port = 443
             proto = 'ssl'
         else:
             port = 80
             proto = 'tcp'
         endpoint = clientFromString(reactor, '{0}:host={1}:port={2}:timeout={3}'.format(proto, host, port, timeout))
     return endpoint
开发者ID:socillion,项目名称:twistedpusher,代码行数:15,代码来源:client.py

示例9: test_system_tor

    def test_system_tor(self):
        from test_torconfig import FakeControlProtocol

        def boom(*args):
            # why does the new_callable thing need a callable that
            # returns a callable? Feels like I must be doing something
            # wrong somewhere...
            def bam(*args, **kw):
                return self.protocol
            return bam
        with patch('txtorcon.endpoints.launch_tor') as launch_mock:
            with patch('txtorcon.endpoints.build_tor_connection', new_callable=boom) as btc:
                client = clientFromString(
                    self.reactor,
                    "tcp:host=localhost:port=9050"
                )
                ep = yield TCPHiddenServiceEndpoint.system_tor(self.reactor,
                                                               client, 80)
                port = yield ep.listen(NoOpProtocolFactory())
                toa = port.getHost()
                self.assertTrue(hasattr(toa, 'onion_uri'))
                self.assertTrue(hasattr(toa, 'onion_port'))
                port.startListening()
                str(port)
                port.tor_config
                # system_tor should be connecting to a running one,
                # *not* launching a new one.
                self.assertFalse(launch_mock.called)
开发者ID:coffeemakr,项目名称:txtorcon,代码行数:28,代码来源:test_endpoints.py

示例10: _make_i2p_handler

    def _make_i2p_handler(self):
        enabled = self.get_config("i2p", "enabled", True, boolean=True)
        if not enabled:
            return None
        i2p = _import_i2p()
        if not i2p:
            return None

        samport = self.get_config("i2p", "sam.port", None)
        launch = self.get_config("i2p", "launch", False, boolean=True)
        configdir = self.get_config("i2p", "i2p.configdir", None)

        if samport:
            if launch:
                raise ValueError("tahoe.cfg [i2p] must not set both "
                                 "sam.port and launch")
            ep = endpoints.clientFromString(reactor, samport)
            return i2p.sam_endpoint(ep)

        if launch:
            executable = self.get_config("i2p", "i2p.executable", None)
            return i2p.launch(i2p_configdir=configdir, i2p_binary=executable)

        if configdir:
            return i2p.local_i2p(configdir)

        return i2p.default(reactor)
开发者ID:david415,项目名称:tahoe-lafs,代码行数:27,代码来源:node.py

示例11: connectionMade

 def connectionMade(self):
     # print("EndpointForwardingProtocol.connectionMade")
     self._destFactory = DestEndpointForwardingFactory(self)
     self._destEndpoint = clientFromString(
         self.factory.service._reactor, self.factory.service._destEndpointDescriptor
     )
     self._destEndpointPort = yield self._destEndpoint.connect(self._destFactory)
开发者ID:MrDice,项目名称:tk-framework-desktopserver,代码行数:7,代码来源:forwarder.py

示例12: makeService

def makeService(config):
    s = MultiService()


    # ZipkinTracer(
    #     scribe_client,
    #     category=None,
    #     end_annotations=None,
    #     max_traces=50,
    #     max_idle_time=10,
    #     _reactor=None)
    push_tracer(
        ZipkinTracer(
            ScribeClient(clientFromString(reactor, config['scribe'])), 'zipkin', None, 10, 10, None))

    root = RootResource()

    # if config['rproxy']:
    #     root = RProxyWrapper(root)

    site = server.Site(root)
    site.displayTracebacks = False

    api_service = strports.service(config['port'], site)
    api_service.setServiceParent(s)

    return s
开发者ID:ops-baidu,项目名称:restkin,代码行数:27,代码来源:api.py

示例13: main

def main(reactor, procName, *args):
    clientEndpoints = {}
    for k, v in os.environ.iteritems():
        _, _, clientName = k.partition('client_endpoint_')
        if clientName:
            clientEndpoints[clientName] = clientFromString(reactor, v)
    if not clientEndpoints:
        raise ValueError("no client endpoints detected in the environment")

    plugins = [pluginClass(clientEndpoints)
               for pluginClass in sorted(pluginClasses, key=nameLength, reverse=True)]

    if args == ('suggest',):
        suggestions = []
        for plugin in plugins:
            suggestions.extend(plugin.name + arg for arg in plugin.suggest())
        print '\n'.join(suggestions)
        return defer.succeed(None)

    procName = os.path.basename(procName)
    for plugin in plugins:
        _, foundPluginName, arg = procName.partition(plugin.name)
        if not foundPluginName:
            continue
        command = 'fetch' if not args else args[0]
        method = getattr(plugin, 'command_' + command, None)
        if not method:
            raise ValueError("%r plugin can't handle the command %r" % (plugin.name, command))
        return defer.maybeDeferred(method, arg)

    raise ValueError("no plugin was found with the name %r" % (procName,))
开发者ID:habnabit,项目名称:polecat,代码行数:31,代码来源:munin-stats.py

示例14: test_startServer

    def test_startServer(self):
        """
        Should call twisted.internet.endpoints.serverFromString and hook that
        up to the factory
        """
        h = Hub()
        h.remote_echo = lambda x: x
        h.startServer(h.getPBServerFactory(), 'tcp:10999')
        
        # connect to it
        self.clientPort = None
        client = clientFromString(reactor, 'tcp:host=127.0.0.1:port=10999')
        factory = pb.PBClientFactory()
        d = client.connect(factory)
        
        def saveClient(clientPort):
            self.clientPort = clientPort

        d.addCallback(saveClient)
        d.addCallback(lambda ign: factory.getRootObject())
        d.addCallback(lambda obj: obj.callRemote('echo', 'foo'))
        d.addCallback(lambda res: self.assertEqual(res, 'foo'))
        d.addCallback(lambda ign: self.clientPort.transport.loseConnection())
        d.addCallback(lambda ign: h.stopServer('tcp:10999'))
        return d
开发者ID:hagna,项目名称:simplebb,代码行数:25,代码来源:test_hub.py

示例15: _connect_to_daemon

 def _connect_to_daemon(self):
     """Connect to the daemon so that we can receive events."""
     description = 'unix:path=%s' % DAEMON_SOCKET
     client = endpoints.clientFromString(reactor, description)
     self._protocol = yield client.connect(self._factory)
     # add the user with no paths
     yield self._protocol.add_user([])
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:7,代码来源:fsevents_daemon.py


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