U
    	|e                     @   s   d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZmZ dd Zdd	 Zd
d Zdd Zdd ZdddZdd Zdd Zdd ZG dd dZdS )    )settings)TemplateVariableVariableNode)Context)get_template)	BlockNodeExtendsNodec                 C   s   t | tr| jS | jjS d S N)
isinstancer   nodelisttemplate)tpl r   L/var/www/website-v5/atlas_env/lib/python3.8/site-packages/sekizai/helpers.py_get_nodelist   s    
r   c                 C   sH   t | dr| jrdS t | drDt | jdrD| jjs@t| jjtrDdS dS )Nparent_name_exprTparent_namefiltersF)hasattrr   r   r   r   varr   )noder   r   r   is_variable_extend_node   s    r   c                  C   s   t  } td| _| S )N )r   r   r   )contextr   r   r   get_context   s    
r   c                 C   s   t | rdS | t }t|tD ]X}|j|kr@|||j< q&||j }g }t|jdrx|j|krx|	|j |j}qN||_q&t|t
D ]}t||  qqdS )z^
    Extends the dictionary `blocks` with *new* blocks in the parent node
    (recursive)
    Nr   )r   
get_parentr   r   get_nodes_by_typer   namer   superappendr	   _extend_blocks)extend_nodeblocksparentr   blockZseen_supersr   r   r   r!      s"    


r!   c                 C   s   t | rg S | j}t| | g }| D ]}|t|j|7 }q(| t }t|	t
sl|tt|d7 }n|tt|| 7 }|S )z^
    Returns a list of namespaces found in the parent template(s) of this
    ExtendsNode
    N)r   r#   r!   values_scan_namespacesr   r   r   r   r   r	   )r"   r#   foundr%   Zparent_templater   r   r   _extend_nodelist;   s$    
r)   Nc                 C   s   ddl m}m} g }| D ]}t|||frV||jd i  |t|jd |7 }qt|t	rn|t
|7 }qt|tr|r|jjdkrt|jdr|t|jj|j7 }q|S )Nr   )RenderBlockWithDatar   r   zblock.super)Z!sekizai.templatetags.sekizai_tagsr*   r+   r   r    kwargsresolver'   r#   r	   r)   r   filter_expressiontokenr   r   r   )r   current_blockr*   r+   r(   r   r   r   r   r'   Y   s     
r'   c                 C   s   t | }tt|S r
   )r   r'   r   )r   Zcompiled_templater   r   r   get_namespacesq   s    r1   c                 C   s4   t tddrdS t| }|D ]}||kr dS qdS )zs
    Validates that a template (or it's parents if check_inheritance is True)
    contain all given namespaces
    ZSEKIZAI_IGNORE_VALIDATIONFT)getattrr   r1   )r   
namespacesr(   	namespacer   r   r   validate_templatev   s    r5   c                   C   s   t tddS )NZSEKIZAI_VARNAMEZSEKIZAI_CONTENT_HOLDER)r2   r   r   r   r   r   get_varname   s    r6   c                   @   s,   e Zd ZdZdd Zedd Zdd ZdS )	Watcherz
    Watches a context for changes to the sekizai data, so it can be replayed
    later. This is useful for caching.

    NOTE: This class assumes you ONLY ADD, NEVER REMOVE data from the context!
    c                 C   s    || _ dd | j D | _d S )Nc                 S   s   i | ]\}}|t |qS r   )list).0keyvaluer   r   r   
<dictcomp>   s     z$Watcher.__init__.<locals>.<dictcomp>)r   dataitemsfrozen)selfr   r   r   r   __init__   s    zWatcher.__init__c                 C   s   | j t i S r
   )r   getr6   )r@   r   r   r   r=      s    zWatcher.datac                    s   t | j}t | j}||A }i }|D ]}t| j| ||< q$||@ }|D ]2}t | j|   fdd| j| D }|||< qH|S )Nc                    s   g | ]}| kr|qS r   r   )r9   itemZold_setr   r   
<listcomp>   s     z'Watcher.get_changes.<locals>.<listcomp>)setr?   r=   r8   )r@   ZsfrozenZsdataZnew_keyschangesr:   Zshared_keys
new_valuesr   rD   r   get_changes   s    



zWatcher.get_changesN)__name__
__module____qualname____doc__rA   propertyr=   rI   r   r   r   r   r7      s
   
r7   )N)django.confr   Zdjango.template.baser   r   r   django.template.contextr   django.template.loaderr   Zdjango.template.loader_tagsr   r	   r   r   r   r!   r)   r'   r1   r5   r6   r7   r   r   r   r   <module>   s   

