Exemplo n.º 1
0
    def autoRegister(self, obj):
        from twisted.python import reflect

        d = {}
        reflect.accumulateMethods(obj, d, self.prefix)
        for k, v in d.items():
            self.registerHandler(k, v)
Exemplo n.º 2
0
 def test_prefix(self):
     """
     If a prefix is given, L{accumulateMethods} limits its results to
     methods beginning with that prefix.  Keys in the resulting dictionary
     also have the prefix removed from them.
     """
     x = Separate()
     output = {}
     accumulateMethods(x, output, 'good_')
     self.assertEqual({'method': x.good_method}, output)
Exemplo n.º 3
0
 def test_ownClass(self):
     """
     If x is and instance of Base and Base defines a method named method,
     L{accumulateMethods} adds an item to the given dictionary with
     C{"method"} as the key and a bound method object for Base.method value.
     """
     x = Base()
     output = {}
     accumulateMethods(x, output)
     self.assertEqual({"method": x.method}, output)
Exemplo n.º 4
0
 def test_prefix(self):
     """
     If a prefix is given, L{accumulateMethods} limits its results to
     methods beginning with that prefix.  Keys in the resulting dictionary
     also have the prefix removed from them.
     """
     x = Separate()
     output = {}
     accumulateMethods(x, output, 'good_')
     self.assertEqual({'method': x.good_method}, output)
Exemplo n.º 5
0
 def test_ownClass(self):
     """
     If x is and instance of Base and Base defines a method named method,
     L{accumulateMethods} adds an item to the given dictionary with
     C{"method"} as the key and a bound method object for Base.method value.
     """
     x = Base()
     output = {}
     accumulateMethods(x, output)
     self.assertEqual({"method": x.method}, output)
Exemplo n.º 6
0
    def addAdditionalOptions(self):
        """
        Add additional options to the optFlags and optParams lists.
        These will be defined by 'opt_foo' methods of the Options subclass
        @return: C{None}
        """
        methodsDict = {}
        reflect.accumulateMethods(self.options, methodsDict, 'opt_')
        methodToShort = {}
        for name in methodsDict.copy():
            if len(name) == 1:
                methodToShort[methodsDict[name]] = name
                del methodsDict[name]

        for methodName, methodObj in methodsDict.items():
            longname = methodName.replace('_', '-')  # t.p.usage does this
            # if this option is already defined by the optFlags or
            # optParameters then we don't want to override that data
            if longname in self.allOptionsNameToDefinition:
                continue

            descr = self.getDescription(longname)

            short = None
            if methodObj in methodToShort:
                short = methodToShort[methodObj]

            reqArgs = methodObj.im_func.func_code.co_argcount
            if reqArgs == 2:
                self.optParams.append([longname, short, None, descr])
                self.paramNameToDefinition[longname] = [short, None, descr]
                self.allOptionsNameToDefinition[longname] = [
                    short, None, descr
                ]
            else:
                # reqArgs must equal 1. self.options would have failed
                # to instantiate if it had opt_ methods with bad signatures.
                self.optFlags.append([longname, short, descr])
                self.flagNameToDefinition[longname] = [short, descr]
                self.allOptionsNameToDefinition[longname] = [
                    short, None, descr
                ]
Exemplo n.º 7
0
    def addAdditionalOptions(self):
        """
        Add additional options to the optFlags and optParams lists.
        These will be defined by 'opt_foo' methods of the Options subclass
        @return: C{None}
        """
        methodsDict = {}
        reflect.accumulateMethods(self.options, methodsDict, 'opt_')
        methodToShort = {}
        for name in methodsDict.copy():
            if len(name) == 1:
                methodToShort[methodsDict[name]] = name
                del methodsDict[name]

        for methodName, methodObj in methodsDict.items():
            long = methodName.replace('_', '-') # t.p.usage does this
            # if this option is already defined by the optFlags or
            # optParameters then we don't want to override that data
            if long in self.optAll_d:
                continue

            descr = self.getDescription(long)

            short = None
            if methodObj in methodToShort:
                short = methodToShort[methodObj]

            reqArgs = methodObj.im_func.func_code.co_argcount
            if reqArgs == 2:
                self.optParams.append([long, short, None, descr])
                self.optParams_d[long] = [short, None, descr]
                self.optAll_d[long] = [short, None, descr]
            elif reqArgs == 1:
                self.optFlags.append([long, short, descr])
                self.optFlags_d[long] = [short, descr]
                self.optAll_d[long] = [short, None, descr]
            else:
                raise TypeError, '%r has wrong number ' \
                                 'of arguments' % (methodObj,)
    def addAdditionalOptions(self):
        """
        Add additional options to the optFlags and optParams lists.
        These will be defined by 'opt_foo' methods of the Options subclass
        @return: L{None}
        """
        methodsDict = {}
        reflect.accumulateMethods(self.options, methodsDict, 'opt_')
        methodToShort = {}
        for name in methodsDict.copy():
            if len(name) == 1:
                methodToShort[methodsDict[name]] = name
                del methodsDict[name]

        for methodName, methodObj in methodsDict.items():
            longname = methodName.replace('_', '-') # t.p.usage does this
            # if this option is already defined by the optFlags or
            # optParameters then we don't want to override that data
            if longname in self.allOptionsNameToDefinition:
                continue

            descr = self.getDescription(longname)

            short = None
            if methodObj in methodToShort:
                short = methodToShort[methodObj]

            reqArgs = methodObj.__func__.__code__.co_argcount
            if reqArgs == 2:
                self.optParams.append([longname, short, None, descr])
                self.paramNameToDefinition[longname] = [short, None, descr]
                self.allOptionsNameToDefinition[longname] = [short, None, descr]
            else:
                # reqArgs must equal 1. self.options would have failed
                # to instantiate if it had opt_ methods with bad signatures.
                self.optFlags.append([longname, short, descr])
                self.flagNameToDefinition[longname] = [short, descr]
                self.allOptionsNameToDefinition[longname] = [short, None, descr]
