arte/utils/decorator.py
def cache_on_disk(fname=None, fname_func=None, adapter=FitsFileCache):
    '''
    Decorator that caches a function result into a local file.

    The file can be specified as either a constant filename, or a function
    that returns a filename. The second form is useful if the filename is not
    known when the function is defined, but only at runtime.

    Roughly equivalent to:

        if adapter.check(fname):
            data = adapter.load(fname)
        else:
            data = f()
            adapter.store(fname, data)
        return data

    Parameters
    ----------
    fname : str, optional
        name of the file where the data is stored. One of `filename` and
        `fname_func` must be specified.
    fname_func : callable, optional
        function or callable without arguments that returns a filename,
        to be used in case the name changes at runtime.
    adapter : class
        class managing the load/store to file, optional. By default FITS
        files will be used as storage.
    '''
    if (fname is None and fname_func is None) or \
       (fname is not None and fname_func is not None):
        raise ValueError('One of filename and fname_func must be specified')

    # Always use fname_func, binding the current value of filename.
    if fname:

        def fname_func():
            return fname

    def decorator(f):

        @wraps(f)
        def cache_result_into_files(*args, **kwargs):
            fname = fname_func()
            if adapter.check(fname):
                return adapter.load(fname)
            else:
                data = f(*args, **kwargs)
                adapter.store(fname, data)
                return data

        return cache_result_into_files

    return decorator

    Decorator that caches a function result into a local file.

    The file can be specified as either a constant filename, or a function
    that returns a filename. The second form is useful if the filename is not
    known when the function is defined, but only at runtime.

    Roughly equivalent to:

        if adapter.check(fname):
            data = adapter.load(fname)
        else:
            data = f()
            adapter.store(fname, data)
        return data

    Parameters
    ----------
    fname : str, optional
        name of the file where the data is stored. One of `filename` and
        `fname_func` must be specified.
    fname_func : callable, optional
        function or callable without arguments that returns a filename,
        to be used in case the name changes at runtime.
    adapter : class
        class managing the load/store to file, optional. By default FITS
        files will be used as storage.
    
Decorator that caches a function result into a local file.
The file can be specified as either a constant filename, or a function
that returns a filename. The second form is useful if the filename is not
known when the function is defined, but only at runtime.

Roughly equivalent to.



Parameters

fname : str, optional
name of the file where the data is stored. One of `filename` and
`fname_func` must be specified.
fname_func : callable, optional
function or callable without arguments that returns a filename,
to be used in case the name changes at runtime.
adapter : class
class managing the load/store to file, optional. By default FITS
files will be used as storage.
Decorator that caches a function result into a local file . The file can be specified as either a constant filename or a function that returns a filename . The second form is useful if the filename is not known when the function is defined but only at runtime . Roughly equivalent to . Parameters fname : str optional name of the file where the data is stored . One of ` filename ` and ` fname_func ` must be specified . fname_func : callable optional function or callable without arguments that returns a filename to be used in case the name changes at runtime . adapter : class class managing the load / store to file optional . By default FITS files will be used as storage .
def cache_on_disk(fname=None, fname_func=None, adapter=FitsFileCache):
    if (fname is None and fname_func is None) or \
       (fname is not None and fname_func is not None):
        raise ValueError('One of filename and fname_func must be specified')
    if fname:
        def fname_func():
            return fname
    def decorator(f):
        @wraps(f)
        def cache_result_into_files(*args, **kwargs):
            fname = fname_func()
            if adapter.check(fname):
                return adapter.load(fname)
            else:
                data = f(*args, **kwargs)
                adapter.store(fname, data)
                return data
        return cache_result_into_files
    return decorator
def cache_on_disk ( fname = None , fname_func = None , adapter = FitsFileCache ) : if ( fname is None and fname_func is None ) or ( fname is not None and fname_func is not None ) : raise ValueError ( 'One of filename and fname_func must be specified' ) if fname : def fname_func ( ) : return fname def decorator ( f ) : @ wraps ( f ) def cache_result_into_files ( * args , ** kwargs ) : fname = fname_func ( ) if adapter . check ( fname ) : return adapter . load ( fname ) else : data = f ( * args , ** kwargs ) adapter . store ( fname , data ) return data return cache_result_into_files return decorator
Decorator that caches a function result into a local file.
Decorator that caches a function result into a local file .
'''
    Decorator that caches a function result into a local file.

    The file can be specified as either a constant filename, or a function
    that returns a filename. The second form is useful if the filename is not
    known when the function is defined, but only at runtime.

    Roughly equivalent to:

        if adapter.check(fname):
            data = adapter.load(fname)
        else:
            data = f()
            adapter.store(fname, data)
        return data

    Parameters
    ----------
    fname : str, optional
        name of the file where the data is stored. One of `filename` and
        `fname_func` must be specified.
    fname_func : callable, optional
        function or callable without arguments that returns a filename,
        to be used in case the name changes at runtime.
    adapter : class
        class managing the load/store to file, optional. By default FITS
        files will be used as storage.
    ''' # Always use fname_func, binding the current value of filename.
fname
fname_func
adapter