
    >Tf`                     l    d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
 dZ G d de          Zd	 Zd
S )    )apps)
BaseLoaderTemplateNotFound)find_referenced_templates)SandboxedEnvironment)
get_config)DataFileLoaderc                   $    e Zd ZdZd Zd Zd ZdS )r	   zX
    Custom Jinja2 loader to facilitate populating template content from DataFiles.
    c                 "    || _         i | _        d S N)data_source_template_cache)selfr   s     5/var/www/html/netbox-4.1.3/netbox/utilities/jinja2.py__init__zDataFileLoader.__init__   s    &!    c                 T   t          j        dd          }	 | j        |         }n# t          $ r t	          |          w xY wt          |                    |                    x}r>|                     d |j        	                    | j
        |          D                        ||d fS )NcoreDataFilec                 (    i | ]}|j         |j        S  )pathdata_as_string).0dfs     r   
<dictcomp>z-DataFileLoader.get_source.<locals>.<dictcomp>    s,     " " "/1*" " "r   )sourcepath__inc                      dS )NTr   r   r   r   <lambda>z+DataFileLoader.get_source.<locals>.<lambda>%   s    $ r   )r   	get_modelr   KeyErrorr   r   parsecache_templatesobjectsfilterr   )r   environmenttemplater   template_sourcereferenced_templatess         r   
get_sourcezDataFileLoader.get_source   s    >&*55	-"28<OO 	- 	- 	-"8,,,	- $=[=N=N=_=_#`#`` 	   " " ''t/?J^'__" " "   
 ,,66s   % ?c                 :    | j                             |           d S r   )r   update)r   	templatess     r   r$   zDataFileLoader.cache_templates'   s    ##I.....r   N)__name__
__module____qualname____doc__r   r+   r$   r   r   r   r	   r	      sK         " " "7 7 7$/ / / / /r   r	   c                     t                      }|j                            t                      j                    |                    |           j        di |S )zZ
    Render a Jinja2 template with the provided context. Return the rendered content.
    )r   r   )r   filtersr-   r   JINJA2_FILTERSfrom_stringrender)template_codecontextr'   s      r   render_jinja2r:   /   sW     '((Kz||:;;;?;""-"88?JJ'JJJr   N)django.appsr   jinja2r   r   jinja2.metar   jinja2.sandboxr   netbox.configr   __all__r	   r:   r   r   r   <module>rA      s          / / / / / / / / 1 1 1 1 1 1 / / / / / / $ $ $ $ $ $
/ / / / /Z / / /DK K K K Kr   