A descriptor modifier which caches the result of __get__.
490812
def lazy(decorator):
    """"""
    def decorate(fn, *args, **kwargs):
        name = fn.__name__
        parent = decorator(fn, *args, **kwargs)
        #doc = _add_msg(getattr(parent, '__doc__', None), '*@lazy*')
        doc = getattr(parent, '__doc__', None)
        if hasattr(parent, '__set__') or hasattr(parent, '__delete__'):
            return _lazy_data(name, parent, doc)
        else:
            return _lazy_nondata(name, parent, doc)
    return decorate
1201215
def fd(self):
        """"""
        if isinstance(self._rlist.path_or_fd(), string_types()):
            raise ValueError("File descriptor queried although mapping was generated from path")
        # END handle type
        return self._rlist.path_or_fd()
1031869
def memoize(func, cache, num_args):
    

    @wraps(func)
    def wrapper(*args):
        mem_args = args[:num_args]
        if mem_args in cache:
            return cache[mem_args]
        result = func(*args)
        cache[mem_args] = result
        return result

    return wrapper
82298
def from_def(cls, obj):
        
        prof = cls(obj["steamid"])
        prof._cache = obj

        return prof
37758
def get_descriptor(ctx):
    
    d_net = gluon.nn.Sequential()
    with d_net.name_scope():

        d_net.add(SNConv2D(num_filter=64, kernel_size=4, strides=2, padding=1, in_channels=3, ctx=ctx))
        d_net.add(gluon.nn.LeakyReLU(0.2))

        d_net.add(SNConv2D(num_filter=128, kernel_size=4, strides=2, padding=1, in_channels=64, ctx=ctx))
        d_net.add(gluon.nn.LeakyReLU(0.2))

        d_net.add(SNConv2D(num_filter=256, kernel_size=4, strides=2, padding=1, in_channels=128, ctx=ctx))
        d_net.add(gluon.nn.LeakyReLU(0.2))

        d_net.add(SNConv2D(num_filter=512, kernel_size=4, strides=2, padding=1, in_channels=256, ctx=ctx))
        d_net.add(gluon.nn.LeakyReLU(0.2))

        d_net.add(SNConv2D(num_filter=1, kernel_size=4, strides=1, padding=0, in_channels=512, ctx=ctx))

    return d_net
710134
def cached_property(getter):
    
    def decorator(self):
        key = "_cached_property_" + getter.__name__

        if not hasattr(self, key):
            setattr(self, key, getter(self))

        return getattr(self, key)

    decorator.__name__ = getter.__name__
    decorator.__module__ = getter.__module__
    decorator.__doc__ = getter.__doc__

    return property(decorator)
768114
def cache_as_field(cache_name):
    """"""
    def cache_wrapper(func):
        @functools.wraps(func)
        def inner_wrapper(self, *args, **kwargs):
            value = getattr(self, cache_name, UndefToken)
            if value != UndefToken:
                return value

            ret = func(self, *args, **kwargs)
            setattr(self, cache_name, ret)
            return ret
        return inner_wrapper
    return cache_wrapper
282521
def cache_result(default_size=settings.AVATAR_DEFAULT_SIZE):
    
    if not settings.AVATAR_CACHE_ENABLED:
        def decorator(func):
            return func
        return decorator

    def decorator(func):
        def cached_func(user, size=None, **kwargs):
            prefix = func.__name__
            cached_funcs.add(prefix)
            key = get_cache_key(user, size or default_size, prefix=prefix)
            result = cache.get(key)
            if result is None:
                result = func(user, size or default_size, **kwargs)
                cache_set(key, result)
            return result
        return cached_func
    return decorator
1264496
def Getter(accessor, normalizer=lambda x: x):
    
    if not callable(accessor):
        short_description = get_pretty_name(accessor)
        accessor = attrgetter(accessor)
    else:
        short_description = getattr(accessor, 'short_description', None)

    def getter(obj):
        ret = accessor(obj)
        # handle things like get_absolute_url
        if callable(ret):
            ret = ret()
        return normalizer(ret)

    if short_description:
        getter.short_description = short_description

    return getter
135081
def lazy_result(f):
    """"""
    @wraps(f)
    def decorated(ctx, param, value):
        return LocalProxy(lambda: f(ctx, param, value))
    return decorated
237247
def cached(func):
    """"""
    ret = None

    def call_or_cache(*args, **kwargs):
        nonlocal ret
        if ret is None:
            ret = func(*args, **kwargs)
        return ret

    return call_or_cache
610262
def cache_property(key, empty, type):
    """"""
    return property(lambda x: x._get_cache_value(key, empty, type),
                    lambda x, v: x._set_cache_value(key, v, type),
                    lambda x: x._del_cache_value(key),
                    'accessor for %r' % key)
902628
function loadPresetDescriptor(descriptor) {
  return {
    type: "preset",
    options: loadDescriptor(descriptor).value,
    alias: descriptor.alias,
    loc: descriptor.loc,
    dirname: descriptor.dirname
  };
}
757623
def memoize(obj):
    """"""
    cache = obj.cache = {}

    @functools.wraps(obj)
    def memoizer(*args, **kwargs):
        if args not in cache:
            cache[args] = obj(*args, **kwargs)
        return cache[args]
    return memoizer
575191
def get_descriptor_for_layer(self, layer):
        
        if not layer in self._layer_descriptor_cache:
            params = {'f': 'pjson'}
            if self.token:
                params['token'] = self.token
            response = requests.get(self._build_request(layer), params=params)
            self._layer_descriptor_cache[layer] = response.json()
        return self._layer_descriptor_cache[layer]
1220268
def _write_to_cache(self, expr, res):
        """"""
        res = dedent(res)
        super()._write_to_cache(expr, res)
1163069
def cache_generator(self, key, generator):
        """"""
        results = []
        for result in generator:
            results.append(result)
            yield result

        self.inferred[key] = tuple(results)