Пример #1
0
    def entangle(fn):
        def method_router(func, self, *args, **kwargs):
            if callable(func):
                name = func.__name__
                method = cherrypy.request.method
                target = name + "_" + method
                alternate = None

                if isinstance(alt_mappings, dict) and \
                  alt_mappings.has_key(method):
                    alternate = alt_mappings[method]
                    if(hasattr(self, alternate) and
                       callable(self.__getattribute__(alternate))):
                        return self.__getattribute__(alternate)(*args, **kwargs)

                if hasattr(self, target) and \
                  callable(self.__getattribute__(target)):
                    return self.__getattribute__(target)(*args, **kwargs)
                elif(default and
                     hasattr(self, default) and
                     callable(self.__getattribute__(default))):
                    return self.__getattribute__(default)(*args, **kwargs)
                elif hasattr(self, name + "_GET"):
                    return self.__getattribute__(name+"_GET")(*args, **kwargs)
                else:
                    raise cherrypy.NotFound()

            else:
                raise cherrypy.NotFound()
        return decorator(method_router)(fn)
Пример #2
0
 def make_decorator(func):
     argnames, varargs, kwargs, defaults = getargspec(func)
     defaults = list(ensure_sequence(defaults))
     defaults = [d for d in defaults if
         argnames[-len(defaults) + defaults.index(d)] not in add]
     argnames = [arg for arg in argnames if arg not in add]
     return decorator(entagle, (argnames, varargs, kwargs, defaults))(func)
Пример #3
0
    def entangle(fn):
        def method_router(func, self, *args, **kwargs):
            if callable(func):
                name = func.__name__
                method = cherrypy.request.method
                target = name + "_" + method
                alternate = None

                if isinstance(alt_mappings, dict) and \
                  alt_mappings.has_key(method):
                    alternate = alt_mappings[method]
                    if (hasattr(self, alternate)
                            and callable(self.__getattribute__(alternate))):
                        return self.__getattribute__(alternate)(*args,
                                                                **kwargs)

                if hasattr(self, target) and \
                  callable(self.__getattribute__(target)):
                    return self.__getattribute__(target)(*args, **kwargs)
                elif (default and hasattr(self, default)
                      and callable(self.__getattribute__(default))):
                    return self.__getattribute__(default)(*args, **kwargs)
                elif hasattr(self, name + "_GET"):
                    return self.__getattribute__(name + "_GET")(*args,
                                                                **kwargs)
                else:
                    raise cherrypy.NotFound()

            else:
                raise cherrypy.NotFound()

        return decorator(method_router)(fn)
Пример #4
0
 def make_decorator(func):
     argnames, varargs, kwargs, defaults = getargspec(func)
     defaults = list(ensure_sequence(defaults))
     defaults = [
         d for d in defaults
         if argnames[-len(defaults) + defaults.index(d)] not in add
     ]
     argnames = [arg for arg in argnames if arg not in add]
     return decorator(entagle, (argnames, varargs, kwargs, defaults))(func)