3 �N�f*Q � @ s� d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z ddlmZ ddl mZmZmZmZ edf d d d� i�� Ze� ZdjZd ejd�kZdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Z dDdd�Z!dEd!d"�Z"d#d$� Z#dFd%d&�Z$dGd'd(�Z%dHd-d.�Z&dId0d1�Z'G d2d3� d3e(�Z)ydd4lm*Z* e*j+e)� W n e,k �rP Y nX dJf d*dfd8d9�Z-dKd:d;�Z.eG d<d=� d=e(��Z/G d>d?� d?e(�Z0G d@dA� dAe(�Z1ye2dB� d*Z3W n e4k �r� dZ3Y nX ddCl5m6Z6m7Z7m8Z8 dS )Lz� jinja2.utils ~~~~~~~~~~~~ Utility functions. :copyright: (c) 2017 by the Jinja Team. :license: BSD, see LICENSE for more details. � N)�deque)� ascii_letters)�digits)�Lock)� text_type�string_types�implements_iterator� url_quoteZMissingType�__repr__c C s dS )N�missing� )�xr r �/usr/lib/python3.6/utils.py�<lambda> s r � z\/�/c C s d| _ | S )a+ This decorator can be used to mark a function or method context callable. A context callable is passed the active :class:`Context` as first argument when called from the template. This is useful if a function wants to get access to the context or functions provided on the context object. For example a function that returns a sorted list of template variables the current template exports could look like this:: @contextfunction def get_exported_names(context): return sorted(context.exported_vars) T)�contextfunction)�fr r r r s r c C s d| _ | S )aG This decorator can be used to mark a function or method as an eval context callable. This is similar to the :func:`contextfunction` but instead of passing the context, an evaluation context object is passed. For more information about the eval context, see :ref:`eval-context`. .. versionadded:: 2.4 T)�evalcontextfunction)r r r r r 0 s r c C s d| _ | S )z�This decorator can be used to mark a function or method as environment callable. This decorator works exactly like the :func:`contextfunction` decorator just that the first argument is the active :class:`Environment` and not context. T)�environmentfunction)r r r r r = s r c C s t j| j� | S )z%Marks the function as internally used)� internal_code�add�__code__)r r r r �internalcodeG s r c C s ddl m} t| |�S )a� Check if the object passed is undefined. This does nothing more than performing an instance check against :class:`Undefined` but looks nicer. This can be used for custom filters or tests that want to react to undefined variables. For example a custom default filter can look like this:: def default(var, default=''): if is_undefined(var): return default return var r )� Undefined)Zjinja2.runtimer � isinstance)�objr r r r �is_undefinedM s r c C s x| D ]}qW dS )z4Consumes an iterable without doing anything with it.Nr )�iterableZeventr r r �consume] s r c C s, ddl m} ddlm} | j� |j� dS )a" Jinja2 keeps internal caches for environments and lexers. These are used so that Jinja2 doesn't have to recreate environments and lexers all the time. Normally you don't have to care about that but if you are measuring memory consumption you may want to clean the caches. r )�_spontaneous_environments)�_lexer_cacheN)Zjinja2.environmentr Zjinja2.lexerr! �clear)r r! r r r �clear_cachesc s r# Fc C s� yfd| kr| j dd�\}}n6d| krJ| j d�}dj|dd� �}|d }nt| �S tt|dd|g�|�S ttfk r� |s�� Y nX dS )a� Imports an object based on a string. This is useful if you want to use import paths as endpoints or something similar. An import path can be specified either in dotted notation (``xml.sax.saxutils.escape``) or with a colon as object delimiter (``xml.sax.saxutils:escape``). If the `silent` is True the return value will be `None` if the import fails. :return: imported object �:� �.N���r'