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


Python usage.Options方法代码示例

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


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

示例1: write

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def write(self, genSubs=True):
        """
        Generate the completion function and write it to the output file
        @return: L{None}

        @type genSubs: C{bool}
        @param genSubs: Flag indicating whether or not completions for the list
            of subcommand should be generated. Only has an effect
            if the C{subCommands} attribute has been defined on the
            L{twisted.python.usage.Options} instance.
        """
        if genSubs and getattr(self.options, 'subCommands', None) is not None:
            gen = ZshArgumentsGenerator(self.options, self.cmdName, self.file)
            gen.extraActions.insert(0, SubcommandAction())
            gen.write()
            self.file.write(b'local _zsh_subcmds_array\n_zsh_subcmds_array=(\n')
            for (cmd, short, parser, desc) in self.options.subCommands:
                self.file.write(
                    b'\"' + cmd.encode('utf-8') + b':' + desc.encode('utf-8') +b'\"\n')
            self.file.write(b")\n\n")
            self.file.write(b'_describe "sub-command" _zsh_subcmds_array\n')
        else:
            gen = ZshArgumentsGenerator(self.options, self.cmdName, self.file)
            gen.write() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:_shellcomp.py

示例2: writeExtras

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def writeExtras(self):
        """
        Write out completion information for extra arguments appearing on the
        command-line. These are extra positional arguments not associated
        with a named option. That is, the stuff that gets passed to
        Options.parseArgs().

        @return: L{None}

        @raises: ValueError: if C{Completer} with C{repeat=True} is found and
            is not the last item in the C{extraActions} list.
        """
        for i, action in enumerate(self.extraActions):
            # a repeatable action must be the last action in the list
            if action._repeat and i != len(self.extraActions) - 1:
                raise ValueError("Completer with repeat=True must be "
                                 "last item in Options.extraActions")
            self.file.write(
                escape(action._shellCode('', usage._ZSH)).encode('utf-8'))
            self.file.write(b' \\\n') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:_shellcomp.py

示例3: test_accumulateMetadata

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def test_accumulateMetadata(self):
        """
        Are `compData' attributes you can place on Options classes
        picked up correctly?
        """
        opts = FighterAceExtendedOptions()
        ag = _shellcomp.ZshArgumentsGenerator(opts, 'ace', 'dummy_value')

        descriptions = FighterAceOptions.compData.descriptions.copy()
        descriptions.update(FighterAceExtendedOptions.compData.descriptions)

        self.assertEqual(ag.descriptions, descriptions)
        self.assertEqual(ag.multiUse,
                          set(FighterAceOptions.compData.multiUse))
        self.assertEqual(ag.mutuallyExclusive,
                          FighterAceOptions.compData.mutuallyExclusive)

        optActions = FighterAceOptions.compData.optActions.copy()
        optActions.update(FighterAceExtendedOptions.compData.optActions)
        self.assertEqual(ag.optActions, optActions)

        self.assertEqual(ag.extraActions,
                          FighterAceOptions.compData.extraActions) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_shellcomp.py

示例4: test_incompleteCommandLine

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def test_incompleteCommandLine(self):
        """
        Completion still happens even if a command-line is given
        that would normally throw UsageError.
        """
        outputFile = BytesIO()
        self.patch(usage.Options, '_shellCompFile', outputFile)
        opts = FighterAceOptions()

        self.assertRaises(SystemExit, opts.parseOptions,
                          ["--fokker", "server", "--unknown-option",
                           "--unknown-option2",
                           "--_shell-completion", "zsh:5"])
        outputFile.seek(0)
        # test that we got some output
        self.assertEqual(1, len(outputFile.read(1))) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_shellcomp.py

