)h] UddlZddlZddlZddlZddlZddlmZ ddlm Z n#e $r ddlm Z YnwxYwddl m Z ddl m Z ddlmZddlmZddlmZddlZejrddlZejd ejd ejf Zed d ddiZejed<eZ ej!eed<dj"Z#dedefdZ$dedefdZ%dedefdZ&Gddej'Z(dedefdZ)dejde*fdZ+dej,ejddfdZ-dPdZ.dQd!e/d"e*dejfd#Z0dRd%e/d&e/dej1ej2fd'Z3dejde/fd(Z4dejde/fd)Z5ej6d*ej7ej8zZ9ej6d+Z: dSd,e/d-ej1e;d.ej1e/d/ej1e/d0ej1ej,e/de/f d1Z< dTd6e;d7e*d8e;d9e;de/f d:Z=dUdejdZ>ej?j@Gd?d@ZA dVdBejBe/dCejBe/dDe*dEe*dejej1e/ge*ff dFZC dWdejdGej1ejd e/fdHejdejDfdIZEGdJdKZFGdLdMZGGdNdOZHdS)XN)abc)deque)choice) randrange)Lock)CodeType)quote_from_bytesF.)bound MissingType__repr__cdS)Nmissingr xs ./usr/lib/python3/dist-packages/jinja2/utils.pyrs r internal_codefreturnc(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_argrs r pass_contextr s 'A Hrc(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_contextrrs rpass_eval_contextr"1s ,A Hrc(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 environmentrrs rpass_environmentr%Bs +A HrceZdZejZejZejZede de j dfdZ dS)robjrc4t|dr|jSdS)Nr)hasattrr)clsr's rfrom_objz_PassArg.from_objTs# 3( ) ) &% %trN) __name__ __module__ __qualname__enumautorr!r$ classmethodr tOptionalr+r rrrrOsndikkG49;;L$)++K1J!7[rrcDt|j|S)z%Marks the function as internally used)radd__code__rs r internalcoder7\saj!!! Hrr'c.ddlm}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)runtimer: isinstance)r'r:s r is_undefinedr=bs&#""""" c9 % %%riterablec|D]}dS)z4Consumes an iterable without doing anything with it.Nr )r>_s rconsumerAss      rcnddlm}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. r9)get_spontaneous_environment) _lexer_cacheN)r$rClexerrD cache_clearclear)rCrDs r clear_cachesrHysR 988888######++---rF import_namesilentc d|vr|dd\}}n-d|vr|d\}}}nt|Stt|dd|g|S#tt f$r|sYdSwxYw)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 :r9.N)split rpartition __import__getattr ImportErrorAttributeError)rIrJmoduler'r@s r import_stringrUs  +  %++C33KFCC K  (33C88NFAssk** *z&$se<>( # #t $  rc|dS|turdSt|}|jdkr |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 objectrM)ratyper-r,)r'r*s robject_type_reprrds`  {v z s))C ~##,''''n 4 4s| 4 4 44rc$ddlm}||S)z.Format an object using :func:`pprint.pformat`.r)pformat)pprintrf)r'rfs rrfrfs" 73<<ra@ ^ ( (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_schemesc dtdtffd }ndtdtfd}tjdttj|}|rdtj|dnd }|rd tj|dnd }t |D]\} } d | d } } } tjd | }|r0|} | |d} | d rGtj d | }|r0|} | d| } dD]\}}| |}|| |kr4tt|| |D]>}| |t!|z}| | d|z } | |d} ?t"| rZ| ds| drd| d||d|| d} nd| d||d|| d} n| dr4t&| ddrd| d| ddd} nqd| vr=| ds(d| vr$t&| r d| d| d} n0|.|D]+}| |kr#| |rd| d||d| d} ,| | | || <d |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. NrrcHt|kr |ddS|S)Nz...)len)rris rtrim_urlzurlize..trim_urls11vv&&O^O,1111Hrc|SNr rs rrpzurlize..trim_urlsHrz(\s+)z rel=""rz target="z ^([(<]|<)+))>rM, >z([)>.,\n]|>)+$))(rt)@zwww.rLz > 1I2F;;E 1{{}}%++--0%M ( ( J ,,z22Kfll844443{DJJx,@,@AABB ( ( JJx003x==@ $z z**IJJ'  ( >>& ! ! W  ,, 0A0A)0L0L WWWW;WW&AQAQWWW ....;..x''...   y ) ) WioofQRRj.I.I W;;;6!"":;;;FF 6MM%%f-- 6!!''"?>>&>>>FF  &' W WV##(9(9&(A(A#VVV(VKVV&VVVF*F*D**a 775>>rTdnhtmlrmaxc Pddlm}|}g}t|D]2}d}dx} } d} d} g} t tt ||D]\}} t |} | | kr| } n|r| } d}|t ddz | kr |} | d z } | d z } |t d d z | kr |x} } | d z } d}| | d | }| d r|ddd z}n| d s|d z }||4|sd |Stj d d|DS)z+Generate some lorem ipsum for the template.r9)LOREM_IPSUM_WORDSTrNFrv rrM z rwc3FK|]}dtj|dVdS)z

z

