
    h                     J    S r SSKrSSKJr  SSKJr  SSKJr   " S S\5      rg)	z
Wrapper class that takes a list of template loaders as an argument and attempts
to load templates from them in order, caching the result.
    N)TemplateDoesNotExist)copy_exception   )Loaderc                   `   ^  \ rS rSrU 4S jrS rS rSU 4S jjrS rSS jr	S r
S	 rS
rU =r$ )r      c                 ^   > 0 U l         UR                  U5      U l        [        TU ]  U5        g N)get_template_cacheget_template_loadersloaderssuper__init__)selfenginer   	__class__s      P/var/www/html/env/lib/python3.13/site-packages/django/template/loaders/cached.pyr   Loader.__init__   s*    "$227;     c              #      #    U R                    H.  n[        US5      (       d  M  UR                  5        S h  vN   M0     g  N	7f)Nget_dirs)r   hasattrr   )r   loaders     r   r   Loader.get_dirs   s3     llFvz**!??,,, #,s   AAA
Ac                 8    UR                   R                  U5      $ r
   )r   get_contents)r   origins     r   r   Loader.get_contents   s    }}))&11r   c                   > U R                  X5      nU R                  R                  U5      nU(       aT  [        U[        5      (       a  [        U[        5      (       a  U" U5      e[        U[        5      (       a  [        U5      eU$  [        TU ]%  X5      nXPR                  U'   U$ ! [         a?  nU R                  R                  (       a  [        U5      O[        U R                  U'   e SnAff = f)a  
Perform the caching that gives this loader its name. Often many of the
templates attempted will be missing, so memory use is of concern here.
To keep it in check, caching behavior is a little complicated when a
template is not found. See ticket #26306 for more details.

With template debugging disabled, cache the TemplateDoesNotExist class
for every missing template and raise a new instance of it after
fetching it from the cache.

With template debugging enabled, a unique TemplateDoesNotExist object
is cached for each missing template to preserve debug data. When
raising an exception, Python sets __traceback__, __context__, and
__cause__ attributes on it. Those attributes can contain references to
all sorts of objects up the call chain and caching them creates a
memory leak. Thus, unraised copies of the exceptions are cached and
copies of those copies are raised after they're fetched from the cache.
N)	cache_keyr   get
isinstancetype
issubclassr   r   r   get_templater   debug)r   template_nameskipkeycachedtemplateer   s          r   r%   Loader.get_template   s    & nn]1((,,S1&$''Jv?S,T,T]++F$899$V,,M	4w+M@H ,4##C( $ 	%)[[%6%6q!<P ##C( 		s   
B) )
C23:C--C2c              #   h   #    U R                    H  nUR                  U5       S h  vN   M     g  N	7fr
   )r   get_template_sources)r   r'   r   s      r   r/   Loader.get_template_sourcesD   s*     llF22=AAA #As   $20
2c                     SnU(       aE  U Vs/ s H   oDR                   U:X  d  M  UR                  PM"     nnU(       a  U R                  U5      nSR                  S [	        U5      U4 5       5      $ s  snf )a*  
Generate a cache key for the template name and skip.

If skip is provided, only origins that match template_name are included
in the cache key. This ensures each template is only parsed and cached
once if contained in different extend chains like:

    x -> a -> a
    y -> a -> a
    z -> a -> a
 -c              3   6   #    U  H  o(       d  M  Uv   M     g 7fr
    ).0ss     r   	<genexpr>#Loader.cache_key.<locals>.<genexpr>]   s     J#Da#Ds   
	)r'   namegenerate_hashjoinstr)r   r'   r(   skip_prefixr   matchings         r   r    Loader.cache_keyH   sr     *.*.2F2F-2W$   "00:xxJC$6#DJJJs
   A2A2c                     [         R                  " SR                  U5      R                  5       5      R	                  5       $ )N|)hashlibsha1r<   encode	hexdigest)r   valuess     r   r;   Loader.generate_hash_   s,    ||CHHV,3356@@BBr   c                 8    U R                   R                  5         g)zEmpty the template cache.N)r   clear)r   s    r   resetLoader.resetb   s    %%'r   )r   r   r
   )__name__
__module____qualname____firstlineno__r   r   r   r%   r/   r    r;   rK   __static_attributes____classcell__)r   s   @r   r   r      s4    !
-
2&PBK.C( (r   r   )	__doc__rC   django.templater   django.template.backends.djangor   baser   
BaseLoaderr5   r   r   <module>rX      s&   
  0 : &V(Z V(r   