B g[a[i�@shUddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddl mZddlmZddlmZddlZejr�ddlZejd ejd ejfd �Zed d ddd�i��Zejed<e�Zej eed<dj!Z"eed�dd�Z#eed�dd�Z$eed�dd�Z%Gdd�dej&�Z'eed�dd�Z(eed�dd �Z)eed�d!d"�Z*eed�d#d$�Z+eje,d%�d&d'�Z-ej.ejdd(�d)d*�Z/dd+�d,d-�Z0d`e1e,ejd/�d0d1�Z2dae1e1ej3ej4d3�d4d5�Z5eje1d%�d6d7�Z6eje1d%�d8d9�Z7e�8d:ej9ej:B�Z;e�8d;�Z<dbe1ej3e=ej3e1ej3e1ej3ej.e1e1d<�d=d>�Z>dce=e,e=e=e1dC�dDdE�Z?ddeje1e,e1dG�dHdI�Z@deeje1e,e1dG�dJdK�ZAejBjCGdLdM�dM��ZDdfejEe1ejEe1e,e,ejej3e1ge,fdO�dPdQ�ZFdgejej3ejd e1fejejGdR�dSdT�ZHGdUdV�dV�ZIGdWdX�dX�ZJGdYdZ�dZ�ZKGd[d\�d\ejG�ZGeje1d]�d^d_�ZLdS)h�N)�abc)�deque)�choice)� randrange)�Lock)�CodeType)�quote_from_bytes�F.)�boundZ MissingType��__repr__cCsdS)N�missingr )�xr r �=/opt/alt/python37/lib/python3.7/site-packages/jinja2/utils.py�<lambda>�rr � internal_code�)�f�returncCs tj|_|S)a�Pass the :class:`~jinja2.runtime.Context` as the first argument to the decorated function when called while rendering a template. Can be used on functions, filters, and tests. If only ``Context.eval_context`` is needed, use :func:`pass_eval_context`. If only ``Context.environment`` is needed, use :func:`pass_environment`. .. versionadded:: 3.0.0 Replaces ``contextfunction`` and ``contextfilter``. )�_PassArg�context�jinja_pass_arg)rr r r� pass_contexts rcCs tj|_|S)a�Pass the :class:`~jinja2.nodes.EvalContext` as the first argument to the decorated function when called while rendering a template. See :ref:`eval-context`. Can be used on functions, filters, and tests. If only ``EvalContext.environment`` is needed, use :func:`pass_environment`. .. versionadded:: 3.0.0 Replaces ``evalcontextfunction`` and ``evalcontextfilter``. )r� eval_contextr)rr r r�pass_eval_context/s rcCs tj|_|S)aPass the :class:`~jinja2.Environment` as the first argument to the decorated function when called while rendering a template. Can be used on functions, filters, and tests. .. versionadded:: 3.0.0 Replaces ``environmentfunction`` and ``environmentfilter``. )r� environmentr)rr r r�pass_environment@s rc@s>eZdZe��Ze��Ze��Zee e j dd�dd��Z dS)r)�objrcCs�t|d�r|jSxjdD]b}|�dd�}xP|�d�|�d�fD]8}t||d�dkr<tj|�d |�d �td d �||Sq<WqWdS) Nr)rrr�_r�function�filterFTz= is deprecated and will stop working in Jinja 3.1. Use 'pass_z ' instead.�)� stacklevel)�hasattrr�replace�getattr�warnings�warn�DeprecationWarning)�clsr�prefixZsquashed�namer r r�from_objRs   z_PassArg.from_objN) �__name__� __module__� __qualname__�enum�autorrr� classmethodr �t�Optionalr-r r r rrMs rcCstjdtdd�t|�S)z�Pass the context as the first argument to the decorated function. .. deprecated:: 3.0 Will be removed in Jinja 3.1. Use :func:`~jinja2.pass_context` instead. zZ'contextfunction' is renamed to 'pass_context', the old name will be removed in Jinja 3.1.r")r#)r'r(r)r)rr r r�contextfunctiongs r6cCstjdtdd�t|�S)z�Pass the eval context as the first argument to the decorated function. .. deprecated:: 3.0 Will be removed in Jinja 3.1. Use :func:`~jinja2.pass_eval_context` instead. .. versionadded:: 2.4 zc'evalcontextfunction' is renamed to 'pass_eval_context', the old name will be removed in Jinja 3.1.r")r#)r'r(r)r)rr r r�evalcontextfunctionws r7cCstjdtdd�t|�S)z�Pass the environment as the first argument to the decorated function. .. deprecated:: 3.0 Will be removed in Jinja 3.1. Use :func:`~jinja2.pass_environment` instead. zb'environmentfunction' is renamed to 'pass_environment', the old name will be removed in Jinja 3.1.r")r#)r'r(r)r)rr r r�environmentfunction�s r8cCst�|j�|S)z%Marks the function as internally used)r�add�__code__)rr r r� internalcode�s r;)rrcCsddlm}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 �)� Undefined)Zruntimer=� isinstance)rr=r r r� is_undefined�s r?)�iterablercCsx |D]}qWdS)z4Consumes an iterable without doing anything with it.Nr )r@rr r r�consume�s rA)rcCs,ddlm}ddlm}|��|��dS)a Jinja keeps internal caches for environments and lexers. These are used so that Jinja 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<)�get_spontaneous_environment)� _lexer_cacheN)rrBZlexerrC� cache_clear�clear)rBrCr r r� clear_caches�s  rFF)� import_name�silentrc CsvyRd|kr|�dd�\}}n"d|kr6|�d�\}}}nt|�Stt|dd|g�|�Sttfk rp|sl�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 �:r<�.N)�split� rpartition� __import__r&� ImportError�AttributeError)rGrH�modulerrr r r� import_string�s rQ�rb)�filename�modercCstj�|�sdSt||�S)z\Returns a file descriptor for the filename if that file exists, otherwise ``None``. N)�os�path�isfile�open)rSrTr r r�open_if_exists�s rYcCsJ|dkr dS|tkrdSt|�}|jdkr6|j�d�S|j�d|j�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�builtinsz objectrJ)r[�typer/r.)rr*r r r�object_type_repr�s  r^cCsddlm}||�S)z.Format an object using :func:`pprint.pformat`.r)�pformat)�pprintr_)rr_r r rr_�s r_a@ ^ ( (https?://|www\.) # scheme or www (([\w%-]+\.)+)? # subdomain ( [a-z]{2,63} # basic tld | xn--[\w%]{2,59} # idna tld ) | ([\w%-]{2,63}\.)+ # basic domain (com|net|int|edu|gov|org|info|mil) # basic tld | (https?://) # scheme ( (([\d]{1,3})(\.[\d]{1,3}){3}) # IPv4 | (\[([\da-f]{0,4}:){2}([\da-f]{0,4}:?){1,6}]) # IPv6 ) ) (?::[\d]{1,5})? # port (?:[/?#]\S*)? # path, query, and fragment $ z^\S+@\w[\w.-]*\.\w+$)�text�trim_url_limit�rel�target� extra_schemesrc s��dk rttd��fdd� }nttd�dd�}t�dtt�|���}|rZdt�|��d�nd }|rtd t�|��d�nd }�x@t|�D�]2\} } d | d } } } t�d | �}|r�|��} | |��d�} | � d �r�t� d | �}|r�|��} | d|� ��} xzdD]r\}}| � |�}|| � |�k�r"q�xLt t|| � |���D]4}| �|�t|�}| | d|�7} | |d�} �q8Wq�Wt�| ��r�| �d��s�| �d��r�d| �d|�|�d|| ��d�} n d| �d|�|�d|| ��d�} n�| �d��rt�| dd���rd| �d| dd��d�} n�d| k�rX| �d��sXd| k�rXt�| ��rXd| �d| �d�} nL|dk �r�x@|D]8}| |k�rh| �|��rhd| �d|�|�d| �d�} �qhW| �| �| ��|| <q�Wd �|�S)a;Convert URLs in text into clickable links. This may not recognize links in some situations. Usually, a more comprehensive formatter, such as a Markdown library, is a better choice. Works on ``http://``, ``https://``, ``www.``, ``mailto:``, and email addresses. Links with trailing punctuation (periods, commas, closing parentheses) and leading punctuation (opening parentheses) are recognized excluding the punctuation. Email addresses that include header fields are not recognized (for example, ``mailto:address@example.com?cc=copy@example.com``). :param text: Original text containing URLs to link. :param trim_url_limit: Shorten displayed URL values to this length. :param target: Add the ``target`` attribute to links. :param rel: Add the ``rel`` attribute to links. :param extra_schemes: Recognize URLs that start with these schemes in addition to the default behavior. .. versionchanged:: 3.0 The ``extra_schemes`` parameter was added. .. versionchanged:: 3.0 Generate ``https://`` links for URLs without a scheme. .. versionchanged:: 3.0 The parsing rules were updated. Recognize email addresses with or without the ``mailto:`` scheme. Validate IP addresses. Ignore parentheses and brackets in more cases. N)rrcs"t|��kr|d���d�S|S)Nz...)�len)r)rbr r�trim_urlGs zurlize.<locals>.trim_urlcSs|S)Nr )rr r rrgOsz(\s+)z rel="�"rz target="z ^([(<]|&lt;)+)�)�>rJ�,� z&gt;z([)>.,\n]|&gt;)+$))�(ri)�<rj)z&lt;z&gt;zhttps://zhttp://z <a href="rjz</a>z<a href="https://zmailto:�z">�@zwww.rIz<a href="mailto:)�str�rerK� markupsafe�escape� enumerate�match�group�end�endswith�search�start�count�range�min�indexrf�_http_re� startswith� _email_re�join)rarbrcrdrerg�wordsZrel_attrZ target_attr�i�word�head�middle�tailrvZ start_charZend_charZ start_countrZ end_index�schemer )rbr�urlizesT&     ""       "r��T��d)�n�htmlr~�maxrcCsXddlm}|��}g}�xt|�D�]}d}d} } d} d} g} x�ttt||���D]�\}}xt|�} | | kr`| } Pq`W|r�| ��} d}|tdd�| kr�|} | d 7} | d 7} |td d �| kr�|} } | d 7} d}| �| �qVWd� | �}|� d ��r |dd�d }n|� d ��s |d 7}|�|�q$W|�s>d� |�St � d� dd�|D���S)z+Generate some lorem ipsum for the template.r<)�LOREM_IPSUM_WORDSTrNF��r"rk� r�rJ� ���z rlcss |]}dt�|��d�VqdS)z<p>z</p>N)rsrt)�.0rr r r� <genexpr>�sz'generate_lorem_ipsum.<locals>.<genexpr>) � constantsr�rKr}rurr� capitalize�appendr�ryrs�Markup)r�r�r~r�r�r��resultrZnext_capitalizedZ last_commaZ last_fullstopr��last�p�idxZp_strr r r�generate_lorem_ipsum�sJ     r��utf-8)r�charset�for_qsrcCsPt|t�s&t|t�st|�}|�|�}|r.dnd}t||�}|rL|�dd�}|S)a5Quote a string for use in a URL using the given charset. :param obj: String or bytes to quote. Other types are converted to string then encoded to bytes using the given charset. :param charset: Encode text to bytes using this charset. :param for_qs: Quote "/" and use "+" for spaces. r�/z%20�+)r>�bytesrq�encoderr%)rr�r��safe�rvr r r� url_quote�s      r�cCs&ddl}|jdtdd�t|||d�S)Nrz_'unicode_urlencode' has been renamed to 'url_quote'. The old name will be removed in Jinja 3.1.r")r#)r�r�)r'r(r)r�)rr�r�r'r r r�unicode_urlencode�s r�c@s�eZdZdZedd�dd�Zdd�dd�Zeje ej fd�d d �Z eje ej fdd �d d �Z ej d�dd�Zdd�dd�Zd1ej ej ej d�dd�Zd2ej ej ej d�dd�Zdd�dd�Zej ed�dd�Zed�dd�Ze d�dd�Zej ej d�d d!�Zej ej dd"�d#d$�Zej dd�d%d&�Zejej ej ej fd�d'd(�Zejej d�d)d*�Zejej d�d+d,�Zejej d�d-d.�Zejej d�d/d0�Z eZ!dS)3�LRUCachez"A simple LRU Cache implementation.N)�capacityrcCs ||_i|_t�|_|��dS)N)r��_mappingr�_queue� _postinit)�selfr�r r r�__init__�szLRUCache.__init__)rcCs4|jj|_|jj|_|jj|_t�|_|jj |_ dS)N) r��popleft�_popleft�popZ_pop�remove�_remover�_wlockr��_append)r�r r rr�s    zLRUCache._postinitcCs|j|j|jd�S)N)r�r�r�)r�r�r�)r�r r r� __getstate__szLRUCache.__getstate__)�drcCs|j�|�|��dS)N)�__dict__�updater�)r�r�r r r� __setstate__s zLRUCache.__setstate__cCs|jfS)N)r�)r�r r r�__getnewargs__szLRUCache.__getnewargs__cCs,|�|j�}|j�|j�|j�|j�|S)z&Return a shallow copy of the instance.)� __class__r�r�r�r��extend)r�r�r r r�copys z LRUCache.copy)�key�defaultrcCs"y||Stk r|SXdS)z/Return an item from the cache dict or `default`N)�KeyError)r�r�r�r r r�getsz LRUCache.getcCs*y||Stk r$|||<|SXdS)zvSet `default` if the key is not in the cache otherwise leave unchanged. Return the value of this key. N)r�)r�r�r�r r r� setdefault$s zLRUCache.setdefaultc Cs*|j�|j��|j��WdQRXdS)zClear the cache.N)r�r�rEr�)r�r r rrE.s zLRUCache.clear)r�rcCs ||jkS)z$Check if a key exists in this cache.)r�)r�r�r r r� __contains__4szLRUCache.__contains__cCs t|j�S)z%Return the current size of the cache.)rfr�)r�r r r�__len__8szLRUCache.__len__cCsdt|�j�d|j�d�S)Nrnr�rj)r]r.r�)r�r r rr <szLRUCache.__repr__c Cs\|j�L|j|}|jd|krNy|�|�Wntk rBYnX|�|�|SQRXdS)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�N)r�r�r�r�� ValueErrorr�)r�r�r�r r r� __getitem__?s  zLRUCache.__getitem__)r��valuerc Cs\|j�L||jkr|�|�nt|j�|jkr:|j|��=|�|�||j|<WdQRXdS)zhSets the value for an item. Moves the item up so that it has the highest priority then. N)r�r�r�rfr�r�r�)r�r�r�r r r� __setitem__Us    zLRUCache.__setitem__c CsB|j�2|j|=y|�|�Wntk r2YnXWdQRXdS)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� __delitem__bs zLRUCache.__delitem__cs$�fdd�t�j�D�}|��|S)zReturn a list of items.csg|]}|�j|f�qSr )r�)r�r�)r�r r� <listcomp>psz"LRUCache.items.<locals>.<listcomp>)�listr��reverse)r�r�r )r�r�itemsnszLRUCache.itemscCsdd�|��D�S)zReturn a list of all values.cSsg|] }|d�qS)r<r )r�rr r rr�vsz#LRUCache.values.<locals>.<listcomp>)r�)r�r r r�valuestszLRUCache.valuescCst|�S)z7Return a list of all keys ordered by most recent usage.)r�)r�r r r�keysxsz LRUCache.keyscCstt|j��S)N)�reversed�tupler�)r�r r r�__iter__|szLRUCache.__iter__cCstt|j��S)zTIterate over the keys in the cache dict, oldest items coming first. )�iterr�r�)r�r r r� __reversed__szLRUCache.__reversed__)N)N)"r.r/r0�__doc__�intr�r�r4�Mappingrq�Anyr�r��Tupler�r�r�r�rE�boolr�r�r r�r�r��Iterabler�r�r��Iteratorr�r��__copy__r r r rr��s,   "r��r�Zhtm�xml)�enabled_extensions�disabled_extensions�default_for_stringr�rcsHtdd�|D���tdd�|D���tjttd�����fdd� }|S)acIntelligently sets the initial value of autoescaping based on the filename of the template. This is the recommended way to configure autoescaping if you do not want to write a custom function yourself. If you want to enable it for all templates created from strings or for all templates with `.html` and `.xml` extensions:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( enabled_extensions=('html', 'xml'), default_for_string=True, )) Example configuration to turn it on at all times except if the template ends with `.txt`:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( disabled_extensions=('txt',), default_for_string=True, default=True, )) The `enabled_extensions` is an iterable of all the extensions that autoescaping should be enabled for. Likewise `disabled_extensions` is a list of all templates it should be disabled for. If a template is loaded from a string then the default from `default_for_string` is used. If nothing matches then the initial value of autoescaping is set to the value of `default`. For security reasons this function operates case insensitive. .. versionadded:: 2.9 css"|]}d|�d�����VqdS)rJN)�lstrip�lower)r�rr r rr��sz$select_autoescape.<locals>.<genexpr>css"|]}d|�d�����VqdS)rJN)r�r�)r�rr r rr��s)� template_namercs4|dkr �S|��}|���r"dS|���r0dS�S)NTF)r�ry)r�)r�r��disabled_patterns�enabled_patternsr r� autoescape�s  z%select_autoescape.<locals>.autoescape)r�r4r5rqr�)r�r�r�r�r�r )r�r�r�r�r�select_autoescape�s( r�)r�dumps�kwargsrcKs@|dkrtj}t�||f|��dd��dd��dd��dd ��S) a�Serialize an object to a string of JSON with :func:`json.dumps`, then replace HTML-unsafe characters with Unicode escapes and mark the result safe with :class:`~markupsafe.Markup`. This is available in templates as the ``|tojson`` filter. The following characters are escaped: ``<``, ``>``, ``&``, ``'``. The returned string is safe to render in HTML documents and ``<script>`` tags. The exception is in HTML attributes that are double quoted; either use single quotes or the ``|forceescape`` filter. :param obj: The object to serialize to JSON. :param dumps: The ``dumps`` function to use. Defaults to ``env.policies["json.dumps_function"]``, which defaults to :func:`json.dumps`. :param kwargs: Extra arguments to pass to ``dumps``. Merged onto ``env.policies["json.dumps_kwargs"]``. .. versionchanged:: 3.0 The ``dumper`` parameter is renamed to ``dumps``. .. versionadded:: 2.9 Nrnz\u003crjz\u003e�&z\u0026�'z\u0027)�jsonr�rsr�r%)rr�r�r r r�htmlsafe_json_dumps�s r�c@sXeZdZdZejdd�dd�Zdd�dd�Zeejd�d d ��Z ejd�d d �Z e Z dS) �CycleraDCycle through values by yield them one at a time, then restarting once the end is reached. Available as ``cycler`` in templates. Similar to ``loop.cycle``, but can be used outside loops or across multiple loops. For example, render a list of folders and files in a list, alternating giving them "odd" and "even" classes. .. code-block:: html+jinja {% set row_class = cycler("odd", "even") %} <ul class="browser"> {% for folder in folders %} <li class="folder {{ row_class.next() }}">{{ folder }} {% endfor %} {% for file in files %} <li class="file {{ row_class.next() }}">{{ file }} {% endfor %} </ul> :param items: Each positional argument will be yielded in the order given for each cycle. .. versionadded:: 2.1 N)r�rcGs|s td��||_d|_dS)Nz$at least one item has to be providedr)� RuntimeErrorr��pos)r�r�r r rr�szCycler.__init__)rcCs d|_dS)z*Resets the current item to the first item.rN)r�)r�r r r�resetsz Cycler.resetcCs |j|jS)zxReturn the current item. Equivalent to the item that will be returned next time :meth:`next` is called. )r�r�)r�r r r�current szCycler.currentcCs |j}|jdt|j�|_|S)zXReturn the current item, then advance :attr:`current` to the next item. r<)r�r�rfr�)r�r�r r r�nextsz Cycler.next) r.r/r0r�r4r�r�r��propertyr�r��__next__r r r rr��sr�c@s0eZdZdZd edd�dd�Zed�dd �ZdS) �JoinerzA joining helper for templates.�, N)�seprcCs||_d|_dS)NF)r�used)r�rr r rr�!szJoiner.__init__)rcCs|jsd|_dS|jS)NTr)rr)r�r r r�__call__%szJoiner.__call__)r)r.r/r0r�rqr�rr r r rr�sr�c@sZeZdZdZejejdd�dd�Zeejd�dd�Zeejdd �d d �Z ed �d d�Z dS)� Namespacez~A namespace object that can hold arbitrary attributes. It may be initialized from a dictionary or with keyword arguments.N)�argsr�rcOs&|d|dd�}}t||�|_dS)Nrr<)�dict�_Namespace__attrs)rr�r�r r rr�0szNamespace.__init__)r,rcCsB|dkrt�||�Sy |j|Stk r<t|�d�YnXdS)N>r�r)�object�__getattribute__rr�rO)r�r,r r rr 4s   zNamespace.__getattribute__)r,r�rcCs||j|<dS)N)r)r�r,r�r r rr�=szNamespace.__setitem__)rcCsd|j�d�S)Nz <Namespace rj)r)r�r r rr @szNamespace.__repr__) r.r/r0r�r4r�r�rqr r�r r r r rr,s  rcseZdZd�fdd� Z�ZS)r�rN�strictcs"tjdtdd�t��||||�S)Nzc'jinja2.Markup' is deprecated and will be removed in Jinja 3.1. Import 'markupsafe.Markup' instead.r")r#)r'r(r)�super�__new__)r*�base�encoding�errors)r�r rr Es zMarkup.__new__)rNr )r.r/r0r � __classcell__r r )r�rr�Dsr�)�srcCstjdtdd�t�|�S)Nzc'jinja2.escape' is deprecated and will be removed in Jinja 3.1. Import 'markupsafe.escape' instead.r")r#)r'r(r)rsrt)rr r rrtOs rt)F)rR)NNNN)r�Tr�r�)r�F)r�F)r�r TF)N)Mr1r�rUrr�typingr4r'� collectionsrr�randomrr� threadingr�typesr� urllib.parserrs� TYPE_CHECKINGZtyping_extensions�te�TypeVar�Callabler�r r]r �__annotations__�setr� MutableSetr��concatrrr�Enumrr6r7r8r;r�r?r�rArFrqrQr5�IOrYr^r_�compile� IGNORECASE�VERBOSEr�r�r�r�r�r�r��MutableMapping�registerr�� Collectionr�r�r�r�r�rrtr r r r�<module>s|            *t 5  4&6