B
    Ö-
dó	  ã               @   s–   d dl Z d dlmZ d dlmZmZ d dlmZ ddlm	Z	m
Z
mZmZ e	de dd	Zee
jƒd
d„ ƒZee
jdddd„ ƒZee
jƒdd„ ƒZdS )é    N)Úsettings)ÚDEFAULT_CACHE_ALIASÚcaches)ÚFileBasedCacheé   )ÚErrorÚTagsÚWarningÚregisterz4You must define a '%s' cache in your CACHES setting.zcaches.E001)Úidc             K   s   t tjkrtgS g S )N)r   r   ÚCACHESÚE001)Úapp_configsÚkwargs© r   ú=/tmp/pip-install-nbqhn9mb/Django/django/core/checks/caches.pyÚ!check_default_cache_is_configured   s    
r   T)Zdeployc                s4  g }x(dD ]}t t|d ƒ}|s$q|dkrltƒ }xH|D ].}t|ttfƒrR|\}}| t |¡ 	¡ ¡ q8W nt |¡ 	¡ h}x®tj
D ]¤}t| }	t|	tƒsœq„t |	j¡ 	¡ ‰ t‡ fdd„|D ƒƒrÈd}
n:t‡ fdd„|D ƒƒräd}
nt‡ fdd„|D ƒƒr„d	}
nq„| td
|› d|
› d|› ddd¡ q„W qW |S )N)Z
MEDIA_ROOTZSTATIC_ROOTÚSTATICFILES_DIRSr   c             3   s   | ]}|ˆ kV  qd S )Nr   )Ú.0Úpath)Ú
cache_pathr   r   ú	<genexpr>*   s    z3check_cache_location_not_exposed.<locals>.<genexpr>Úmatchesc             3   s   | ]}|ˆ j kV  qd S )N)Úparents)r   r   )r   r   r   r   ,   s    z	is insidec             3   s   | ]}ˆ |j kV  qd S )N)r   )r   r   )r   r   r   r   .   s    ÚcontainszYour 'zf' cache configuration might expose your cache or lead to corruption of your data because its LOCATION ú Ú.zcaches.W002)r   )Úgetattrr   ÚsetÚ
isinstanceÚlistÚtupleÚaddÚpathlibÚPathÚresolver   r   r   Z_dirÚanyÚappendr	   )r   r   ÚerrorsÚnameZsettingÚpathsZstaticfiles_dirÚ_ÚaliasÚcacheZrelationr   )r   r   Ú check_cache_location_not_exposed   s8    

r.   c             K   s`   g }xVt j ¡ D ]H\}}t| }t|tƒs,qt |d ¡ ¡ s| 	t
d|› ddd¡ qW |S )NZLOCATIONzYour 'z@' cache LOCATION path is relative. Use an absolute path instead.zcaches.W003)r   )r   r   Úitemsr   r   r   r#   r$   Zis_absoluter'   r	   )r   r   r(   r,   Úconfigr-   r   r   r   Ú"check_file_based_cache_is_absolute;   s    

r1   )r#   Zdjango.confr   Zdjango.core.cacher   r   Z$django.core.cache.backends.filebasedr   Ú r   r   r	   r
   r   r   r.   r1   r   r   r   r   Ú<module>   s   %