o
    r|a	                     @   s,   d Z ddlZddlmZ G dd deZdS )zO
This module supports customized (aka special or specified) template loading.

    N)Loaderc                   @   s2   e Zd ZdZdddZdd Zdd Zd	d
 ZdS )
SpecLoaderzU
    Supports loading custom-specified templates (from TemplateSpec instances).

    Nc                 C   s   |d u rt  }|| _d S N)r   loader)selfr    r   5/usr/lib/python3/dist-packages/pystache/specloader.py__init__   s   
zSpecLoader.__init__c                 C   sV   |j durtj|j S | j }|jdur|j}n||}|||j	}|j
|fS )aY  
        Return the path to the template as a relative (dir, file_name) pair.

        The directory returned is relative to the directory containing the
        class definition of the given object.  The method returns None for
        this directory if the directory is unknown without first searching
        the search directories.

        N)Ztemplate_rel_pathospathsplitr   _make_locatortemplate_nameZmake_template_nameZmake_file_nameZtemplate_extensionZtemplate_rel_directory)r   speclocatorr   	file_namer   r   r   _find_relative   s   





zSpecLoader._find_relativec                 C   sf   |j dur|j S | |\}}| j }|du r$|j|| jj|d}|S ||}tj	|||}|S )zW
        Find and return the path to the template associated to the instance.

        N)r   )
Ztemplate_pathr   r   r   Zfind_objectZsearch_dirsZget_object_directoryr
   r   join)r   r   Zdir_pathr   r   r   Zobj_dirr   r   r   _find5   s   


zSpecLoader._findc                 C   s6   |j dur| j|j |jS | |}| j||jS )z
        Find and return the template associated to a TemplateSpec instance.

        Returns the template as a unicode string.

        Arguments:

          spec: a TemplateSpec instance.

        N)templater   strZtemplate_encodingr   read)r   r   r   r   r   r   loadJ   s   

zSpecLoader.loadr   )__name__
__module____qualname____doc__r	   r   r   r   r   r   r   r   r      s    
r   )r   os.pathr
   Zpystache.loaderr   objectr   r   r   r   r   <module>   s   