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


Python util.padTo函数代码示例

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


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

示例1: test_makeCopy

 def test_makeCopy(self):
     """
     L{util.padTo} doesn't modify the input list but makes a copy.
     """
     items = []
     util.padTo(4, items)
     self.assertEqual([], items)
开发者ID:RedMoons,项目名称:Study_Python_Beautifulsoup4,代码行数:7,代码来源:test_util.py

示例2: _gather_flags

    def _gather_flags(self):
        """
        Gather up boolean (flag) options.
        """

        longOpt, shortOpt = [], ''
        docs, settings, synonyms, dispatch = {}, {}, {}, {}

        flags = []
        reflect.accumulateClassList(self.__class__, 'optFlags', flags)

        for flag in flags:
            long, short, doc = util.padTo(3, flag)
            if not long:
                raise ValueError("A flag cannot be without a name.")

            docs[long] = doc
            settings[long] = 0
            if short:
                shortOpt = shortOpt + short
                synonyms[short] = long
            longOpt.append(long)
            synonyms[long] = long
            dispatch[long] = self._generic_flag

        return longOpt, shortOpt, docs, settings, synonyms, dispatch
开发者ID:Almad,项目名称:twisted,代码行数:26,代码来源:usage.py

示例3: test_specificDefaultValue

 def test_specificDefaultValue(self):
     """
     A specific value can be added to a list to cause it to have a certain
     length.
     """
     padded = util.padTo(4, [], "x")
     self.assertEqual(["x"] * 4, padded)
开发者ID:RedMoons,项目名称:Study_Python_Beautifulsoup4,代码行数:7,代码来源:test_util.py

示例4: test_padNonEmptyList

 def test_padNonEmptyList(self):
     """
     A list which already has some items has the padding value added after
     those items.
     """
     padded = util.padTo(3, [1, 2], "z")
     self.assertEqual([1, 2, "z"], padded)
开发者ID:RedMoons,项目名称:Study_Python_Beautifulsoup4,代码行数:7,代码来源:test_util.py

示例5: _gather_parameters

    def _gather_parameters(self):
        """
        Gather options which take a value.
        """
        longOpt, shortOpt = [], ''
        docs, settings, synonyms, dispatch = {}, {}, {}, {}

        parameters = []

        reflect.accumulateClassList(self.__class__, 'optParameters',
                                    parameters)

        synonyms = {}

        for parameter in parameters:
            long, short, default, doc, paramType = util.padTo(5, parameter)
            if not long:
                raise ValueError("A parameter cannot be without a name.")

            docs[long] = doc
            settings[long] = default
            if short:
                shortOpt = shortOpt + short + ':'
                synonyms[short] = long
            longOpt.append(long + '=')
            synonyms[long] = long
            if paramType is not None:
                dispatch[long] = CoerceParameter(self, paramType)
            else:
                dispatch[long] = CoerceParameter(self, str)

        return longOpt, shortOpt, docs, settings, synonyms, dispatch
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:32,代码来源:usage.py

示例6: test_default

 def test_default(self):
     """
     C{None} values can be added to a list to cause it to have a certain
     length.
     """
     padded = util.padTo(3, [])
     self.assertEqual([None] * 3, padded)
开发者ID:RedMoons,项目名称:Study_Python_Beautifulsoup4,代码行数:7,代码来源:test_util.py

示例7: test_alreadyPaddedCopies

 def test_alreadyPaddedCopies(self):
     """
     If the list is already the length indicated by the padding argument
     then the return value is a copy of the input.
     """
     items = [1, 2]
     padded = util.padTo(len(items), items)
     self.assertIsNot(padded, items)
开发者ID:RedMoons,项目名称:Study_Python_Beautifulsoup4,代码行数:8,代码来源:test_util.py

示例8: test_alreadyPadded

 def test_alreadyPadded(self):
     """
     If the list is already the length indicated by the padding argument
     then a list with the same value is returned.
     """
     items = [1, 2]
     padded = util.padTo(len(items), items)
     self.assertEqual(items, padded)
开发者ID:RedMoons,项目名称:Study_Python_Beautifulsoup4,代码行数:8,代码来源:test_util.py

