%PDF- %PDF-
Direktori : /snap/core/17212/usr/lib/python3/dist-packages/jinja2/__pycache__/ |
Current File : //snap/core/17212/usr/lib/python3/dist-packages/jinja2/__pycache__/loaders.cpython-35.pyc |
$�U�C � @ sl d Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z m Z d d l m Z m Z d d � Z Gd d � d e � Z Gd d � d e � Z Gd d � d e � Z Gd d � d e � Z Gd d � d e � Z Gd d � d e � Z Gd d � d e � Z Gd d � d e � Z Gd d � d e � Z d S)z� jinja2.loaders ~~~~~~~~~~~~~~ Jinja loader classes. :copyright: (c) 2010 by the Jinja Team. :license: BSD, see LICENSE for more details. � N)� ModuleType)�path)�sha1)�TemplateNotFound)�open_if_exists�internalcode)�string_types� iteritemsc C s� g } x{ | j d � D]j } t j | k sR t j rC t j | k sR | t j k ra t | � � q | r | d k r | j | � q W| S)z�Split a path into segments and perform a sanity check. If it detects '..' in the path it will raise a `TemplateNotFound` error. �/�.)�splitr �sep�altsep�pardirr �append)�template�piecesZpiece� r �0/usr/lib/python3/dist-packages/jinja2/loaders.py�split_template_path s r c @ sI e Z d Z d Z d Z d d � Z d d � Z e d d d � � Z d 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 file(path) as f: source = f.read().decode('utf-8') return source, path, lambda: mtime == getmtime(path) Tc C s/ | j s t d | j j � � t | � � d S)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 unicode string or a ASCII bytestring. 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&%s cannot provide access to the sourceN)�has_source_access�RuntimeError� __class__�__name__r )�self�environmentr r r r � get_sourceF s zBaseLoader.get_sourcec C s t d � � d S)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_templates] s zBaseLoader.list_templatesNc C s� d } | d k r i } | j | | � \ } } } | j } | d k ri | j | | | | � } | j } | d k r� | j | | | � } | d k r� | j d k r� | | _ | j | � | j 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 �name�globalsr �source�filename�uptodateZbccZbucketr r r �loadc s zBaseLoader.load) r � __module__�__qualname__�__doc__r r r r r( r r r r r % s r c @ s@ e Z d Z d Z d d d d � Z d d � Z d d � Z d S)�FileSystemLoadera" Loads templates from the file system. This loader can find templates in folders on the file system and is the preferred way to load them. The loader takes the path to the templates as string, or if multiple locations are wanted a list of them which is then looked up in the given order:: >>> loader = FileSystemLoader('/path/to/templates') >>> loader = FileSystemLoader(['/path/to/templates', '/other/path']) Per default the template encoding is ``'utf-8'`` which can be changed by setting the `encoding` parameter to something else. To follow symbolic links, set the *followlinks* parameter to ``True``:: >>> loader = FileSystemLoader('/path/to/templates', followlinks=True) .. versionchanged:: 2.8+ The *followlinks* parameter was added. zutf-8Fc C s= t | t � r | g } t | � | _ | | _ | | _ d S)N)� isinstancer �list� searchpath�encoding�followlinks)r r/ r0 r1 r r r �__init__� s zFileSystemLoader.__init__c s� t | � } x� | j D]� } t j | | � � t � � } | d k rI q z | j � j | j � } Wd | j � Xt j � � � � � f d d � } | � | f SWt | � � d S)Nc s4 y t j � � � k SWn t k r/ d SYn Xd S)NF)r �getmtime�OSErrorr )r&