| Server IP : 93.86.61.54 / Your IP : 216.73.216.156 Web Server : Apache/2.4.62 (Ubuntu) System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64 User : www-data ( 33) PHP Version : 8.4.22 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/lib/python3/dist-packages/pystache/__pycache__/ |
Upload File : |
o
r|a � @ sL d Z ddlZddlmZ ddlmZ ddlmZ dd� ZG dd � d e�Z dS )
zJ
This module provides a Loader class for locating and reading templates.
� N)�common)�defaults)�Locatorc C s ddd�} | S )Nc S s |du rt j}t| |t j�S )zW
Raises a TypeError exception if the given string is already unicode.
N)r �STRING_ENCODING�str�
DECODE_ERRORS)�s�encoding� r
�1/usr/lib/python3/dist-packages/pystache/loader.py�
to_unicode s z$_make_to_unicode.<locals>.to_unicode�Nr
)r r
r
r �_make_to_unicode s
r c @ sV e Zd ZdZ ddd�Zdd� Zddd�Zdd d
�Zdd� Zd
d� Z dd� Z
dS )�Loaderz�
Loads the template associated to a name or user-defined object.
All load_*() methods return the template as a unicode string.
Nc C sT |du rt j}|du rt j}|du rt j}|du rt� }|| _|| _|| _|| _dS )a
Construct a template loader instance.
Arguments:
extension: the template file extension, without the leading dot.
Pass False for no extension (e.g. to use extensionless template
files). Defaults to the package default.
file_encoding: the name of the encoding to use when converting file
contents to unicode. Defaults to the package default.
search_dirs: the list of directories in which to search when loading
a template by name or file name. Defaults to the package default.
to_unicode: the function to use when converting strings of type
str to unicode. The function should have the signature:
to_unicode(s, encoding=None)
It should accept a string of type str and an optional encoding
name and return a string of type unicode. Defaults to calling
Python's built-in function unicode() using the package string
encoding and decode errors defaults.
N) r �TEMPLATE_EXTENSION�
FILE_ENCODING�SEARCH_DIRSr � extension�
file_encoding�search_dirsr )�selfr r r r r
r
r �__init__) s !
zLoader.__init__c C s t | jd�S )N)r )r r )r r
r
r �
_make_locator\ s zLoader._make_locatorc C s t |t�r t|�S | �||�S )an
Convert a string to unicode using the given encoding, and return it.
This function uses the underlying to_unicode attribute.
Arguments:
s: a basestring instance to convert to unicode. Unlike Python's
built-in unicode() function, it is okay to pass unicode strings
to this function. (Passing a unicode string to Python's unicode()
with the encoding argument throws the error, "TypeError: decoding
Unicode is not supported.")
encoding: the encoding to pass to the to_unicode attribute.
Defaults to None.
)�
isinstancer r )r r r r
r
r r _ s
z
Loader.strc C sD t �|�}|du r| j}t�� dkr| �||��dd�S | �||�S )zZ
Read the template at the given path, and return it as a unicode string.
N�Windows�
� )r �readr �platform�systemr �replace)r �pathr �br
r
r r v s
zLoader.readc C � | � � }|�|| j�}| �|�S )z�
Find and return the template with the given file name.
Arguments:
file_name: the file name of the template.
)r � find_filer r )r � file_name�locatorr! r
r
r � load_file� �
zLoader.load_filec C r# )z�
Find and return the template with the given template name.
Arguments:
name: the name of the template.
)r � find_namer r )r �namer&