3
U'ícâX ã @ sN d Z ddlZddlZddlZddlZddlZddlZddl m
Z
ddlmZ ddlm
Z
ddlmZ ddlmZ dd lmZ dd
lmZ ejr¦ddlmZ ddlmZ eeje d
ddZG dd dZG dd deZG dd deZG dd deZG dd deZ G dd deZ!G dd deZ"G dd deZ#G d d! d!eZ$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^| j dD ]P}tjj|ks@tjjr4tjj|ks@|tjjkrJt| q|r|dkr|j| qW |S )zSplit 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 ú0/tmp/pip-build-gk9425m9/Jinja2/jinja2/loaders.pyÚsplit_template_path s
r c @ s e Zd ZdZdZdeejeeje ejej g e
f f dddZeje ddd Z
eddeejejeejf ddd
dZd
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