Exemplo n.º 9
0
    def addAdditionalOptions(self):
        """Add additional options to the optFlags and optParams lists.
        These will be defined by 'opt_foo' methods of the Options subclass"""
        methodsDict = {}
        reflect.accumulateMethods(self.optionsClass, methodsDict, 'opt_', curClass=self.optionsClass)
        # we need to go through methodsDict and figure out is there are such things as
        # opt_debug and opt_b that point to the same method (long and short option names
        methodToShort = {}
        for name in methodsDict.copy():
            if len(name) == 1:
                methodToShort[methodsDict[name]] = name
                del methodsDict[name]

        for methodName, methodObj in methodsDict.items():
            long = methodName.replace('_', '-') # t.p.usage does this
            # if this option is already defined by the optFlags or
            # optParameters then we don't want to override that data
            if long in self.optAll_d:
                continue

            descr = self.getDescription(long)

            short = None
            if methodObj in methodToShort:
                short = methodToShort[methodObj]

            reqArgs = methodObj.im_func.func_code.co_argcount
            if reqArgs == 2:
                self.optParams.append([long, short, None, descr])
                self.optParams_d[long] = [short, None, descr]
                self.optAll_d[long] = [short, None, descr]
            elif reqArgs == 1:
                self.optFlags.append([long, short, descr])
                self.optFlags_d[long] = [short, descr]
                self.optAll_d[long] = [short, None, descr]
            else:
                raise SystemExit, 'opt_ method has wrong number of arguments'
Exemplo n.º 10
0
    def addAdditionalOptions(self):
        """Add additional options to the optFlags and optParams lists.
        These will be defined by 'opt_foo' methods of the Options subclass"""
        methodsDict = {}
        reflect.accumulateMethods(self.options, methodsDict, 'opt_')
        # we need to go through methodsDict and figure out is there are such things as
        # opt_debug and opt_b that point to the same method (long and short option names
        methodToShort = {}
        for name in methodsDict.copy():
            if len(name) == 1:
                methodToShort[methodsDict[name]] = name
                del methodsDict[name]

        for methodName, methodObj in methodsDict.items():
            long = methodName.replace('_', '-')  # t.p.usage does this
            # if this option is already defined by the optFlags or
            # optParameters then we don't want to override that data
            if long in self.optAll_d:
                continue

            descr = self.getDescription(long)

            short = None
            if methodObj in methodToShort:
                short = methodToShort[methodObj]

            reqArgs = methodObj.im_func.func_code.co_argcount
            if reqArgs == 2:
                self.optParams.append([long, short, None, descr])
                self.optParams_d[long] = [short, None, descr]
                self.optAll_d[long] = [short, None, descr]
            elif reqArgs == 1:
                self.optFlags.append([long, short, descr])
                self.optFlags_d[long] = [short, descr]
                self.optAll_d[long] = [short, None, descr]
            else:
                raise SystemExit, 'opt_ method has wrong number of arguments'
Exemplo n.º 11
0
 def _getAsserts(self):
     dct = {}
     accumulateMethods(self, dct, 'assert')
     return [ dct[k] for k in dct if not k.startswith('Not') and k != '_' ]
 def _getAsserts(self):
     dct = {}
     accumulateMethods(self, dct, "assert")
     return [dct[k] for k in dct if not k.startswith("Not") and k != "_"]
Exemplo n.º 13
0
 def autoRegister(self, obj):
     from twisted.python import reflect
     d = {}
     reflect.accumulateMethods(obj, d, self.prefix)
     for k, v in d.items():
         self.registerHandler(k, v)
Exemplo n.º 14
0
 def register(self, obj, check_exists=False):
     d = {}
     reflect.accumulateMethods(obj, d, self.prefix)
     for k, v in d.items():
         self.sub(k, v, check_exists=check_exists)
Exemplo n.º 15
0
 def register(self, obj):
     d = {}
     reflect.accumulateMethods(obj, d, self.prefix)
     for k, v in d.items():
         self.sub(k, v)
Exemplo n.º 16
0
 def register(self, obj):
     d = {}
     reflect.accumulateMethods(obj, d, self.prefix)
     for k,v in d.items():
         self.sub(k, v)