@ qj UddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddl mZddlmZddlmZddlZejrddlZejd ejd ejf Zed d ddiZejed<eZej eed<dj!Z"dedefdZ#dedefdZ$dedefdZ%Gddej&Z'dedefdZ(dedefdZ)dedefdZ*dedefdZ+dejde,fdZ-d ej.ejddfd!Z/dXd"Z0dYd$e1d%e,dejfd&Z2dZd(e1d)e1dej3ej4fd*Z5dejde1fd+Z6dejde1fd,Z7ej8d-ej9ej:zZ;ej8d.Z< d[d/e1d0ej3e=d1ej3e1d2ej3e1d3ej3ej.e1de1f d4Z> d\d9e=d:e,d;e=drs 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_contextrs '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"/s ,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%@s +A HrceZdZejZejZejZede de j dfdZ dS)robjrct|dr|jSdD]f}|dd}|d|dfD]C}t||ddur.t j|d |d t d ||ccSDgdS) Nr)rr!r$_rfunctionfilterFTz= is deprecated and will stop working in Jinja 3.1. Use 'pass_z ' instead. stacklevel)hasattrrreplacegetattrwarningswarnDeprecationWarning)clsr'prefixsquashednames rfrom_objz_PassArg.from_objRs 3( ) ) &% %> ' 'F~~c2..H#---(/B/B/BB ' '3e,,44MGG4:GGG*#$  v;&&&&&5 'trN) __name__ __module__ __qualname__enumautorr!r$ classmethodr tOptionalr9r rrrrMsndikkG49;;L$)++K1J!7[rrcXtjdtdt|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-)r2r3r4rrs rcontextfunctionrCgs6 M )  ??rcXtjdtdt|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-)r2r3r4r"rs revalcontextfunctionrEws8 M 2  Q  rcXtjdtdt|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-)r2r3r4r%rs renvironmentfunctionrGs8 M 2  A  rcDt|j|S)z%Marks the function as internally used)radd__code__rs r internalcoderKsaj!!! 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)runtimerN isinstance)r'rNs r is_undefinedrQs&#""""" c9 % %%riterablec|D]}dS)z4Consumes an iterable without doing anything with it.Nr )rRr)s rconsumerTs      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. rM)get_spontaneous_environment) _lexer_cacheN)r$rVlexerrW cache_clearclear)rVrWs r clear_cachesr[sR 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 :rM.N)split rpartition __import__r1 ImportErrorAttributeError)r\r]moduler'r)s r import_stringrgs  +  %++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 objectr`)rstyper;r:)r'r5s robject_type_reprrvs`  {v z s))C ~##,''''n 4 4s| 4 4 44rc$ddlm}||S)z.Format an object using :func:`pprint.pformat`.r)pformat)pprintrx)r'rxs rrxrxs" 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)rr{s rtrim_urlzurlize..trim_urlGs11vv&&O^O,1111Hrc|SNr rs rrzurlize..trim_urlOsHrz(\s+)z rel=""rz target="z ^([(<]|<)+))>r`, >z([)>.,\n]|>)+$))(r)@zwww.r_z > 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.rM)LOREM_IPSUM_WORDSTrNFr,r rr` z rc3FK|]}dtj|dVdS)z

z

N)rr.0rs r z'generate_lorem_ipsum..s9CCq2 )!,,222CCCCCCr) constantsrrarrrr capitalizeappendrrrMarkup)rrrrrrresultr)next_capitalized last_comma last_fullstoprlastpidxp_strs rgenerate_lorem_ipsumrs-,,,,,  # # % %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+)rPbytesrencoder r0)r'rrsafervs r url_quoters c5 ! !"#s## c((Cjj!! "33dD #t $ $B $ ZZs # # Irc^ddl}|jdtdt|||S)Nrz_'unicode_urlencode' has been renamed to 'url_quote'. The old name will be removed in Jinja 3.1.r,r-)rr)r2r3r4r)r'rrr2s runicode_urlencodersHOOOHM .  S'& 9 9 99rceZdZdZdeddfdZddZdeje 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|_|dSr)r_mappingr_queue _postinit)selfrs r__init__zLRUCache.__init__s1  .0 ).  rc|jj|_|jj|_|jj|_t|_|jj |_ dSr) rpopleft_popleftpop_popremove_remover_wlockr_appendrs rrzLRUCache._postinits@ + KO {) ff {) rc,|j|j|jdS)Nrrrrrs r __getstate__zLRUCache.__getstate__s   k   rdcb|j||dSr)__dict__updater)rrs r __setstate__zLRUCache.__setstate__s. Q rc|jfSr)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.setdefault$s> 9    DINNN s  c|j5|j|jddddS#1swxYwYdS)zClear the cache.N)rrrZrrs rrZzLRUCache.clear.s [  M   ! ! ! K                       s3AA A c||jvS)z$Check if a key exists in this cache.rrrs r __contains__zLRUCache.__contains__4sdm##rc*t|jS)z%Return the current size of the cache.)rrrs r__len__zLRUCache.__len__8s4=!!!rcBdt|jd|jdS)Nrrr)rur: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)rrrrrrr)rrrs r __setitem__zLRUCache.__setitem__Us[ ' '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)rrrrr s r __delitem__zLRUCache.__delitem__bs[   c"  S!!!!                       s, A(A 5A5AA  A cpfdtjD}||S)zReturn a list of items.c.g|]}|j|fSr r)rrrs r z"LRUCache.items..ps%III3 c*+IIIr)listrreverse)rrs` ritemszLRUCache.itemsns;IIIItDK7H7HIII rc>d|DS)zReturn a list of all values.cg|] }|d S)rMr rs rrz#LRUCache.values..vs+++!+++r)rrs rvalueszLRUCache.valuests++djjll++++rc t|S)z7Return a list of all keys ordered by most recent usage.)rrs rkeysz LRUCache.keysxsDzzrcDtt|jSr)reversedtuplerrs r__iter__zLRUCache.__iter__|sdk**+++rcDtt|jS)zTIterate over the keys in the cache dict, oldest items coming first. )iterr#rrs r __reversed__zLRUCache.__reversed__sE$+&&'''rrN)rrr)"r:r;r<__doc__intrrr@MappingrAnyrrTuplerrrrrZboolr r rrrrIterablerrr Iteratorr$r'__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/dSr`Nlstriplowerrs rrz$select_autoescape..sAUUQ8#!4!4!6!688UUUUUUrc3jK|].}d|dV/dSr:r;rs rrz$select_autoescape..sAWWa9!((3--"5"5"7"799WWWWWWr template_namerc|S|}|rdS|rdSS)NTF)r=r)r?rr7disabled_patternsenabled_patternss r autoescapez%select_autoescape..autoescapes]  % %%++--  ! !"2 3 3 4  ! !"3 4 4 5r)r#r@rArr.)r5r6r7rrCrArBs `` @@rselect_autoescaperDsPUUBTUUUUUWWCVWWWWW!*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 ``