B g[a[i@shUddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddl mZddlmZddlmZddlZejrddlZejd ejd ejfd Zed d dddiZejed<eZej eed<dj!Z"eedddZ#eedddZ$eedddZ%Gdddej&Z'eedddZ(eeddd Z)eedd!d"Z*eedd#d$Z+eje,d%d&d'Z-ej.ejdd(d)d*Z/dd+d,d-Z0d`e1e,ejd/d0d1Z2dae1e1ej3ej4d3d4d5Z5eje1d%d6d7Z6eje1d%d8d9Z7e8d:ej9ej:BZ;e8d;ZZ>dce=e,e=e=e1dCdDdEZ?ddeje1e,e1dGdHdIZ@deeje1e,e1dGdJdKZAejBjCGdLdMdMZDdfejEe1ejEe1e,e,ejej3e1ge,fdOdPdQZFdgejej3ejd e1fejejGdRdSdTZHGdUdVdVZIGdWdXdXZJGdYdZdZZKGd[d\d\ejGZGeje1d]d^d_ZLdS)hN)abc)deque)choice) randrange)Lock)CodeType)quote_from_bytesF.)boundZ MissingType__repr__cCsdS)Nmissingr )xr r =/opt/alt/python37/lib/python3.7/site-packages/jinja2/utils.pyrr internal_code)freturncCs tj|_|S)aPass 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``. )_PassArgcontextjinja_pass_arg)rr r r pass_contexts rcCs tj|_|S)aPass 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 rpass_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 rpass_environment@s rc@s>eZdZeZeZeZee e j ddddZ dS)r)objrcCst|dr|jSxjdD]b}|dd}xP|d|dfD]8}t||ddkr.trim_urlcSs|S)Nr )rr r rrgOsz(\s+)z rel=""rz target="z ^([(<]|<)+))>rJ, z>z([)>.,\n]|>)+$))(ri)@zwww.rIzd |St d dd|DS)z+Generate some lorem ipsum for the template.r<)LOREM_IPSUM_WORDSTrNFr"rk rrJ z rlcss |]}dt|dVqdS)z

z

N)rsrt).0rr r r sz'generate_lorem_ipsum..) constantsrrKr}rurr capitalizeappendrryrsMarkup)rrr~rrrresultrZnext_capitalizedZ last_commaZ last_fullstoprlastpidxZp_strr r rgenerate_lorem_ipsumsJ     rutf-8)rcharsetfor_qsrcCsPt|ts&t|tst|}||}|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>bytesrqencoderr%)rrrsafervr r r url_quotes      rcCs&ddl}|jdtddt|||dS)Nrz_'unicode_urlencode' has been renamed to 'url_quote'. The old name will be removed in Jinja 3.1.r")r#)rr)r'r(r)r)rrrr'r r runicode_urlencodes rc@seZdZdZeddddZddddZeje ej fdd d Z eje ej fdd d d Z ej dddZddddZd1ej ej ej dddZd2ej ej ej dddZddddZej edddZedddZe dddZej ej dd d!Zej ej dd"d#d$Zej ddd%d&Zejej ej ej fdd'd(Zejej dd)d*Zejej dd+d,Zejej dd-d.Zejej dd/d0Z eZ!dS)3LRUCachez"A simple LRU Cache implementation.N)capacityrcCs ||_i|_t|_|dS)N)r_mappingr_queue _postinit)selfrr r r__init__szLRUCache.__init__)rcCs4|jj|_|jj|_|jj|_t|_|jj |_ dS)N) rpopleft_popleftpopZ_popremove_remover_wlockr_append)rr r rrs    zLRUCache._postinitcCs|j|j|jdS)N)rrr)rrr)rr r r __getstate__szLRUCache.__getstate__)drcCs|j||dS)N)__dict__updater)rrr r r __setstate__s zLRUCache.__setstate__cCs|jfS)N)r)rr r r__getnewargs__szLRUCache.__getnewargs__cCs,||j}|j|j|j|j|S)z&Return a shallow copy of the instance.) __class__rrrrextend)rrr r rcopys z LRUCache.copy)keydefaultrcCs"y||Stk r|SXdS)z/Return an item from the cache dict or `default`N)KeyError)rrrr r rgetsz 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)rrrr r r setdefault$s zLRUCache.setdefaultc Cs*|j|j|jWdQRXdS)zClear the cache.N)rrrEr)rr r rrE.s zLRUCache.clear)rrcCs ||jkS)z$Check if a key exists in this cache.)r)rrr r r __contains__4szLRUCache.__contains__cCs t|jS)z%Return the current size of the cache.)rfr)rr r r__len__8szLRUCache.__len__cCsdt|jd|jdS)Nrnrrj)r]r.r)rr r rr <szLRUCache.__repr__c Cs\|jL|j|}|jd|krNy||Wntk rBYnX|||SQRXdS)zGet 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. rN)rrrr ValueErrorr)rrrr r r __getitem__?s  zLRUCache.__getitem__)rvaluerc Cs\|jL||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)rrrrfrrr)rrrr r r __setitem__Us    zLRUCache.__setitem__c CsB|j2|j|=y||Wntk r2YnXWdQRXdS)z]Remove an item from the cache dict. Raise a `KeyError` if it does not exist. N)rrrr)rrr r r __delitem__bs zLRUCache.__delitem__cs$fddtjD}||S)zReturn a list of items.csg|]}|j|fqSr )r)rr)rr r psz"LRUCache.items..)listrreverse)rrr )rritemsnszLRUCache.itemscCsdd|DS)zReturn a list of all values.cSsg|] }|dqS)r<r )rrr r rrvsz#LRUCache.values..)r)rr r rvaluestszLRUCache.valuescCst|S)z7Return a list of all keys ordered by most recent usage.)r)rr r rkeysxsz LRUCache.keyscCstt|jS)N)reversedtupler)rr r r__iter__|szLRUCache.__iter__cCstt|jS)zTIterate over the keys in the cache dict, oldest items coming first. )iterrr)rr r r __reversed__szLRUCache.__reversed__)N)N)"r.r/r0__doc__intrrr4MappingrqAnyrrTuplerrrrrEboolrrr rrrIterablerrrIteratorrr__copy__r r r rrs,   "rrZhtmxml)enabled_extensionsdisabled_extensionsdefault_for_stringrrcsHtdd|Dtdd|Dtjttdfdd }|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|dVqdS)rJN)lstriplower)rrr r rrsz$select_autoescape..css"|]}d|dVqdS)rJN)rr)rrr r rrs) template_namercs4|dkr S|}|r"dS|r0dSS)NTF)rry)r)rrdisabled_patternsenabled_patternsr r autoescapes  z%select_autoescape..autoescape)rr4r5rqr)rrrrrr )rrrrrselect_autoescapes( r)rdumpskwargsrcKs@|dkrtj}t||f|dddddddd S) aSerialize 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 ``