示例9: updateDestinguishedName

 def updateDestinguishedName(self, subject):
     DN = {}
     parameters = []
     reflect.accumulateClassList(self.__class__, 'optParameters', parameters)
     for parameter in parameters:
         key, short, val, doc, _type = util.padTo(5, parameter)
         if self.opts[key]:
             val = _type and _type(self.opts[key]) or self.opts[key]
         elif self.defaults[key]:
             val = _type and _type(self.defaults[key]) or self.defaults[key]
         if key == 'years':
             val = 60 * 60 * 24 * 365 * val
         if val and key in self.x509names:
             try:
                 setattr(subject, self.x509names.get(key), val.strip())
             except crypto.Error, err:
                 raise SysExit("Setting value of '%s' failed: %s",
                               key, err[0][0][2])
             DN[self.x509names.get(key)] = val.strip()
开发者ID:UfSoft,项目名称:afm-new,代码行数:19,代码来源:certs.py

示例10: _set_defaults

 def _set_defaults(self, parser, subCommands):
     parser_defaults = parser.defaults()
     for name, sname, options, doc in subCommands:
         if hasattr(options, 'optParameters'):
             parameters = []
             instance = options().__class__
             reflect.accumulateClassList(instance, 'optParameters',
                                         parameters)
             for idx, parameter in enumerate(parameters):
                 long, short, default, doc, type = util.padTo(5, parameter)
                 _def = parser_defaults.get(long, default)
                 if parser.has_option(name, long):
                     _def = parser.get(name, long, _def)
                 if _def != default:
                     option = [long, short, type and type(_def) or _def, doc]
                     if type:
                         option.append(type)
                     parameters[idx] = option
             # Override class defaults with config-file defaults
             options.optParameters = parameters
         if hasattr(options, "subCommands"):
             self._set_defaults(parser, options.subCommands)
开发者ID:UfSoft,项目名称:SSHgD,代码行数:22,代码来源:service.py

示例11: __init__

    def __init__(self, cmd_name, options, file):
        """
        @type cmd_name: C{str}
        @param cmd_name: The name of the command

        @type options: C{twisted.usage.Options}
        @param options: The C{twisted.usage.Options} instance defined
                        for this command

        @type file: C{file}
        @param file: The C{file} to write the completion function to
        """
        self.cmd_name = cmd_name
        self.options = options
        self.file = file

        self.altArgDescr = {}
        self.actionDescr = {}
        self.multiUse = []
        self.mutuallyExclusive = []
        self.actions = {}
        self.extras = []

        aCL = reflect.accumulateClassList
        aCD = reflect.accumulateClassDict

        aCD(options.__class__, 'zsh_altArgDescr', self.altArgDescr)
        aCD(options.__class__, 'zsh_actionDescr', self.actionDescr)
        aCL(options.__class__, 'zsh_multiUse', self.multiUse)
        aCL(options.__class__, 'zsh_mutuallyExclusive',
            self.mutuallyExclusive)
        aCD(options.__class__, 'zsh_actions', self.actions)
        aCL(options.__class__, 'zsh_extras', self.extras)

        optFlags = []
        optParams = []

        aCL(options.__class__, 'optFlags', optFlags)
        aCL(options.__class__, 'optParameters', optParams)

        for i, optList in enumerate(optFlags):
            if len(optList) != 3:
                optFlags[i] = util.padTo(3, optList)

        for i, optList in enumerate(optParams):
            if len(optList) != 4:
                optParams[i] = util.padTo(4, optList)


        self.optFlags = optFlags
        self.optParams = optParams

        optParams_d = {}
        for optList in optParams:
            optParams_d[optList[0]] = optList[1:]
        self.optParams_d = optParams_d

        optFlags_d = {}
        for optList in optFlags:
            optFlags_d[optList[0]] = optList[1:]
        self.optFlags_d = optFlags_d

        optAll_d = {}
        optAll_d.update(optParams_d)
        optAll_d.update(optFlags_d)
        self.optAll_d = optAll_d

        self.addAdditionalOptions()

        # makes sure none of the zsh_ data structures reference option
        # names that don't exist. (great for catching typos)
        self.verifyZshNames()

        self.excludes = self.makeExcludesDict()
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:74,代码来源:zshcomp.py

