OwlCyberSecurity - MANAGER
Edit File: loaders.cpython-37.pyc
B ����G؊a�X������������������@���sN��d�Z�ddlZddlZddlZddlZddlZddlZddl m Z �ddlmZ�ddlm Z �ddlmZ�ddlmZ�dd lmZ�dd lmZ�ejr�ddlmZ�ddlmZ�eeje�d �dd�ZG�dd��d�ZG�dd��de�ZG�dd��de�ZG�dd��de�ZG�dd��de�Z G�dd��de�Z!G�dd��de�Z"G�dd��de�Z#G�d d!��d!e�Z$dS�)"zKAPI and implementations for loading templates from different data sources. �����N)�abc)�sha1)� import_module)� ModuleType����)�TemplateNotFound)�internalcode)�open_if_exists)�Environment)�Template)�template�returnc�������������C���sh���g�}x^|���d�D�]P}tjj|ks@tjjr4tjj|ks@|tjjkrJt|���q|r|dkr|�|��qW�|S�)z�Split a path into segments and perform a sanity check. If it detects '..' in the path it will raise a `TemplateNotFound` error. �/�.)�split�os�path�sep�altsep�pardirr����append)r����piecesZpiece��r����?/opt/alt/python37/lib/python3.7/site-packages/jinja2/loaders.py�split_template_path���s���� r���c������������ ���@���s����e�Zd�ZdZdZdeejeeje�ejej g�e f��f�d�dd�Zeje�d�dd �Z eddeejejeejf��dd�d d��Zd S�)� BaseLoadera���Baseclass for all loaders. Subclass this and override `get_source` to implement a custom loading mechanism. The environment provides a `get_template` method that calls the loader's `load` method to get the :class:`Template` object. A very basic example for a loader that looks up templates on the file system could look like this:: from jinja2 import BaseLoader, TemplateNotFound from os.path import join, exists, getmtime class MyLoader(BaseLoader): def __init__(self, path): self.path = path def get_source(self, environment, template): path = join(self.path, template) if not exists(path): raise TemplateNotFound(template) mtime = getmtime(path) with open(path) as f: source = f.read() return source, path, lambda: mtime == getmtime(path) Tr ���)�environmentr���r ���c�������������C���s&���|�j�stt|��j��d���t|��dS�)a���Get the template source, filename and reload helper for a template. It's passed the environment and template name and has to return a tuple in the form ``(source, filename, uptodate)`` or raise a `TemplateNotFound` error if it can't locate the template. The source part of the returned tuple must be the source of the template as a string. The filename should be the name of the file on the filesystem if it was loaded from there, otherwise ``None``. The filename is used by Python for the tracebacks if no loader extension is used. The last item in the tuple is the `uptodate` function. If auto reloading is enabled it's always called to check if the template changed. No arguments are passed so the function must store the old state somewhere (for example in a closure). If it returns `False` the template will be reloaded. z$ cannot provide access to the sourceN)�has_source_access�RuntimeError�type�__name__r���)�selfr���r���r���r���r���� get_sourceJ���s����zBaseLoader.get_source)r ���c�������������C���s���t�d��dS�)z�Iterates over all templates. If the loader does not support that it should raise a :exc:`TypeError` which is the default behavior. z-this loader cannot iterate over all templatesN)� TypeError)r!���r���r���r����list_templatesd���s����zBaseLoader.list_templatesNr���)r����name�globalsr ���c������� ������C���s����d}|dkri�}|���||�\}}}|j}|dk rF|�||||�} | j}|dkr\|�|||�}|dk r~| jdkr~|| _|�| ��|j�||||�S�)ac��Loads a template. This method looks up the template in the cache or loads one by calling :meth:`get_source`. Subclasses should not override this method as loaders working on collections of other loaders (such as :class:`PrefixLoader` or :class:`ChoiceLoader`) will not call this method but `get_source` directly. N)r"���Zbytecode_cacheZ get_bucket�code�compileZ set_bucket�template_classZ from_code) r!���r���r%���r&���r'����source�filename�uptodateZbcc�bucketr���r���r����loadj���s���� zBaseLoader.load)N)r ���� __module__�__qualname__�__doc__r����str�t�Tuple�Optional�Callable�boolr"����Listr$���r����MutableMapping�Anyr.���r���r���r���r���r���)���s���0r���c���������������@���s����e�Zd�ZdZdejeejej ejeejf��f�ee dd�dd�Zdeejeeej g�e f�f�d �d d�Zeje�d�d d�ZdS�)�FileSystemLoadera��Load templates from a directory in the file system. The path can be relative or absolute. Relative paths are relative to the current working directory. .. code-block:: python loader = FileSystemLoader("templates") A list of paths can be given. The directories will be searched in order, stopping at the first matching template. .. code-block:: python loader = FileSystemLoader(["/override/templates", "/default/templates"]) :param searchpath: A path, or list of paths, to the directory that contains the templates. :param encoding: Use this encoding to read the text from template files. :param followlinks: Follow symbolic links in the path. .. versionchanged:: 2.8 Added the ``followlinks`` parameter. �utf-8FN)� searchpath�encoding�followlinksr ���c�������������C���s<���t�|tj�rt�|t�r|g}dd��|D��|�_||�_||�_d�S�)Nc�������������S���s���g�|�]}t��|��qS�r���)r����fspath)�.0�pr���r���r���� <listcomp>����s����z-FileSystemLoader.__init__.<locals>.<listcomp>)� isinstancer����Iterabler2���r=���r>���r?���)r!���r=���r>���r?���r���r���r����__init__����s ����zFileSystemLoader.__init__r ���)r���r���r ���c���������� ������s����t�|�}xz|�jD�]p}tjj|f|�����t���}|d�kr8qz|����|�j�}W�d�|� ���X�tj� ����td����fdd�}|��|fS�W�t|��d�S�)N)r ���c������������������s*���yt�j�����kS��tk r$���dS�X�d�S�)NF)r���r����getmtime�OSErrorr���)r+����mtimer���r���r,�������s����z-FileSystemLoader.get_source.<locals>.uptodate) r���r=���r���r����joinr ����read�decoder>����closerG���r7���r���)r!���r���r���r���r=����f�contentsr,���r���)r+���rI���r���r"�������s���� zFileSystemLoader.get_source)r ���c������� ������C���s����t���}x�|�jD�]�}tj||�jd�}x~|D�]v\}}}xj|D�]b}tj�||�t|�d����tjj �� tjj d�}|d�d��dkr�|dd���}||kr8|�|��q8W�q(W�qW�t|�S�)N)r?���r�������z./) �setr=���r����walkr?���r���rJ����len�stripr����replace�add�sorted) r!����foundr=���Zwalk_dir�dirpath�_� filenamesr+���r���r���r���r���r$�������s���� zFileSystemLoader.list_templates)r<���F)r ���r/���r0���r1���r3����Unionr2���r����PathLike�Sequencer7���rF���r4���r6���r"���r8���r$���r���r���r���r���r;�������s����( $r;���c������������ ���@���sh���e�Zd�ZdZdededd�dd�Zd eejeeejej g�e f��f�d �dd�Zeje�d �dd�Z dS�)� PackageLoaderal��Load templates from a directory in a Python package. :param package_name: Import name of the package that contains the template directory. :param package_path: Directory within the imported package that contains the templates. :param encoding: Encoding of template files. The following example looks up templates in the ``pages`` directory within the ``project.ui`` package. .. code-block:: python loader = PackageLoader("project.ui", "pages") Only packages installed as directories (standard pip behavior) or zip/egg files (less common) are supported. The Python API for introspecting data in packages is too limited to support other installation methods the way this loader requires. There is limited support for :pep:`420` namespace packages. The template directory is assumed to only be in one namespace contributor. Zip files contributing to a namespace are not supported. .. versionchanged:: 3.0 No longer uses ``setuptools`` as a dependency. .. versionchanged:: 3.0 Limited PEP 420 namespace package support. � templates�utf-8r2���N)�package_name�package_pathr>���r ���c������� ������C���sl��t�j�|��t�jj�}|t�jjkr(d}n(|d�d��t�jjt�jj�krP|dd���}||�_||�_||�_t |��t j�|�}|d�k s�t d��|j}|d�k s�t d��||�_d�|�_d�}t|tj�r�|j|�_tt|j��}t�j�||�}njg�}|jr�|�|j��n |jd�k �r|�t�j�|j���x0|D�](} t�j�| |�} t�j�| ��r| }P��qW�|d�k�rbtd|�d���||�_d�S�)N��rP���z-An import spec was not found for the package.z'A loader was not found for the package.zThe zC package was not installed in a way that PackageLoader understands.) r���r����normpath�rstripr����curdirrc���rb���r>���r���� importlib�util� find_spec�AssertionError�loader�_loader�_archiverD���� zipimport�zipimporter�archive�next�iter�submodule_search_locationsrJ����extend�originr����dirname�isdir� ValueError�_template_root) r!���rb���rc���r>����specrl���Z template_rootZpkgdir�roots�rootr���r���r���rF�����sD���� zPackageLoader.__init__r ���)r���r���r ���c���������� ������s����t�jj|�jft|�����|�jd�krvt�j���s6t|��t�d��}|� ��}W�d�Q�R�X�t�j� ����td����fdd�}nBy|�j� ��}W�n,�tk r��}�zt|�|�W�d�d�}~X�Y�nX�d�}|�|�j��|fS�)N�rb)r ���c������������������s���t�j���ot�j�����kS�)N)r���r����isfilerG���r���)rI���rB���r���r���� up_to_dateV��s����z,PackageLoader.get_source.<locals>.up_to_date)r���r���rJ���rz���r���rn���r���r����openrK���rG���r7���rm����get_datarH���rL���r>���)r!���r���r���rN���r*���r�����er���)rI���rB���r���r"���F��s���� zPackageLoader.get_source)r ���c����������������s���g�}|�j�d�krdt|�j�}x�t�|�j�D�]8\��}}��|d����tjj���|���fdd�|D����q&W�n�t |�j d�sxtd��|�jt|�j��d����tjj�tjj�}t|�}xL|�j j� ��D�]<}|�|�r�|d�tjjkr�|�||d����tjjd���q�W�|����|S�)Nc�������������3���s(���|�] }t�j���|��t�jjd��V��qdS�)r���N)r���r���rJ���rU���r���)rA���r%���)rY���r���r���� <genexpr>q��s���z/PackageLoader.list_templates.<locals>.<genexpr>�_fileszFThis zip import does not have the required metadata to list templates.���r���)rn���rS���rz���r���rR����lstripr���r���ru����hasattrrm���r#���r�����keys� startswithr���rU����sort)r!����results�offsetrZ���r[����prefixr%���r���)rY���r���r$���g��s&���� "zPackageLoader.list_templates)r`���ra���)r ���r/���r0���r1���r2���rF���r3���r4���r5���r6���r7���r"���r8���r$���r���r���r���r���r_�������s����7*r_���c���������������@���sf���e�Zd�ZdZejeef�dd�dd�Zdeejedej g�e f�f�d�dd �Zeje�d �dd�Z dS�) � DictLoadera��Loads a template from a Python dict mapping template names to template source. This loader is useful for unittesting: >>> loader = DictLoader({'index.html': 'source here'}) Because auto reloading is rarely useful this is disabled per default. N)�mappingr ���c�������������C���s ���||�_�d�S�)N)r����)r!���r����r���r���r���rF������s����zDictLoader.__init__r ���)r���r���r ���c����������������s6������j�kr*��j�����d�����fdd�fS�t���d�S�)Nc������������������s������j����kS�)N)r�����getr���)r!���r*���r���r���r����<lambda>��������z'DictLoader.get_source.<locals>.<lambda>)r����r���)r!���r���r���r���)r!���r*���r���r���r"������s���� zDictLoader.get_source)r ���c�������������C���s ���t�|�j�S�)N)rW���r����)r!���r���r���r���r$������s����zDictLoader.list_templates)r ���r/���r0���r1���r3����Mappingr2���rF���r4���r6���r7���r"���r8���r$���r���r���r���r���r�������s ���$r����c���������������@���s����e�Zd�ZdZejegejejeej eeje�ejejg�e f��f�f��f�dd�dd�Zdeej eeje�ejejg�e f��f�d�dd �ZdS�) �FunctionLoadera���A loader that is passed a function which does the loading. The function receives the name of the template and has to return either a string with the template source, a tuple in the form ``(source, filename, uptodatefunc)`` or `None` if the template does not exist. >>> def load_template(name): ... if name == 'index.html': ... return '...' ... >>> loader = FunctionLoader(load_template) The `uptodatefunc` is a function that is called if autoreload is enabled and has to return `True` if the template is still up to date. For more details have a look at :meth:`BaseLoader.get_source` which has the same return value. N)� load_funcr ���c�������������C���s ���||�_�d�S�)N)r����)r!���r����r���r���r���rF������s����zFunctionLoader.__init__r ���)r���r���r ���c�������������C���s2���|���|�}|d�krt|��t|t�r.|d�d�fS�|S�)N)r����r���rD���r2���)r!���r���r����rvr���r���r���r"������s���� zFunctionLoader.get_source) r ���r/���r0���r1���r3���r6���r2���r5���r\���r4���r7���rF���r"���r���r���r���r���r�������s���0r����c������������ ���@���s����e�Zd�ZdZdejeef�edd�dd�Zeej eef�d�dd �Z d eej eeje�ejejg�e f��f�d�dd �Zedd eejejeejf��dd�dd��Zeje�d�dd�ZdS�)�PrefixLoadera��A loader that is passed a dict of loaders where each loader is bound to a prefix. The prefix is delimited from the template by a slash per default, which can be changed by setting the `delimiter` argument to something else:: loader = PrefixLoader({ 'app1': PackageLoader('mypackage.app1'), 'app2': PackageLoader('mypackage.app2') }) By loading ``'app1/index.html'`` the file from the app1 package is loaded, by loading ``'app2/index.html'`` the file from the second. r���N)r����� delimiterr ���c�������������C���s���||�_�||�_d�S�)N)r����r����)r!���r����r����r���r���r���rF������s����zPrefixLoader.__init__)r���r ���c���������� ���C���sZ���y |��|�jd�\}}|�j|�}W�n0�ttfk rP�}�zt|�|�W�d�d�}~X�Y�nX�||fS�)Nr���)r���r����r����ry����KeyErrorr���)r!���r���r����r%���rl���r����r���r���r���� get_loader���s����zPrefixLoader.get_loaderr ���)r���r���r ���c���������� ���C���sL���|���|�\}}y|�||�S��tk rF�}�zt|�|�W�d�d�}~X�Y�nX�d�S�)N)r����r"���r���)r!���r���r���rl���r%���r����r���r���r���r"������s ����zPrefixLoader.get_sourcer���)r���r%���r&���r ���c���������� ���C���sN���|���|�\}}y|�|||�S��tk rH�}�zt|�|�W�d�d�}~X�Y�nX�d�S�)N)r����r.���r���)r!���r���r%���r&���rl���Z local_namer����r���r���r���r.������s ����zPrefixLoader.load)r ���c�������������C���sF���g�}x<|�j����D�].\}}x$|���D�]}|�||�j�|���q"W�qW�|S�)N)r�����itemsr$���r���r����)r!����resultr����rl���r���r���r���r���r$�����s ����zPrefixLoader.list_templates)r���)N)r ���r/���r0���r1���r3���r����r2���r���rF���r4���r����r5���r6���r7���r"���r���r9���r:���r.���r8���r$���r���r���r���r���r�������s��� 0 r����c������������ ���@���s����e�Zd�ZdZeje�dd�dd�Zdeej eej e�ej ejg�ef��f�d�dd �Z eddeej ejeejf��d d�dd ��Zeje�d�dd�ZdS�)�ChoiceLoadera���This loader works like the `PrefixLoader` just that no prefix is specified. If a template could not be found by one loader the next one is tried. >>> loader = ChoiceLoader([ ... FileSystemLoader('/path/to/user/templates'), ... FileSystemLoader('/path/to/system/templates') ... ]) This is useful if you want to allow users to override builtin templates from a different location. N)�loadersr ���c�������������C���s ���||�_�d�S�)N)r����)r!���r����r���r���r���rF�����s����zChoiceLoader.__init__r ���)r���r���r ���c���������� ���C���s>���x0|�j�D�]&}y|�||�S��tk r,���Y�qX�qW�t|��d�S�)N)r����r"���r���)r!���r���r���rl���r���r���r���r"��� ��s���� zChoiceLoader.get_sourcer���)r���r%���r&���r ���c���������� ���C���s@���x2|�j�D�](}y|�|||�S��tk r.���Y�qX�qW�t|��d�S�)N)r����r.���r���)r!���r���r%���r&���rl���r���r���r���r.���*��s���� zChoiceLoader.load)r ���c�������������C���s,���t���}x|�jD�]}|�|�����qW�t|�S�)N)rQ���r�����updater$���rW���)r!���rX���rl���r���r���r���r$���8��s����zChoiceLoader.list_templates)N)r ���r/���r0���r1���r3���r^���r���rF���r2���r4���r5���r6���r7���r"���r���r9���r:���r.���r8���r$���r���r���r���r���r������s���0r����c���������������@���s���e�Zd�ZdZdS�)�_TemplateModulez9Like a normal module but with support for weak referencesN)r ���r/���r0���r1���r���r���r���r���r����?��s���r����c���������������@���s����e�Zd�ZdZdZejeej ej ejeej f��f�dd�dd�Zeeed�dd ��Z eeed�d d��Zeddeejejeejf��d d�dd��ZdS�)�ModuleLoadera6��This loader loads templates from precompiled templates. Example usage: >>> loader = ChoiceLoader([ ... ModuleLoader('/path/to/compiled/templates'), ... FileSystemLoader('/path/to/templates') ... ]) Templates can be precompiled with :meth:`Environment.compile_templates`. FN)r���r ���c����������������sn���dt�|��d����t���}t|tj�r.t|t�r4|g}dd��|D��|_t�|��fdd��t j ��<�||�_��|�_d�S�)NZ_jinja2_module_templates_�xc�������������S���s���g�|�]}t��|��qS�r���)r���r@���)rA���rB���r���r���r���rC���^��s����z)ModuleLoader.__init__.<locals>.<listcomp>c����������������s���t�j���d��S�)N)�sys�modules�pop)r����)rb���r���r���r����a��r����z'ModuleLoader.__init__.<locals>.<lambda>) �idr����rD���r���rE���r2����__path__�weakref�proxyr����r�����modulerb���)r!���r����modr���)rb���r���rF���R��s����zModuleLoader.__init__)r%���r ���c�������������C���s���dt�|��d������S�)NZtmpl_zutf-8)r����encode� hexdigest)r%���r���r���r����get_template_keyj��s����zModuleLoader.get_template_keyc�������������C���s���t��|��d�S�)Nz.py)r����r����)r%���r���r���r����get_module_filenamen��s����z ModuleLoader.get_module_filenamer ���r���)r���r%���r&���r ���c���������� ���C���s����|���|�}|�j��d|���}t|�j|d��}|d�kr�yt|d�d�dg�}W�n,�tk rp�}�zt|�|�W�d�d�}~X�Y�nX�tj� |d���|d�kr�i�}|j �||j|�S�)Nr���r}���) r����rb����getattrr����� __import__�ImportErrorr���r����r����r����r)���Zfrom_module_dict�__dict__)r!���r���r%���r&����keyr����r����r����r���r���r���r.���r��s���� zModuleLoader.load)N)r ���r/���r0���r1���r���r3���r\���r2���r���r]���r^���rF����staticmethodr����r����r���r5���r9���r:���r.���r���r���r���r���r����C��s���"r����)%r1����importlib.utilrh���r���r�����typingr3���r����ro����collectionsr����hashlibr���r����typesr���� exceptionsr����utilsr���r ���� TYPE_CHECKINGr���r ���r���r2���r8���r���r���r;���r_���r����r����r����r����r����r����r���r���r���r����<module>���s6���nS�"-?0