File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/mako.cpython-310.pyc
Back
o ;j� � @ sp d Z zddlmZmZ dZW n ey dZY nw er6ddlZddlZddl Z ddlZ G dd� de�ZdS dS )z+ Functions for working with Mako templates � )�TemplateCollection�TemplateLookupTFNc @ sD e Zd ZdZddd�Zdd� Zdd � Zddd�Zd d� Zdd� Z d S )�SaltMakoTemplateLookupa Look up Mako template files using file:// or salt:// URLs with <%include/> or <%namespace/>. (1) Look up mako template files on local file system via files://... URL. Make sure mako template file is present locally on minion beforehand. Examples: <%include file="file:///etc/salt/lib/templates/sls-parts.mako"/> <%namespace file="file:///etc/salt/lib/templates/utils.mako" import="helper"/> (2) Look up mako template files on Salt master via salt://... URL. If URL is a relative path (without an URL scheme) then assume it's relative to the directory of the salt file that's doing the lookup. If URL is an absolute path then it's treated as if it has been prefixed with salt://. Examples:: <%include file="templates/sls-parts.mako"/> <%include file="salt://lib/templates/sls-parts.mako"/> <%include file="/lib/templates/sls-parts.mako"/> ##-- treated as salt:// <%namespace file="templates/utils.mako"/> <%namespace file="salt://lib/templates/utils.mako" import="helper"/> <%namespace file="/lib/templates/utils.mako" import="helper"/> ##-- treated as salt:// �baseFc C s. || _ || _d | _|| _tdd�| _i | _d S )N�/��directories)�opts�saltenv�_file_client�pillar_rendr �lookup�cache)�selfr r r � r �C/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/mako.py�__init__2 s zSaltMakoTemplateLookup.__init__c C s | j s tj�| j| j�| _ | j S )z6 Setup and return file_client )r �saltZ fileclientZget_file_clientr r )r r r r �file_client: s �z"SaltMakoTemplateLookup.file_clientc C s@ t j�|�j}|dv r |S |rtd|� d|� ���| j�||�S )N)r �filezUnsupported URL scheme(z) in )�urllib�parse�urlparse�scheme� ValueErrorr � adjust_uri)r �uri�filenamer r r r r D s z!SaltMakoTemplateLookup.adjust_uriNc C s� |� d�rd}d}|}n2d}| jd dkr| jd | j }n tj�| jd d| j�g}|� |�r2|ntjj� |�}| � |� t|d �| _| j� |t|�d � �S ) Nzfile://r zsalt://r �localZ file_rootsZcachedir�filesr )� startswithr r �os�path�joinr �utils�url�create� cache_filer r �get_template�len)r r Z relativeto�protoZ searchpathZsalt_urir r r r( L s � z#SaltMakoTemplateLookup.get_templatec C s. || j vr| �� �|dd| j�| j |<