コード例 #1
0
ファイル: test_util.py プロジェクト: Arshdeep10/scrapy
 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)
コード例 #2
0
 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)
コード例 #3
0
ファイル: usage.py プロジェクト: Almad/twisted
    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
コード例 #4
0
ファイル: test_util.py プロジェクト: Arshdeep10/scrapy
 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)
コード例 #5
0
ファイル: test_util.py プロジェクト: Arshdeep10/scrapy
 def test_default(self):
     """
     L{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)
コード例 #6
0
ファイル: test_util.py プロジェクト: Arshdeep10/scrapy
 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)
コード例 #7
0
    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
コード例 #8
0
    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
コード例 #9
0
 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)
コード例 #10
0
 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)
コード例 #11
0
 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)
コード例 #12
0
ファイル: usage.py プロジェクト: 12019/OpenWrt_Luci_Lua
    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
コード例 #13
0
ファイル: test_util.py プロジェクト: Arshdeep10/scrapy
 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)
コード例 #14
0
ファイル: test_util.py プロジェクト: Arshdeep10/scrapy
 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)
コード例 #15
0
 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)
コード例 #16
0
 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)
コード例 #17
0
def htmlFor_menu(write, name, value, allowMultiple=False):
    "Value of the format [(optionName, displayName[, selected]), ...]"
    write('  <select NAME="%s"%s>\n' %
          (name, (allowMultiple and " multiple") or ''))
    for v in value:
        optionName, displayName, selected = util.padTo(3, v)
        selected = (selected and " selected") or ''
        write('    <option VALUE="%s"%s>%s</option>\n' %
              (optionName, selected, displayName))
    if not value:
        write('    <option VALUE=""></option>\n')
    write("  </select>\n")
コード例 #18
0
ファイル: widgets.py プロジェクト: duyMinhCSE/eXe_handmake
def htmlFor_menu(write, name, value, allowMultiple=False):
    "Value of the format [(optionName, displayName[, selected]), ...]"

    write('  <select NAME="%s"%s>\n' %
          (name, (allowMultiple and " multiple") or ''))

    for v in value:
        optionName, displayName, selected = util.padTo(3, v)
        selected = (selected and " selected") or ''
        write('    <option VALUE="%s"%s>%s</option>\n' %
              (optionName, selected, displayName))
    if not value:
        write('    <option VALUE=""></option>\n')
    write("  </select>\n")
コード例 #19
0
ファイル: certs.py プロジェクト: UfSoft/afm-new
 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()
コード例 #20
0
ファイル: service.py プロジェクト: UfSoft/SSHgD
 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)
コード例 #21
0
ファイル: zshcomp.py プロジェクト: MayuraVerma/Kannada
    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()
コード例 #22
0
    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()
コード例 #23
0
ファイル: _shellcomp.py プロジェクト: levanhong05/MeshMagic
    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
        aCD = reflect.accumulateClassDict

        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()
コード例 #24
0
ファイル: zshcomp.py プロジェクト: UstadMobile/eXePUB
    def __init__(self, cmd_name, options, file):
        """write the zsh completion code to the given file"""
        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)
        #        optFlags = getattr(options, 'optFlags', [])
        aCL(options.__class__, 'optParameters', optParams)
        #        optParams = getattr(options, '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()
コード例 #25
0
ファイル: zshcomp.py プロジェクト: pwarren/AGDeviceControl
    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()