示例12: __init__

    def __init__(self, options, cmdName, file):
        self.options = options
        self.cmdName = cmdName
        self.file = file

        self.descriptions = {}
        self.multiUse = set()
        self.mutuallyExclusive = []
        self.optActions = {}
        self.extraActions = []

        for cls in reversed(inspect.getmro(options.__class__)):
            data = getattr(cls, 'compData', None)
            if data:
                self.descriptions.update(data.descriptions)
                self.optActions.update(data.optActions)
                self.multiUse.update(data.multiUse)

                self.mutuallyExclusive.extend(data.mutuallyExclusive)

                # I don't see any sane way to aggregate extraActions, so just
                # take the one at the top of the MRO (nearest the `options'
                # instance).
                if data.extraActions:
                    self.extraActions = data.extraActions

        aCL = reflect.accumulateClassList

        optFlags = []
        optParams = []

        aCL(options.__class__, 'optFlags', optFlags)
        aCL(options.__class__, 'optParameters', optParams)

        for i, optList in enumerate(optFlags):
            if len(optList) != 3:
                optFlags[i] = util.padTo(3, optList)

        for i, optList in enumerate(optParams):
            if len(optList) != 5:
                optParams[i] = util.padTo(5, optList)


        self.optFlags = optFlags
        self.optParams = optParams

        paramNameToDefinition = {}
        for optList in optParams:
            paramNameToDefinition[optList[0]] = optList[1:]
        self.paramNameToDefinition = paramNameToDefinition

        flagNameToDefinition = {}
        for optList in optFlags:
            flagNameToDefinition[optList[0]] = optList[1:]
        self.flagNameToDefinition = flagNameToDefinition

        allOptionsNameToDefinition = {}
        allOptionsNameToDefinition.update(paramNameToDefinition)
        allOptionsNameToDefinition.update(flagNameToDefinition)
        self.allOptionsNameToDefinition = allOptionsNameToDefinition

        self.addAdditionalOptions()

        # makes sure none of the Completions metadata references
        # option names that don't exist. (great for catching typos)
        self.verifyZshNames()

        self.excludes = self.makeExcludesDict()
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:68,代码来源:_shellcomp.py

示例13: __init__

    def __init__(self, cmd_name, optionsClass, file):
        """write the zsh completion code to the given file"""
        self.cmd_name = cmd_name
        self.optionsClass = optionsClass
        self.file = file

        self.altArgDescr = {}
        self.actionDescr = {}
        self.multiUse = []
        self.mutuallyExclusive = []
        self.actions = {}
        self.extras = []

        aCL = reflect.accumulateClassList
        aCD = reflect.accumulateClassDict

        aCD(optionsClass, 'zsh_altArgDescr', self.altArgDescr)
        aCD(optionsClass, 'zsh_actionDescr', self.actionDescr)
        aCL(optionsClass, 'zsh_multiUse', self.multiUse)
        aCL(optionsClass, 'zsh_mutuallyExclusive', self.mutuallyExclusive)
        aCD(optionsClass, 'zsh_actions', self.actions)
        aCL(optionsClass, 'zsh_extras', self.extras)

        optFlags = []
        optParams = []

        aCL(optionsClass, 'optFlags', optFlags)
#        optFlags = getattr(optionsClass, 'optFlags', [])
        aCL(optionsClass, 'optParameters', optParams)
#        optParams = getattr(optionsClass, 'optParameters', [])

#        for l in optFlags:
#            print l
#        for l in optParams:
#            print l

        for i, optList in enumerate(optFlags):
            if len(optList) != 3:
                optFlags[i] = util.padTo(3, optList)

        for i, optList in enumerate(optParams):
            if len(optList) != 4:
                optParams[i] = util.padTo(4, optList)


        self.optFlags = optFlags
        self.optParams = optParams

        optParams_d = {}
        for optList in optParams:
            optParams_d[optList[0]] = optList[1:]
        self.optParams_d = optParams_d

        optFlags_d = {}
        for optList in optFlags:
            optFlags_d[optList[0]] = optList[1:]
        self.optFlags_d = optFlags_d

        optAll_d = {}
        optAll_d.update(optParams_d)
        optAll_d.update(optFlags_d)
        self.optAll_d = optAll_d

        self.addAdditionalOptions()

        # makes sure none of the zsh_ data structures reference option names that
        # don't exist. (great for catching typos)
        self.verifyZshNames()
        
        self.excludes = self.makeExcludesDict()
开发者ID:pwarren,项目名称:AGDeviceControl,代码行数:70,代码来源:zshcomp.py


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