human
Complete this python program:
def _weak_lru_cache(maxsize=100):
assistant
#Here is the Python code you requested.

    """Users should only access the lru_cache through its public API:
    cache_info, cache_clear
    The internals of the lru_cache are encapsulated for thread safety and
    to allow the implementation to change.
    """
    def decorating_function(user_function, tuple=tuple, sorted=sorted, len=len, KeyError=KeyError):
        (hits, misses) = ([0], [0])
        kwd_mark = (object(),)
        lock = Lock()
        if (maxsize is None):
            cache = _WeakArgsDict()
            @wraps(user_function)
            def wrapper(*args, **kwds):
                key = args
                if kwds:
                    key += (kwd_mark + tuple(sorted(kwds.items())))
                try:
                    result = cache[key]
                    hits[0] += 1
                    return result
                except KeyError:
                    pass
                result = user_function(*args, **kwds)
                cache[key] = result
                misses[0] += 1
                return result
        else:
            cache = _WeakArgsOrderedDict()
            cache_popitem = cache.popitem
            cache_renew = cache.move_to_end
            @wraps(user_function)
            def wrapper(*args, **kwds):
                key = args
                if kwds:
                    key += (kwd_mark + tuple(sorted(kwds.items())))
                with lock:
                    try:
                        result = cache[key]
                        cache_renew(key)
                        hits[0] += 1
                        return result
                    except KeyError:
                        pass
                result = user_function(*args, **kwds)
                with lock:
                    cache[key] = result
                    misses[0] += 1
                    if (len(cache) > maxsize):
                        cache_popitem(False)
                return result
        def cache_info():
            'Report    cache    statistics'
            with lock:
                return (hits[0], misses[0], maxsize, len(cache))
        def cache_clear():
            'Clear    the    cache    and    cache    statistics'
            with lock:
                cache.clear()
                hits[0] = misses[0] = 0
       ...