Example #1
0
 def test_is_function_instance_method(self):
     class Foo(object):
         def method(self):
             pass
         @staticmethod
         def staticmethod():
             pass
         @classmethod
         def classmethod(cls):
             pass
     f = Foo()
     self.assertTrue(is_function(f.method))
     self.assertTrue(is_function(f.staticmethod))
     self.assertTrue(is_function(f.classmethod))
Example #2
0
    def test_is_function_instance_method(self):
        class Foo(object):
            def method(self):
                pass

            @staticmethod
            def staticmethod():
                pass

            @classmethod
            def classmethod(cls):
                pass
        f = Foo()
        self.assertTrue(util.is_function(f.method))
        self.assertTrue(util.is_function(f.staticmethod))
        self.assertTrue(util.is_function(f.classmethod))
Example #3
0
def get_obj_cls(obj):
    if not obj or util.is_function(obj):
        return None

    if util.is_container(obj):
        return obj

    if not util.is_primitive(obj):
        return type(obj)

    return None
Example #4
0
 def _flatten_dict_obj(self, obj, data):
     """_flatten_dict_obj recursively calls to flatten() on a dictionary's values.
     and places them into data.
     """
     for k, v in obj.iteritems():
         if util.is_function(v):
             continue
         if type(k) not in types.StringTypes:
             k = repr(k)
         self._namestack.append(k)
         data[k] = self.flatten(v)
         self._namestack.pop()
     return data
Example #5
0
 def _flatten_dict_obj(self, obj, data):
     """_flatten_dict_obj recursively calls to flatten() on a dictionary's values.
     and places them into data.
     """
     for k, v in obj.iteritems():
         if util.is_function(v):
             continue
         if type(k) not in types.StringTypes:
             k = repr(k)
         self._namestack.append(k)
         data[k] = self.flatten(v)
         self._namestack.pop()
     return data
Example #6
0
 def test_is_function_lambda(self):
     self.assertTrue(is_function(lambda: False))
Example #7
0
 def test_is_function_builtins(self):
     self.assertTrue(is_function(globals))
Example #8
0
 def test_is_function_lambda(self):
     self.assertTrue(util.is_function(lambda: False))
Example #9
0
 def test_is_function_builtins(self):
     self.assertTrue(util.is_function(globals))