Example #1
0
    def __init__(self, func, *args, **kwargs):
        """ Wrap func in a ArgCache. """

        ## Keep the original function's name and docstring
        ## If the original function has any more-complicated attrs,
        ## don't bother to maintain them; we have our own attrs,
        ## and merging custom stuff could be dangerous.
        if hasattr(func, '__name__'):
            self.__name__ = func.__name__
        if hasattr(func, '__doc__'):
            self.__doc__ = func.__doc__

        import inspect

        self.argspec = inspect.getargspec(func)
        self.func = func
        params = self.argspec[0]
        extra_name = kwargs.pop('uid_extra', '')
        name = describe_func(func) + extra_name
        uid = get_uid(func) + extra_name
        if self.argspec[1] is not None:
            raise ESPError(), "ArgCache does not support varargs."
        if self.argspec[2] is not None:
            raise ESPError(), "ArgCache does not support keywords."

        super(ArgCacheDecorator, self).__init__(name=name,
                                                params=params,
                                                uid=uid,
                                                *args,
                                                **kwargs)
Example #2
0
 def check_for_instance(func, *args, **kwargs):
     """ Protect against stupid Django/Python multiple imports."""
     import inspect
     params = inspect.getargspec(func)[
         0]  # FIXME: Make an esp.cache.functions or something
     uid = get_uid(func)
     # We don't really care about the name yet
     return ArgCache.check_for_instance(None, params, uid)