1 from inspect import isclass, getargspec
4 def is_gilbert_plugin(class_or_instance):
5 from philo.contrib.gilbert.options import GilbertPluginBase, GilbertPlugin
6 return (isclass(class_or_instance) and issubclass(class_or_instance, GilbertPlugin)) or isinstance(class_or_instance, GilbertPlugin) or (getattr(class_or_instance, '__metaclass__', None) is GilbertPluginBase) or (getattr(class_or_instance, 'gilbert_plugin', False) and (getattr(class_or_instance, 'gilbert_plugin_name', None) is not None) and (getattr(class_or_instance, 'gilbert_plugin_classes', None) is not None))
9 def is_gilbert_class(class_or_instance):
10 from philo.contrib.gilbert.options import GilbertClassBase, GilbertClass
11 return (isclass(class_or_instance) and issubclass(class_or_instance, GilbertClass)) or isinstance(class_or_instance, GilbertClass) or (getattr(class_or_instance, '__metaclass__', None) is GilbertClassBase) or (getattr(class_or_instance, 'gilbert_class', False) and (getattr(class_or_instance, 'gilbert_class_name', None) is not None) and (getattr(class_or_instance, 'gilbert_class_methods', None) is not None))
14 def is_gilbert_method(function):
15 return getattr(function, 'gilbert_method', False)
18 def gilbert_method(function=None, name=None, argc=None, restricted=True):
19 def wrapper(function):
20 setattr(function, 'gilbert_method', True)
21 setattr(function, 'gilbert_method_name', name or function.__name__)
22 setattr(function, 'gilbert_method_restricted', restricted)
25 args = getargspec(function)[0]
30 new_argc = new_argc - 1
32 if args[0] == 'request':
34 new_argc = new_argc - 1
35 setattr(function, 'gilbert_method_argc', new_argc)
37 if function is not None:
38 return wrapper(function)
42 def call_gilbert_method(method, cls, request, *args, **kwargs):
43 arg_list = getargspec(method)[0]
45 if arg_list[0] == 'self':
46 if len(arg_list) > 1 and arg_list[1] == 'request':
47 return method(cls, request, *args, **kwargs)
48 return method(cls, *args, **kwargs)
49 elif arg_list[0] == 'request':
50 return method(request, *args, **kwargs)
52 return method(*args, **kwargs)