示例5: test_incompleteCommandLine_case3

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def test_incompleteCommandLine_case3(self):
        """
        Completion still happens even if a command-line is given
        that would normally throw UsageError.

        Break subcommand detection in a different way by providing
        an invalid subcommand name.
        """
        outputFile = BytesIO()
        self.patch(usage.Options, '_shellCompFile', outputFile)
        opts = FighterAceOptions()

        self.assertRaises(SystemExit, opts.parseOptions,
                          ["--fokker", "unknown-subcommand",
                           "--list-server", "--_shell-completion", "zsh:4"])
        outputFile.seek(0)
        # test that we got some output
        self.assertEqual(1, len(outputFile.read(1))) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_shellcomp.py

示例6: test_brokenActions

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def test_brokenActions(self):
        """
        A C{Completer} with repeat=True may only be used as the
        last item in the extraActions list.
        """
        class BrokenActions(usage.Options):
            compData = usage.Completions(
                extraActions=[usage.Completer(repeat=True),
                              usage.Completer()]
                )

        outputFile = BytesIO()
        opts = BrokenActions()
        self.patch(opts, '_shellCompFile', outputFile)
        self.assertRaises(ValueError, opts.parseOptions,
                          ["", "--_shell-completion", "zsh:2"]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_shellcomp.py

示例7: test_optMethodsDontOverride

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def test_optMethodsDontOverride(self):
        """
        opt_* methods on Options classes should not override the
        data provided in optFlags or optParameters.
        """
        class Options(usage.Options):
            optFlags = [['flag', 'f', 'A flag']]
            optParameters = [['param', 'p', None, 'A param']]

            def opt_flag(self):
                """ junk description """

            def opt_param(self, param):
                """ junk description """

        opts = Options()
        argGen = _shellcomp.ZshArgumentsGenerator(opts, 'ace', None)

        self.assertEqual(argGen.getDescription('flag'), 'A flag')
        self.assertEqual(argGen.getDescription('param'), 'A param') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_shellcomp.py

示例8: _buildResolvers

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def _buildResolvers(config):
    """
    Build DNS resolver instances in an order which leaves recursive
    resolving as a last resort.

    @type config: L{Options} instance
    @param config: Parsed command-line configuration

    @return: Two-item tuple of a list of cache resovers and a list of client
        resolvers
    """
    from twisted.names import client, cache, hosts

    ca, cl = [], []
    if config['cache']:
        ca.append(cache.CacheResolver(verbose=config['verbose']))
    if config['hosts-file']:
        cl.append(hosts.Resolver(file=config['hosts-file']))
    if config['recursive']:
        cl.append(client.createResolver(resolvconf=config['resolv-conf']))
    return ca, cl 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:tap.py

示例9: makeService

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def makeService(config):
    """
    Construct a service for operating a SSH server.

    @param config: An L{Options} instance specifying server options, including
        where server keys are stored and what authentication methods to use.

    @return: A L{twisted.application.service.IService} provider which contains
        the requested SSH server.
    """

    t = factory.OpenSSHFactory()

    r = unix.UnixSSHRealm()
    t.portal = portal.Portal(r, config.get('credCheckers', []))
    t.dataRoot = config['data']
    t.moduliRoot = config['moduli'] or config['data']

    port = config['port']
    if config['interface']:
        # Add warning here
        port += ':interface=' + config['interface']
    return strports.service(port, t) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:tap.py

示例10: test_subCommandParseOptionsHasParent

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def test_subCommandParseOptionsHasParent(self):
        """
        The parseOptions method from the Options object specified for the
        given subcommand is called.
        """
        class SubOpt(usage.Options):
            def parseOptions(self, *a, **kw):
                self.sawParent = self.parent
                usage.Options.parseOptions(self, *a, **kw)
        class Opt(usage.Options):
            subCommands = [
                ('foo', 'f', SubOpt, 'bar'),
                ]
        o = Opt()
        o.parseOptions(['foo'])
        self.assertTrue(hasattr(o.subOptions, 'sawParent'))
        self.assertEqual(o.subOptions.sawParent , o) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_usage.py

示例11: test_subCommandInTwoPlaces

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def test_subCommandInTwoPlaces(self):
        """
        The .parent pointer is correct even when the same Options class is
        used twice.
        """
        class SubOpt(usage.Options):
            pass
        class OptFoo(usage.Options):
            subCommands = [
                ('foo', 'f', SubOpt, 'quux'),
                ]
        class OptBar(usage.Options):
            subCommands = [
                ('bar', 'b', SubOpt, 'quux'),
                ]
        oFoo = OptFoo()
        oFoo.parseOptions(['foo'])
        oBar=OptBar()
        oBar.parseOptions(['bar'])
        self.assertTrue(hasattr(oFoo.subOptions, 'parent'))
        self.assertTrue(hasattr(oBar.subOptions, 'parent'))
        self.failUnlessIdentical(oFoo.subOptions.parent, oFoo)
        self.failUnlessIdentical(oBar.subOptions.parent, oBar) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_usage.py

示例12: test_optionsAliasesOrder

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def test_optionsAliasesOrder(self):
        """
        Options which are synonyms to another option are aliases towards the
        longest option name.
        """
        class Opts(usage.Options):
            def opt_very_very_long(self):
                """
                This is an option method with a very long name, that is going to
                be aliased.
                """

            opt_short = opt_very_very_long
            opt_s = opt_very_very_long

        opts = Opts()

        self.assertEqual(
            dict.fromkeys(
                ["s", "short", "very-very-long"], "very-very-long"), {
                "s": opts.synonyms["s"],
                "short": opts.synonyms["short"],
                "very-very-long": opts.synonyms["very-very-long"],
                }) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_usage.py

示例13: test_reactorSelectionMixinNonExistent

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def test_reactorSelectionMixinNonExistent(self):
        """
        Test that the usage mixin exits when trying to use a non existent
        reactor (the name not matching to any reactor), giving an error
        message.
        """
        class ReactorSelectionOptions(usage.Options, app.ReactorSelectionMixin):
            pass
        self.pluginResults = []

        options = ReactorSelectionOptions()
        options.messageOutput = NativeStringIO()
        e = self.assertRaises(usage.UsageError, options.parseOptions,
                              ['--reactor', 'fakereactortest', 'subcommand'])
        self.assertIn("fakereactortest", e.args[0])
        self.assertIn("help-reactors", e.args[0]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_application.py

示例14: test_reactorSelectionMixinNotAvailable

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def test_reactorSelectionMixinNotAvailable(self):
        """
        Test that the usage mixin exits when trying to use a reactor not
        available (the reactor raises an error at installation), giving an
        error message.
        """
        class ReactorSelectionOptions(usage.Options, app.ReactorSelectionMixin):
            pass
        message = "Missing foo bar"
        def install():
            raise ImportError(message)

        name = 'fakereactortest'
        package = __name__
        description = 'description'
        self.pluginResults = [FakeReactor(install, name, package, description)]

        options = ReactorSelectionOptions()
        options.messageOutput = NativeStringIO()
        e =  self.assertRaises(usage.UsageError, options.parseOptions,
                               ['--reactor', 'fakereactortest', 'subcommand'])
        self.assertIn(message, e.args[0])
        self.assertIn("help-reactors", e.args[0]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_application.py

示例15: run

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import Options [as 别名]
def run():
    options = Options()
    try:
        options.parseOptions()
    except usage.UsageError as e:
        print(str(e))
        sys.exit(1)
    filename = options['filename']
    if options.get('stylesheet') is not None:
        stylesheet = styleLink % (options['stylesheet'],)
    else:
        stylesheet = ''

    with open(filename + '.html', 'wb') as output:
        outHeader = (header % {
            'title': filename,
            'generator': 'htmlizer/%s' % (copyright.longversion,),
            'alternate': alternateLink % {'source': filename},
            'stylesheet': stylesheet
            })
        output.write(outHeader.encode("utf-8"))
        with open(filename, 'rb') as f:
            htmlizer.filter(f, output, htmlizer.SmallerHTMLWriter)
        output.write(footer.encode("utf-8")) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:htmlizer.py


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