N)rr.0rs r z'generate_lorem_ipsum..s9CCq2 )!,,222CCCCCCr) constantsrrNrrrr capitalizeappendrrrMarkup)rrrrrrresultr@next_capitalized last_comma last_fullstoprlastpidxp_strs rgenerate_lorem_ipsumrYs-,,,,,  # # % %E F 1XX%%%&& ]  iS&9&9 : :;;  FC e}}4<<D     )((#( Yq!__$z11 "  Yr2&&&66-00 ] #' HHTNNNN  >>#   #2#J$EE$$  SLE e #{{6"""   CCFCCCCC  rutf-8charsetfor_qsct|ts9t|tst|}||}|rdnd}t ||}|r|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<bytesr}encoder replace)r'rrsafervs r url_quoters c5 ! !"#s## c((Cjj!! "33dD #t $ $B $ ZZs # # IrceZdZdZdeddfdZddZdeje ej ffdZ deje ej fddfd Z dej fd Zdd Zdd ej d ej dej fdZdd ej d ej dej fdZddZd ej defdZdefdZde fdZd ej dej fdZd ej dej ddfdZd ej ddfdZdejej ej ej ffdZdejej fdZdejej fdZdejej fdZdejej fdZ eZ!dS) LRUCachez"A simple LRU Cache implementation.capacityrNcp||_i|_t|_|dSrr)r_mappingr_queue _postinit)selfrs r__init__zLRUCache.__init__s1  .0 ).  rc|jj|_|jj|_|jj|_t|_|jj |_ dSrr) rpopleft_popleftpop_popremove_remover_wlockr_appendrs rrzLRUCache._postinits@ + KO {) ff {) rc,|j|j|jdS)Nrrrrrs r __getstate__zLRUCache.__getstate__s   k   rdcb|j||dSrr)__dict__updater)rrs r __setstate__zLRUCache.__setstate__s. Q rc|jfSrr)rrs r__getnewargs__zLRUCache.__getnewargs__s  rc||j}|j|j|j|j|S)z&Return a shallow copy of the instance.) __class__rrrrextendrrs rcopyz LRUCache.copysJ ^^DM * * 4=))) %%% rkeydefaultc8 ||S#t$r|cYSwxYw)z/Return an item from the cache dict or `default`KeyErrorrrrs rgetz LRUCache.gets5 9    NNN s  cB ||S#t$r |||<|cYSwxYw)zvSet `default` if the key is not in the cache otherwise leave unchanged. Return the value of this key. rrs r setdefaultzLRUCache.setdefaults> 9    DINNN s  c|j5|j|jddddS#1swxYwYdS)zClear the cache.N)rrrGrrs rrGzLRUCache.clears [  M   ! ! ! K                       s3AA A c||jvS)z$Check if a key exists in this cache.rrrs r __contains__zLRUCache.__contains__sdm##rc*t|jS)z%Return the current size of the cache.)rorrs r__len__zLRUCache.__len__s4=!!!rcBdt|jd|jdS)Nrzrru)rcr,rrs rrzLRUCache.__repr__s&;4::&;;;;;;rc|j5|j|}|jd|kr< ||n#t$rYnwxYw|||cdddS#1swxYwYdS)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)rrrs r __getitem__zLRUCache.__getitem__s [  s#B{2#%%LL%%%%!D   S!!!                  s1A1>A1 A A1 A  A11A58A5valuec0|j5||jvr||n7t|j|jkr|j|=||||j|<ddddS#1swxYwYdS)zhSets the value for an item. Moves the item up so that it has the highest priority then. N)rrrrorrr)rrrs r __setitem__zLRUCache.__setitem__ s[ ' 'dm## S!!!!T]##t}44M$--//2 LL   !&DM#  ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'sA6B  BBc|j5|j|= ||n#t$rYnwxYwddddS#1swxYwYdS)z]Remove an item from the cache dict. Raise a `KeyError` if it does not exist. N)rrrrrs r __delitem__zLRUCache.__delitem__s[   c"  S!!!!                       s, A(A 5A5AA  A cpfdtjD}||S)zReturn a list of items.c.g|]}|j|fSr r)rrrs r z"LRUCache.items..%s%III3 c*+IIIr)listrreverse)rrs` ritemszLRUCache.items#s;IIIItDK7H7HIII rc>d|DS)zReturn a list of all values.cg|] }|d S)r9r rs rrz#LRUCache.values..+s+++!+++r)r rs rvalueszLRUCache.values)s++djjll++++rc t|S)z7Return a list of all keys ordered by most recent usage.)rrs rkeysz LRUCache.keys-sDzzrcDtt|jSrr)reversedtuplerrs r__iter__zLRUCache.__iter__1sdk**+++rcDtt|jS)zTIterate over the keys in the cache dict, oldest items coming first. )iterrrrs r __reversed__zLRUCache.__reversed__4sE$+&&'''rrN)rrrr)"r,r-r.__doc__intrrr2Mappingr}AnyrrTuplerrrrrGboolrrrrrrIterabler r rIteratorrr__copy__r rrrrs,,  **** aiQU 3    aiQU 3     ququaeaequ    $$$$$$$"""""<#<<<<qu, 'qu 'QU 't ' ' ' ' qu     qz!'!%,"78 , 15),,,,aj',!*QU+,,,,(aj/(((( HHHrrrhtmxmlenabled_extensionsdisabled_extensionsdefault_for_stringrctd|Dtd|Ddtjtdtffd }|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 c3jK|].}d|dV/dSrMNlstriplowerrs rrz$select_autoescape..esAUUQ8#!4!4!6!688UUUUUUrc3jK|].}d|dV/dSr(r)rs rrz$select_autoescape..fsAWWa9!((3--"5"5"7"799WWWWWWr template_namerc|S|}|rdS|rdSS)NTF)r+r)r-rr%disabled_patternsenabled_patternss r autoescapez%select_autoescape..autoescapehs]  % %%++--  ! !"2 3 3 4  ! !"3 4 4 5r)rr2r3r}r)r#r$r%rr1r/r0s `` @@rselect_autoescaper2=sPUUBTUUUUUWWCVWWWWW!*S/d rdumpskwargsc | tj}tj||fi|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 ``