U
    |®Þhƒ	  ã                   @   s>   d dl Z d dlmZ G dd„ deƒZG dd„ dƒZdd„ ZdS )	é    N)Úcached_propertyc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Úcached_classmethodaÁ  
    Cache the result of a no-arg class method.
    .. code-block:: python
        class Foo:
            @cached_classmethod
            def bar(cls):
                # Some expensive computation
                return 'baz'
    Similar to ``@lru_cache``, but the cache is per-class, stores a single
    value, and thus doesn't fill up; where as ``@lru_cache`` is global across
    all classes, and could fill up if too many classes were used.
    c                 C   s   || _ t | |¡ d S ©N)ÚfnÚ	functoolsÚupdate_wrapper)Úselfr   © r	   ú`/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/utils/decorators.pyÚ__init__   s    zcached_classmethod.__init__c                 C   s   | | S )z/Get the class_cache for this type when accessedr	   )r   ÚinstanceÚownerr	   r	   r
   Ú__get__   s    zcached_classmethod.__get__c                 C   s   t | || jƒ}|| |< |S )z&Make a new class_cache on cache misses)Ú_cacher   )r   ÚclsÚvaluer	   r	   r
   Ú__missing__   s    zcached_classmethod.__missing__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r	   r	   r	   r
   r   	   s   r   c                   @   s4   e Zd ZdZdd„ Zedd„ ƒZdd„ Zdd	„ Zd
S )r   zBCalls the real class method behind when called, caching the resultc                 C   s"   || _ || _|| _t | |¡ d S r   )Úcacher   r   r   r   )r   r   r   r   r	   r	   r
   r   )   s    z_cache.__init__c                 C   s   |   | j¡S )zGenerate the cached value)r   r   ©r   r	   r	   r
   r   /   s    z_cache.valuec                 C   s   | j S )zGet the cached value)r   r   r	   r	   r
   Ú__call__4   s    z_cache.__call__c                 C   s   | j  | jd¡ dS )zClear the cached value.N)r   Úpopr   r   r	   r	   r
   Úcache_clear8   s    z_cache.cache_clearN)	r   r   r   r   r   r   r   r   r   r	   r	   r	   r
   r   &   s   
r   c                    s   ‡ fdd„}t  ˆ ¡|ƒS )a®  
    Modify a view function so its response has the X-Frame-Options HTTP header
    set to 'SAMEORIGIN'.

    Adapted from Django's xframe_options_sameorigin so that it's always applied
    even if the response already has that header set:
    https://github.com/django/django/blob/3.2/django/views/decorators/clickjacking.py#L22-L37

    Usage:
    @xframe_options_sameorigin_override
    def some_view(request):
        ...
    c                     s   ˆ | |Ž}d|d< |S )NZ
SAMEORIGINzX-Frame-Optionsr	   )ÚargsÚkwargsÚresp©Ú	view_funcr	   r
   Úwrapped_viewM   s    
z8xframe_options_sameorigin_override.<locals>.wrapped_view)r   Úwraps)r    r!   r	   r   r
   Ú"xframe_options_sameorigin_override>   s    r#   )r   Zdjango.utils.functionalr   Údictr   r   r#   r	   r	   r	   r
   Ú<module>   s   