U aQi@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 MC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-8gbwd15f\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_argrr 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_contextrrr 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 environmentrrr r rpass_environment@s rc@s>eZdZeZeZeZee e j ddddZ dS)robjrcCst|dr|jSdD]f}|dd}|d|dfD]@}t||ddkr8tj|d |d td d ||Sq8qdS) Nr)rrr_rfunctionfilterFTz= is deprecated and will stop working in Jinja 3.1. Use 'pass_z ' instead. stacklevel)hasattrrreplacegetattrwarningswarnDeprecationWarning)clsr!prefixZsquashednamer r rfrom_objRs  z_PassArg.from_objN) __name__ __module__ __qualname__enumautorrr classmethodr tOptionalr1r r r rrMs rcCstjdtddt|S)zPass 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-rrr r rcontextfunctiongs r:cCstjdtddt|S)zPass 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-rrr r revalcontextfunctionws r;cCstjdtddt|S)zPass 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-rrr r renvironmentfunctions r<cCst|j|S)z%Marks the function as internally used)radd__code__rr r r internalcodes r?r cCsddlm}t||S)aCheck 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)ZruntimerA isinstance)r!rAr r r is_undefineds rC)iterablercCs|D]}qdS)z4Consumes an iterable without doing anything with it.Nr )rDr"r r rconsumesrErcCs,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)rrGlexerrH cache_clearclear)rGrHr r r clear_cachess  rLF) import_namesilentrc CszzVd|kr|dd\}}n$d|kr6|d\}}}n t|WStt|dd|g|WSttfk rt|spYnXdS)aImports 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* ImportErrorAttributeError)rMrNmoduler!r"r r r import_strings  rWrb)filenamemodercCstj|sdSt||S)z\Returns a file descriptor for the filename if that file exists, otherwise ``None``. N)ospathisfileopen)rYrZr r ropen_if_existss r_cCsJ|dkr dS|tkrdSt|}|jdkr6|jdS|jd|jdS)zReturns 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`). NNoneEllipsisbuiltinsz objectrP)ratyper3r2)r!r.r r robject_type_reprs  rdcCsddlm}||S)z.Format an object using :func:`pprint.pformat`.r)pformat)pprintre)r!rer r rres rea@ ^ ( (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+$)texttrim_url_limitreltarget extra_schemesrc sdk rttdfdd }nttddd}tdtt|}|rZdt|dnd }|rtd t|dnd }t|D]&\} } d | d } } } td | }|r|} | |d} | d rt d | }|r|} | d| } dD]n\}}| |}|| |krqt t|| |D]4}| |t|}| | d|7} | |d} q0qt| r| ds| drd| d||d|| d} n d| d||d|| d} n| dr t| ddr d| d| ddd} nd| krL| dsLd| krLt| rLd| d| d} nH|dk r|D]8}| |krZ| |rZd| d||d| d} qZ| | | || <qd |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|ddS|S)Nz...)lenrrhr rtrim_urlGs zurlize..trim_urlcSs|SNr rr r rrnOsz(\s+)z rel=""rz target="z ^([(<]|<)+))>rP, >z([)>.,\n]|>)+$))(rq)@zwww.rOzz

N)r|r}.0rr r r sz'generate_lorem_ipsum..) constantsrrQrr~rr capitalizeappendrrr|Markup)rrrrrrresultr"Znext_capitalizedZ last_commaZ last_fullstoprlastpidxZp_strr r rgenerate_lorem_ipsumsJ        rutf-8)r!charsetfor_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+)rBbytesrzencoderr))r!rrsafervr 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)r!rrr+r r runicode_urlencodesrc@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|_|dSro)r_mappingr_queue _postinit)selfrr r r__init__szLRUCache.__init__rFcCs4|jj|_|jj|_|jj|_t|_|jj |_ dSro) rpopleft_popleftpopZ_popremove_remover_wlockr_appendrr r rrs    zLRUCache._postinitcCs|j|j|jdS)Nrrrrrr r r __getstate__szLRUCache.__getstate__)drcCs|j||dSro)__dict__updater)rrr r r __setstate__s zLRUCache.__setstate__cCs|jfSro)rrr r r__getnewargs__szLRUCache.__getnewargs__cCs,||j}|j|j|j|j|S)z&Return a shallow copy of the instance.) __class__rrrrextendrrr r rcopys z LRUCache.copy)keydefaultrcCs(z ||WStk r"|YSXdS)z/Return an item from the cache dict or `default`NKeyErrorrrrr r rgets z LRUCache.getcCs0z ||WStk r*|||<|YSXdS)zvSet `default` if the key is not in the cache otherwise leave unchanged. Return the value of this key. Nrrr r r setdefault$s  zLRUCache.setdefaultc Cs*|j|j|jW5QRXdS)zClear the cache.N)rrrKrrr r rrK.s zLRUCache.clear)rrcCs ||jkS)z$Check if a key exists in this cache.rrrr r r __contains__4szLRUCache.__contains__cCs t|jS)z%Return the current size of the cache.)rlrrr r r__len__8szLRUCache.__len__cCsdt|jd|jdS)Nrwrrr)rcr2rrr r rr <szLRUCache.__repr__c Csh|jX|j|}|jd|krNz||Wntk rBYnX|||W5QRSQRXdS)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|<W5QRXdS)zhSets the value for an item. Moves the item up so that it has the highest priority then. N)rrrrlrrr)rrrr r r __setitem__Us    zLRUCache.__setitem__c CsB|j2|j|=z||Wntk r2YnXW5QRXdS)z]Remove an item from the cache dict. Raise a `KeyError` if it does not exist. N)rrrrrr r r __delitem__bs zLRUCache.__delitem__cs$fddtjD}||S)zReturn a list of items.csg|]}|j|fqSr r)rrrr r psz"LRUCache.items..)listrreverse)rrr rritemsnszLRUCache.itemscCsdd|DS)zReturn a list of all values.cSsg|] }|dqS)r@r rr r rrvsz#LRUCache.values..)rrr r rvaluestszLRUCache.valuescCst|S)z7Return a list of all keys ordered by most recent usage.)rrr r rkeysxsz LRUCache.keyscCstt|jSro)reversedtuplerrr r r__iter__|szLRUCache.__iter__cCstt|jS)zTIterate over the keys in the cache dict, oldest items coming first. )iterrrrr r r __reversed__szLRUCache.__reversed__)N)N)"r2r3r4__doc__intrrr8MappingrzAnyrrTuplerrrrrKboolrrr 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|dVqdSrPNlstriplowerrr r rrsz$select_autoescape..css"|]}d|dVqdSrrrr r rrs) template_namercs4|dkr S|}|r"dS|r0dSS)NTF)rr)rrrZdisabled_patternsZenabled_patternsr r autoescapes  z%select_autoescape..autoescape)rr8r9rzr)rrrrrr rrselect_autoescapes( r)r!dumpskwargsrcKs@|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 ``