ڝ-dZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl m Z ddl mZddl mZd d lmZd d lmZd d lmZd d lmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlm Z ej!r/ddl"Z#d dl$m%Z%d dl&m'Z'd dlm(Z(d dl)m*Z*Gdde#j+Z,ej-dej.dej/fZ0ej-d Z1ej-d!Z2d"e0d#e0fd$Z3d"e0d#e0fd%Z4d"e0d#e0fd&Z5d'e2d#e2fd(Z6 dd)d*d+ej7ej8e9e:fd,ej7ej.ej/gej/fd-ej7ej/d#ej.ej/gej/ff d.Z; dd)d*d+ej7ej8e9e:fd,ej7ej.ej/gej/fd#ej.ej/gej<ej/ffd/Z=d0ej7ej8e9e:fd#ej<ej8e9e:ffd1Z>d'd2d#efd3Z?d'ej8e9ej@e9ej/fejAejBe9ej/ffd#e9fd4ZCe dd5d6d7e9d8e9d9e9d:ej7e:d#e9f d;ZDd7e9d#e9fd<ZEd7e9d#e9fd=ZFe dd5d6d?ej@e9ej/fd@eGd#e9fdAZHd7e9d#e9fdBZIejJdCZKd7e9d#e9fdDZL dd'ej@e1e2fdGeGdHdIdJeGd#ej<ejBe1e2ff dKZMe dd)d*d'dLdJeGdGeGd+ej7ej8e9e:fd#dMf dNZNe dd)d*d'dLdGeGd+ej7ej8e9e:fd#dOf dPZOd)d*d'dLdQdRdGeGd+ej7ej8e9e:fd#dSf dTZPe dd)d*d'dLdGeGd+ej7ej8e9e:fd#dSf dUZQe dd)d*d'dLdGeGd+ej7ej8e9e:fd#dSf dVZR dd'e2dXe2dYeGd#e2fdZZSe dd5d6d'ejAd?e9d+ej7ej8e9e:fd#e9f d[ZTeeT dd5d6d'ej8ejUejAfd?e9d+ej7ej8e9e:fd#e9f d\ZVdd'e9d^e:d#e9fd_ZWe ddaZXeeX ddcZYe ddeZZeddiZ[dd'ej8e9e\e:fdjeGd#e9fdkZ]d'ej/d#e9fdlZ^ejJdmZ_e dd5d6d'e9dnej7e:doeGdpej7e9dqej7e9drej7ejAe9d#e9fdsZ` dd7e9d^ej8e:e9fdueGdveGd#e9f dwZae ddzd*d7e9d{e:d|eGd}e9d~ej7e:d#e9fdZbe dd)d*d7e9d^e:deGdej7e9deGd#e9fdZcejJdZdd7e9d#e:fdZed d'ej/d-e:de:d#e:fdZfd d'ej/d-e\d#e\fdZgd'e9dej/dej/d#e9fdZhdd'e9dej7e9d#e9fdZid'd2d#e9fdZj dd'dde:ddd#dfdZkeek dd'dbde:dej7ej/d#dfdZl dd'dLde:ddd#dfdZm d d'e\de:ddd#e\fdZnGddejoZpe dd)d*d'dLd+ej8e9e:fd-ej7ej/d#df dZqeeq dd)d*d'dbd+ej8e9e:fd-ej7ej/d#df dZre d d)d*ddLd+ej7ej8e9e:fde2d#e2f dZsees d d)d*ddbd+ej7ej8e9e:fde2d#e2f dZtd dZueeuddZvd'e9d#efdZwd'e9d#e9fdZxejyd'e9d#e9fdZzejyddZzd'ej8e9ejAe2fd#ej8e9ejAe2ffdZzed)d*dej/de9d#ej8eej/ffdZ{ejydfdgd'ejAde9dej/dej/d#ejAf dZ|ejyddddfdgd'ejAd+e9d-ej7ej/d#ejAf dZ|edfdgd'ejAdej/dej/d#ejAf dZ|ejydfdgd'ej8ejUejAfde9dej/dej/d#ejAf dZ}ejyddddfdgd'ej8ejUejAfd+e9d-ej7ej/d#ejAf dZ}ee|dfdgd'ej8ejUejAfdej/dej/d#ejUf dZ}edfdgd'dLdej/dej/d#dOf dZ~ee~dfdgd'dbdej/dej/d#df dZedfdgd'dLdej/dej/d#dOf dZeedfdgd'dbdej/dej/d#df dZedfdgd'dLdej/dej/d#dOf dZeedfdgd'dbdej/dej/d#df dZedfdgd'dLdej/dej/d#dOf dZeedfdgd'dbdej/dej/d#df d„Ze dd5d6d'ej/dej7e:d#efdĄZdfdgdejBdeje9ej/fd#ej.ej/gej/ffdńZdfdgdejBdeje9ej/fdej.ej/gej/fdeGd#ej.ej/gej/ff dȄZdfdgd'dLdejBdeje9ej/fdej.ej/gej/fdeGd#dOfdɄZdfdgd'dbdejBdeje9ej/fdej.ej/gej/fdeGd#dfdʄZided0e{demdeIdeWd:ed?eSd-eSdeMde de de]dueYdegde?dehderideadefdeVdeZd{edevdeFde}deQdeRde^de[dededeDdJezdenidewdededeldeNdedejdetdeLdeidebdeOdeEdeCde`deedeceHedZdS(z7Built-in template filters used with the ``|`` operator.N)abc)chain)groupby)escapeMarkup)soft_str) async_variant) auto_aiter) auto_await auto_to_list)FilterArgumentError) Undefined)htmlsafe_json_dumps) pass_context)pass_environment)pass_eval_contextpformat url_quote)urlize) Environment) EvalContext)Context)SandboxedEnvironmentceZdZdefdZdS)HasHTMLreturncdSNselfs `/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/jinja2/filters.py__html__zHasHTML.__html__&s DN)__name__ __module__ __qualname__strr(r$r)r'r r %s/ c      r)r F.)boundKVfr!cXtjdtdt|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. zX'contextfilter' is renamed to 'pass_context', the old name will be removed in Jinja 3.1. stacklevel)warningswarnDeprecationWarningrr2s r' contextfilterr;/s6 M )  ??r)cXtjdtdt|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 za'evalcontextfilter' is renamed to 'pass_eval_context', the old name will be removed in Jinja 3.1.r4r5)r7r8r9rr:s r'evalcontextfilterr=?s8 M .  Q  r)cXtjdtdt|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. z`'environmentfilter' is renamed to 'pass_environment', the old name will be removed in Jinja 3.1.r4r5)r7r8r9rr:s r'environmentfilterr?Rs8 M .  A  r)valuect|tr,tjt|S|S)zxFor use as a postprocessor for :func:`make_attrgetter`. Converts strings to lowercase and returns other types as-is.) isinstancer-tcastr1lowerr@s r' ignore_caserGcs5%(va''' Lr) environmentr attribute postprocessdefaultcnt|dtjdtjffd }|S)zReturns a callable that looks up the given attribute from a passed object with the rules of the environment. Dots are allowed to access attributes of attributes. Integer parts in paths are looked up as integers. itemr!cD]1}||}t|tr}2 |}|Sr#)getitemrBr)rMpartrKrHpartsrJs r' attrgetterz#make_attrgetter..attrgetterys\  D&&tT22D"z$ 'B'B"  ";t$$D r))_prepare_attribute_partsrCAny)rHrIrJrKrRrQs` `` @r'make_attrgetterrUls\ %Y / /E  15          r)ct|tr|d}n|g}d|Ddtjdtjtjffd }|S)aReturns a callable that looks up the given comma separated attributes from a passed object with the rules of the environment. Dots are allowed to access attributes of each attribute. Integer parts in paths are looked up as integers. The value returned by the returned callable is a list of extracted attribute values. Examples of attribute: "attr1,attr2", "attr1.inner1.0,attr2.inner2.0", etc. ,c,g|]}t|Sr$)rS.0rMs r' z)make_multi_attrgetter..s! > > > %d + + > > >r)rMr!cdgtz}tD]4\}}|}|D]}||} |}|||<5|Sr#)len enumeraterO) rMitemsiattribute_partitem_irPrHrQrJs r'rRz)make_multi_attrgetter..attrgettersU#!*5!1!1   A~F& ; ;$,,VT::&$V,,E!HH r))rBr-splitrCrTList)rHrIrJrcrRrQs` ` @r'make_multi_attrgetterres)S!!5>__S5I5I  > > > > >E16!%= r)attrcx|gSt|trd|dDS|gS)NcXg|]'}|rt|n|(Sr$)isdigitint)rZxs r'r[z,_prepare_attribute_parts..s/FFF!))++,A1FFFr).)rBr-rc)rfs r'rSrSsF | $GFFdjjooFFFF 6Mr)zt.Union[str, HasHTML]ct|dr'tjd|}t t |S)zCEnforce HTML escaping. This will probably double escape variables.r(r )hasattrrCrDr(rr-rFs r'do_forceescaperosEuj!!4y%((1133 #e**  r)ct|tst|tjst |St|t r|}n|}dd|DS)a3Quote data for use in a URL path or query using UTF-8. Basic wrapper around :func:`urllib.parse.quote` when given a string, or :func:`urllib.parse.urlencode` for a dict or iterable. :param value: Data to quote. A string will be quoted directly. A dict or iterable of ``(key, value)`` pairs will be joined as a query string. When given a string, "/" is not quoted. HTTP servers treat "/" and "%2F" equivalently in paths. If you need quoted slashes, use the ``|replace("/", "%2F")`` filter. .. versionadded:: 2.7 &c3fK|],\}}t|ddt|dV-dS)T)for_qs=Nr)rZkvs r' zdo_urlencode..s_GKq!9Qt $ $ $BBy4'@'@'@BBr))rBr-rIterablerdictr_join)r@r_s r' do_urlencoder{s$% Zs|%D%D %16 88OT  r)eval_ctxrsoldnewcountc|d}|js>t|t|t||St|ds t|dr t|dst |}nt |}|t |t ||S)aReturn a copy of the value with all occurrences of a substring replaced with a new one. The first argument is the substring that should be replaced, the second is the replacement string. If the optional third argument ``count`` is given, only the first ``count`` occurrences are replaced: .. sourcecode:: jinja {{ "Hello World"|replace("Hello", "Goodbye") }} -> Goodbye World {{ "aaaaargh"|replace("a", "d'oh, ", 2) }} -> d'oh, d'oh, aaargh Nr() autoescaper-replacernrr )r|r}r~rrs r' do_replacers$ }  91vv~~c#hhC%888 Z   3 # #:&& 1II QKK 99Xc]]HSMM5 9 99r)cDt|S)zConvert a value to uppercase.)r upperr}s r'do_upperr A;;    r)cDt|S)zConvert a value to lowercase.)r rErs r'do_lowerr rr)Td autospacecdd|D}|r|rd|z}|jrt|}|S)acCreate an SGML/XML attribute string based on the items in a dict. All values that are neither `none` nor `undefined` are automatically escaped: .. sourcecode:: html+jinja ... Results in something like this: .. sourcecode:: html
    ...
As you can see it automatically prepends a space in front of the item if the filter returned something unless the second parameter is false.  c3K|]@\}}|t|tt|dt|dVAdS)Nz="")rBrr)rZkeyr@s r'rwzdo_xmlattr..,sd C  Zy%A%A  #;;**&--***    r))rzr_rr)r|rrrvs r' do_xmlattrrsp4 ''))  B R 2X BZZ Ir)cDt|S)zYCapitalize a value. The first character will be uppercase, all others lowercase. )r capitalizers r' do_capitalizer;s A;; ! ! # ##r)z ([-\s({\[<]+)cddtt|DS)zReturn a titlecased version of the value. I.e. words will start with uppercase letters, all remaining characters are lowercase. cg|];}||d|ddz.JsQ    GMMOOd122hnn.. .   r))rz_word_beginning_split_rercr rs r'do_titlerEsJ 77  066x{{CC     r)Frcase_sensitivebyzte.Literal["key", "value"]reversec|dkrdn|dkrdntddtjtjtjfdtjffd }t ||| S) afSort a dict and yield (key, value) pairs. Python dicts may not be in the order you want to display them in, so sort them first. .. sourcecode:: jinja {% for key, value in mydict|dictsort %} sort the dict by key, case insensitive {% for key, value in mydict|dictsort(reverse=true) %} sort the dict by key, case insensitive, reverse order {% for key, value in mydict|dictsort(true) %} sort the dict by key, case sensitive {% for key, value in mydict|dictsort(false, 'value') %} sort the dict by value, case insensitive rrr@r z,You can only sort by either "key" or "value"rMr!c:|}st|}|Sr#)rG)rMr@rposs r' sort_funczdo_dictsort..sort_funcps&S  '&&E r)rr)rrCTuplerTsortedr_)r@rrrrrs ` @r' do_dictsortrRs. U{{ w!"PQQQqu -!% %++--Y @ @ @@r) t.Iterable[V] t.List[V]c\t|||stnd}t|||S)a*Sort an iterable using Python's :func:`sorted`. .. sourcecode:: jinja {% for city in cities|sort %} ... {% endfor %} :param reverse: Sort descending instead of ascending. :param case_sensitive: When sorting strings, sort upper and lower case separately. :param attribute: When sorting objects or dicts, an attribute or key to sort by. Can use dot notation like ``"address.city"``. Can be a list of attributes like ``"age,name"``. The sort is stable, it does not change the relative order of elements that compare equal. This makes it is possible to chain sorts on different attributes and ordering. .. sourcecode:: jinja {% for user in users|sort(attribute="name") |sort(reverse=true, attribute="age") %} ... {% endfor %} As a shortcut to chaining when the direction is the same for all attributes, pass a comma separate list of attributes. .. sourcecode:: jinja {% for user users|sort(attribute="age,name") %} ... {% endfor %} .. versionchanged:: 2.11.0 The ``attribute`` parameter can be a comma separated list of attributes, e.g. ``"age,name"``. .. versionchanged:: 2.6 The ``attribute`` parameter was added. NrJr)rerGr)rHr@rrrIkey_funcs r'do_sortr{sAd%Y~,WKKSWH %Xw 7 7 77r)z t.Iterator[V]c#Kt|||stnd}t}|D]*}||}||vr|||V+dS)aReturns a list of unique items from the given iterable. .. sourcecode:: jinja {{ ['foo', 'bar', 'foobar', 'FooBar']|unique|list }} -> ['foo', 'bar', 'foobar'] The unique items are yielded in the same order as their first occurrence in the iterable passed to the filter. :param case_sensitive: Treat upper and lower case strings as distinct. :param attribute: Filter objects with unique values for this attribute. Nr)rUrGsetadd)rHr@rrIgetterseenrMrs r' do_uniquers(Y~,WKKSWF 55DfTll d?? HHSMMMJJJ r)funczt.Callable[..., V]t.Union[V, Undefined]ct|} t|}n%#t$r|dcYSwxYwt |||st nd}|t |g||S)Nz'No aggregated item, sequence was empty.rr)iternext StopIteration undefinedrUrGr)rHr@rrrIitfirstrs r' _min_or_maxrs eBPR PPP$$%NOOOOOPY~,WKKSWH 4ugr"" 1 1 11s!AAc2t||t||S)aReturn the smallest item from the sequence. .. sourcecode:: jinja {{ [1, 2, 3]|min }} -> 1 :param case_sensitive: Treat upper and lower case strings as distinct. :param attribute: Get the object with the min value of this attribute. )rminrHr@rrIs r'do_minr" {E3 J JJr)c2t||t||S)aReturn the largest item from the sequence. .. sourcecode:: jinja {{ [1, 2, 3]|max }} -> 3 :param case_sensitive: Treat upper and lower case strings as distinct. :param attribute: Get the object with the max value of this attribute. )rmaxrs r'do_maxrrr)r default_valuebooleanc<t|ts|r|s|S|S)a`If the value is undefined it will return the passed default value, otherwise the value of the variable: .. sourcecode:: jinja {{ my_variable|default('my_variable is not defined') }} This will output the value of ``my_variable`` if the variable was defined, otherwise ``'my_variable is not defined'``. If you want to use default with variables that evaluate to false you have to set the second parameter to `true`: .. sourcecode:: jinja {{ ''|default('the string was empty', true) }} .. versionchanged:: 2.11 It's now possible to configure the :class:`~jinja2.Environment` with :class:`~jinja2.ChainableUndefined` to make the `default` filter work on nested elements and attributes that may contain undefined values in the chain without getting an :exc:`~jinja2.UndefinedError`. )rBr)r@rrs r' do_defaultrs/6%## Lr)cP|#tt|j||}|js5t |tt|St |dst|}d}t|D]*\}}t |drd}t |||<+|rt|}nt |}||St|tt|S)a#Return a string which is the concatenation of the strings in the sequence. The separator between elements is an empty string per default, you can define it with the optional parameter: .. sourcecode:: jinja {{ [1, 2, 3]|join('|') }} -> 1|2|3 {{ [1, 2, 3]|join }} -> 123 It is also possible to join certain attributes of an object: .. sourcecode:: jinja {{ users|join(', ', attribute='username') }} .. versionadded:: 2.6 The `attribute` parameter was added. Nr(FT) maprUrHrr-rzrnlistr^rr )r|r@rrI do_escapeidxrMs r' sync_do_joinr1s8OH$8)DDeLL  ,1vv{{3sE??+++ 1j ! !U  "5)) ' 'ICtZ(( '  YYc  q AAAAvve}} A;;  C%00 1 11r)cPKt|t|d{V||Sr#)rr)r|r@rrIs r'do_joinrks6  U(;(;";";";";";";Q J JJr)PwidthcFt||S)z.Centers the value in a field of a given width.)r center)r@rs r' do_centerrus E?? ! !% ( ((r)seqc tt|S#t$r|dcYSwxYw)z$Return the first item of a sequence."No first item, sequence was empty.)rrrrrHrs r' sync_do_firstrzsT KDII KKK$$%IJJJJJKsAA*t.Union[t.AsyncIterable[V], t.Iterable[V]]cK t|d{VS#t$r|dcYSwxYw)Nr)r __anext__StopAsyncIterationrrs r'do_firstrspK__..000000000 KKK$$%IJJJJJKs&+A  A t.Reversible[V]c ttt|S#t$r|dcYSwxYw)zReturn the last item of a sequence. Note: Does not work with generators. You may want to explicitly convert it to a list: .. sourcecode:: jinja {{ data | selectattr('name', '==', 'Jinja') | list | last }} z!No last item, sequence was empty.)rrreversedrrrs r'do_lastrs^JD#''((( JJJ$$%HIIIIIJs(+A  A contextr t.Sequence[V]c tj|S#t$r|jdcYSwxYw)z'Return a random item from the sequence.z#No random item, sequence was empty.)randomchoice IndexErrorrHr)rrs r' do_randomrsUT}S!!! TTT",,-RSSSSSTs $==binarycBt|}|rdnd}|rdnd|rdnd|rdnd|rd nd |rd nd |rd nd|rdnd|rdndg}|dkrdS||krt|dSt|D]#\}}||dzz}||kr||z|z dd|cS$||z|z dd|S)zFormat the value like a 'human-readable' file size (i.e. 13 kB, 4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega, Giga, etc.), if the second parameter is set to `True` the binary prefixes are used (Mebi, Gibi). iiKiBkBMiBMBGiBGBTiBTBPiBPBEiBEBZiBZBYiBYBr z1 Bytez Bytesr4z.1fr)floatrjr^)r@rbytesbaseprefixesr`prefixunits r'do_filesizeformatrs0 %LLE #44tD "d "d "d "d "d "d "d "d H zzx e**$$$$"8,, = =IAvAE?Dt||,-<<>r)z^([\w.+-]{2,}:(/){0,2})$trim_url_limitnofollowtargetrel extra_schemesc|jj}t|pd}|r|d||dpddt|pd}||d}| |dpd}|D].} t | t| d /t||||| } |j rt| } | S) a0Convert 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 value: Original text containing URLs to link. :param trim_url_limit: Shorten displayed URL values to this length. :param nofollow: Add the ``rel=nofollow`` attribute to links. :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. Defaults to ``env.policies["urlize.extra_schemes"]``, which defaults to no extra schemes. .. 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. .. versionchanged:: 2.8 The ``target`` parameter was added. rr z urlize.relrNz urlize.targetzurlize.extra_schemesr$z" is not a valid URI scheme prefix.)r r r r )rHpoliciesrrcrupdaterzr_uri_scheme_re fullmatchrrrr) r|r@r r r r r r rel_partsschemers r' do_urlizers7^#,HSYB%%''((I" j!!! h|,299;;<<< ((6)$$ % % -C ~/* !78>B WW  # #F + + 3%&U&U&UVV V 4  % #    B BZZ Ir)rblankct|tr|nd|zd}t|trtt|}||z }|r+|z|}nR|}|d}|r'|||fd|Dzz }|r|z}|S)aReturn a copy of the string with each line indented by 4 spaces. The first line and blank lines are not indented by default. :param width: Number of spaces, or a string, to indent by. :param first: Don't skip indenting the first line. :param blank: Don't skip indenting empty lines. .. versionchanged:: 3.0 ``width`` can be a string. .. versionchanged:: 2.10 Blank lines are not indented by default. Rename the ``indentfirst`` argument to ``first``. r rc3*K|] }|r|zn|VdSr#r$)rZline indentions r'rwzdo_indent..MsC))7;D2 D  d))))))r))rBr-rrz splitlinespop)r}rrrnewlinerlinesrs @r' do_indentr!'s $%  %K G!V"9%% //LA  ! ' '  7 7  YYq\\   'GLL))))?D))) B  ^ Ir)...envlength killwordsendleewayc| |jd}|t|ksJdt|d||dks Jd|t|||zkr|S|r|d|t|z |zS|d|t|z ddd}||zS) aReturn a truncated copy of the string. The length is specified with the first parameter which defaults to ``255``. If the second parameter is ``true`` the filter will cut the text at length. Otherwise it will discard the last word. If the text was in fact truncated it will append an ellipsis sign (``"..."``). If you want a different ellipsis sign than ``"..."`` you can specify it using the third parameter. Strings that only exceed the length by the tolerance margin given in the fourth parameter will not be truncated. .. sourcecode:: jinja {{ "foo bar baz qux"|truncate(9) }} -> "foo..." {{ "foo bar baz qux"|truncate(9, True) }} -> "foo ba..." {{ "foo bar baz qux"|truncate(11) }} -> "foo bar baz qux" {{ "foo bar baz qux"|truncate(11, False, '...', 0) }} -> "foo bar..." The default leeway on newer Jinja versions is 5 and was 0 before but can be reconfigured globally. Nztruncate.leewayzexpected length >= z, got rzexpected leeway >= 0, got rr )rr]rsplit)r$r}r%r&r'r(results r' do_truncater,Ws@~/0 SXX   MSXXMMVMM    Q;;;=V==;;; 1vv&  ,$6CHH$$%++ "#c(("" # * *3 2 21 5F C<r)Obreak_long_words wrapstringbreak_on_hyphenscddl|jfd|DS)aWrap a string to the given width. Existing newlines are treated as paragraphs to be wrapped separately. :param s: Original text to wrap. :param width: Maximum length of wrapped lines. :param break_long_words: If a word is longer than ``width``, break it across lines. :param break_on_hyphens: If a word contains hyphens, it may be split across lines. :param wrapstring: String to join each wrapped line. Defaults to :attr:`Environment.newline_sequence`. .. versionchanged:: 2.11 Existing newlines are treated as paragraphs wrapped separately. .. versionchanged:: 2.11 Added the ``break_on_hyphens`` parameter. .. versionchanged:: 2.7 Added the ``wrapstring`` parameter. rNc lg|]0}|dd1S)F)r expand_tabsreplace_whitespacer.r0)rzwrap)rZrr.r0textwraprr/s r'r[zdo_wordwrap..sa  OO  %',%5%5    r))r6newline_sequencerzr)rHr}rr.r/r0r6s ````@r' do_wordwrapr8s|<OOO 1 ??     r)z\w+cjttt|S)zCount the words in that string.)r]_word_refindallr rs r' do_wordcountr<s$ x ,, - --r) rc  t|trt||St|S#ttf$r; tt |cYS#ttf$r|cYcYSwxYwwxYw)aConvert the value into an integer. If the conversion doesn't work it will return ``0``. You can override this default using the first parameter. You can also override the default base (10) in the second parameter, which handles input with prefixes such as 0b, 0o and 0x for bases 2, 8 and 16 respectively. The base is ignored for decimal numbers and non-string values. )rBr-rj TypeError ValueErrorr)r@rKrs r'do_intrAs  eS ! ! $ud## #5zz z " uU||$$ $ $ $:&   NNNNN  s1$66BA&#B&A>9B=A>>BcT t|S#ttf$r|cYSwxYw)zConvert the value into a floating point number. If the conversion doesn't work it will return ``0.0``. You can override this default using the first parameter. )rr?r@)r@rKs r'do_floatrDs< U|| z "s ''argskwargscP|r|rtdt||p|zS)aApply the given values to a `printf-style`_ format string, like ``string % values``. .. sourcecode:: jinja {{ "%s, %s!"|format(greeting, name) }} Hello, World! In most cases it should be more convenient and efficient to use the ``%`` operator or :meth:`str.format`. .. code-block:: text {{ "%s, %s!" % (greeting, name) }} {{ "{}, {}!".format(greeting, name) }} .. _printf-style: https://docs.python.org/library/stdtypes.html #printf-style-string-formatting z>can't handle positional and keyword arguments at the same time)rr )r@rErFs r' do_formatrHs?(   ! L    E??fn --r)charscFt||S)z=Strip leading and trailing characters, by default whitespace.)r strip)r@rIs r'do_trimrLs E??  ' ''r)ct|dr'tjd|}t t |S)zAStrip SGML/XML tags and replace adjacent whitespace by one space.r(r )rnrCrDr(rr- striptagsrFs r' do_striptagsrO sQuj!!4y%((1133 #e**   ' ' ) ))r)zt.Collection[V]slices fill_withz t.Optional[V]zt.Iterator[t.List[V]]c#Kt|}t|}||z}||z}d}t|D]K}|||zz} ||kr|dz }||dz|zz} || | } |||kr| || VLdS)aFSlice an iterator and return a list of lists containing those items. Useful if you want to create a div containing three ul tags that represent columns: .. sourcecode:: html+jinja
{%- for column in items|slice(3) %}
    {%- for item in column %}
  • {{ item }}
  • {%- endfor %}
{%- endfor %}
If you pass it a second argument it's used to fill missing values on the last iteration. rr N)rr]rangeappend) r@rPrQrr%items_per_sliceslices_with_extraoffset slice_numberstartr'tmps r' sync_do_slicer[s, u++C XXF&O Ff   77 + + + aKF q(O;;%)n  \5F%F%F JJy ! ! !   r)cNKtt|d{V||Sr#)r[r)r@rPrQs r'do_slicer]<s4 |E22222222FI F FFr) linecountc#Kg}|D]0}t||kr|Vg}||1|r4|,t||kr||g|t|z zz }|VdSdS)a  A filter that batches items. It works pretty much like `slice` just the other way round. It returns a list of lists with the given number of items. If you provide a second parameter this is used to fill up missing items. See this example: .. sourcecode:: html+jinja {%- for row in items|batch(3, ' ') %} {%- for column in row %} {%- endfor %} {%- endfor %}
{{ column }}
N)r]rT)r@r^rQrZrMs r'do_batchr`Es*C s88y IIIC 4   SXX %9%9 I;)c#hh"67 7C r)common precisionmethodz%te.Literal["common", "ceil", "floor"]c|dvrtd|dkrt||Stt|}t jt ||d|zzd|zz S)aRound the number to a given precision. The first parameter specifies the precision (default is ``0``), the second the rounding method: - ``'common'`` rounds either up or down - ``'ceil'`` always rounds up - ``'floor'`` always rounds down If you don't specify a method ``'common'`` is used. .. sourcecode:: jinja {{ 42.55|round }} -> 43.0 {{ 42.55|round(1, 'floor') }} -> 42.5 Note that even if rounded to 0 precision, a float is returned. If you need a real integer, pipe it through `int`: .. sourcecode:: jinja {{ 42.55|round|int }} -> 43 >ceilfloorraz$method must be common, ceil or floorrar=)rroundgetattrmathrCrDr)r@rbrcrs r'do_roundrjjsw<000!"HIII UI&&& 4 D 6%erY788B)OL M MMr)cPeZdZUejed<ejed<defdZdefdZ dS) _GroupTuplegrouperrr!c6t|Sr#)tuple__repr__r%s r'rpz_GroupTuple.__repr__s~~d###r)c6t|Sr#)ro__str__r%s r'rrz_GroupTuple.__str__s}}T"""r)N) r*r+r,rCrT__annotations__rdr-rprrr$r)r'rlrlsb UNNN &LLL$#$$$$#######r)rlz!t.List[t.Tuple[t.Any, t.List[V]]]cxt|||}dtt|||DS)a>Group a sequence of objects by an attribute using Python's :func:`itertools.groupby`. The attribute can use dot notation for nested access, like ``"address.city"``. Unlike Python's ``groupby``, the values are sorted first so only one group is returned for each unique value. For example, a list of ``User`` objects with a ``city`` attribute can be rendered in groups. In this example, ``grouper`` refers to the ``city`` value of the group. .. sourcecode:: html+jinja
    {% for city, items in users|groupby("city") %}
  • {{ city }}
      {% for user in items %}
    • {{ user.name }} {% endfor %}
  • {% endfor %}
``groupby`` yields namedtuples of ``(grouper, list)``, which can be used instead of the tuple unpacking above. ``grouper`` is the value of the attribute, and ``list`` is the items with that value. .. sourcecode:: html+jinja
    {% for group in users|groupby("city") %}
  • {{ group.grouper }}: {{ group.list|join(", ") }} {% endfor %}
You can specify a ``default`` value to use if an object in the list does not have the given attribute. .. sourcecode:: jinja
    {% for city, items in users|groupby("city", default="NY") %}
  • {{ city }}: {{ items|map(attribute="name")|join(", ") }}
  • {% endfor %}
.. versionchanged:: 3.0 Added the ``default`` parameter. .. versionchanged:: 2.6 The attribute supports dot notation for nested access. rKcNg|]"\}}t|t|#Sr$)rlrrZrvaluess r'r[z#sync_do_groupby..s<    C Cf&&   r)r)rUrrrHr@rIrKexprs r'sync_do_groupbyr{sQh ; 7 C C CD  "6%T#:#:#:DAA   r)cKt|||}dttt|d{V||Dd{VS)Nruc^Kg|](\}}t|t|d{V)Sr#)rlrrws r'r[zdo_groupby..sT    C C|F3333333344   r)r)rUrrrrys r' do_groupbyr~s ; 7 C C CD  "6 U0C0C*C*C*C*C*C*C#N#N#NPTUU         r)iterablerYcb|tt|||}t||S)aReturns the sum of a sequence of numbers plus the value of parameter 'start' (which defaults to 0). When the sequence is empty it returns start. It is also possible to sum up only certain attributes: .. sourcecode:: jinja Total: {{ items|sum(attribute='price') }} .. versionchanged:: 2.6 The `attribute` parameter was added to allow suming up over attributes. Also the `start` parameter was moved on to the right. )rrUsum)rHrrIrYs r' sync_do_sumrs3*{I>>II x  r)cK|}|t||}ndtdtfd}t|23d{V}|||z }6|S)Nrkr!c|Sr#r$rks r'rzdo_sum..funcHr))rUr1r )rHrrIrYrrrMs r'do_sumrs B{I66 A !    !**d dd4jj+ IsAc t|S)zkConvert the value into a list. If it was a string the returned list will be a list of characters. )rrFs r' sync_do_listrs ;;r)c0Kt|d{VSr#rrFs r'do_listr s&e$$ $ $ $ $ $ $$r)c t|S)zMark the value as safe which means that in an environment with automatic escaping enabled this variable will not be escaped. rrFs r' do_mark_safer%s %==r)c t|S)zHMark a value as unsafe. This is the reverse operation for :func:`safe`.)r-rFs r'do_mark_unsafer,s u::r)cdSr#r$rFs r' do_reverser1Cr)cdSr#r$rFs r'rr6rr)ct|tr |dddS t|S#t$rK t |}||cYS#t$r}t d|d}~wwxYwwxYw)z\Reverse the object or return an iterator that iterates over it the other way round. Nrzargument must be iterable)rBr-rr?rrr)r@res r'rr;s%TTrT{J JJJ JeB JJLLLIII J J J%&ABB I J Js,1 B$A# B# B-A==BBobjnamecH t|} t||}|jrBtjd|}||||s|||S|S#t$rYnwxYw#t$rYnwxYw| ||S)zGet an attribute of an object. ``foo|attr("bar")`` works like ``foo.bar`` just that always an attribute is returned and items are not looked up. See :ref:`Notes on subscriptions ` for more details. r)rr) r-rh sandboxedrCrDis_safe_attributeunsafe_undefinedAttributeError UnicodeErrorr)rHrrr@s r'do_attrrMs4yy C&&E$ Cf%;[II "44S$FFC&77TBBBL    D        St 4 44s"A=A-- A:9A:= B  B cdSr#r$rr@rrErFs r' sync_do_maprls Cr))rIrKcdSr#r$rr@rIrKs r'rrs Cr)c/XK|r#t|||}|D]}||VdSdS)aApplies a filter on a sequence of objects or looks up an attribute. This is useful when dealing with lists of objects but you are really only interested in a certain value of it. The basic usage is mapping on an attribute. Imagine you have a list of users but you are only interested in a list of usernames: .. sourcecode:: jinja Users on this page: {{ users|map(attribute='username')|join(', ') }} You can specify a ``default`` value to use if an object in the list does not have the given attribute. .. sourcecode:: jinja {{ users|map(attribute="username", default="Anonymous")|join(", ") }} Alternatively you can let it invoke a filter by passing the name of the filter and the arguments afterwards. A good example would be applying a text conversion filter on a sequence: .. sourcecode:: jinja Users on this page: {{ titles|map('lower')|join(', ') }} Similar to a generator comprehension such as: .. code-block:: python (u.username for u in users) (getattr(u, "username", "Anonymous") for u in users) (do_lower(x) for x in titles) .. versionchanged:: 2.11.0 Added the ``default`` parameter. .. versionadded:: 2.7 N) prepare_maprr@rErFrrMs r'rr~s\V 7D&11  D$t**       r)cdSr#r$rs r'do_maprrr)cdSr#r$rs r'rrrr)cK|rLt|||}t|23d{V}t||d{VWV)6dSdSr#)rr r rs r'rrs /7D&11$U++ / / / / / / /$"44::........ . . . . .,++//sAc,t||||ddS)aFilters a sequence of objects by applying a test to each object, and only selecting the objects with the test succeeding. If no test is specified, each object will be evaluated as a boolean. Example usage: .. sourcecode:: jinja {{ numbers|select("odd") }} {{ numbers|select("odd") }} {{ numbers|select("divisibleby", 3) }} {{ numbers|select("lessthan", 42) }} {{ strings|select("equalto", "mystring") }} Similar to a generator comprehension such as: .. code-block:: python (n for n in numbers if test_odd(n)) (n for n in numbers if test_divisibleby(n, 3)) .. versionadded:: 2.7 c|Sr#r$rs r'z sync_do_select..Ar)Fselect_or_rejectrr@rErFs r'sync_do_selectrs8 GUD&++u M MMr)zt.AsyncIterator[V]c0Kt||||ddS)Nc|Sr#r$rs r'rzdo_select..!r)Fasync_select_or_rejectrs r' do_selectrs" "'5$ U S SSr)c,t||||ddS)aFilters a sequence of objects by applying a test to each object, and rejecting the objects with the test succeeding. If no test is specified, each object will be evaluated as a boolean. Example usage: .. sourcecode:: jinja {{ numbers|reject("odd") }} Similar to a generator comprehension such as: .. code-block:: python (n for n in numbers if not test_odd(n)) .. versionadded:: 2.7 c| Sr#r$rs r'rz sync_do_reject..Er)Frrs r'sync_do_rejectrs. GUD&//5 Q QQr)c0Kt||||ddS)Nc| Sr#r$rs r'rzdo_reject..a%r)Frrs r' do_rejectrs# "'5$QV W WWr)c,t||||ddS)aWFilters a sequence of objects by applying a test to the specified attribute of each object, and only selecting the objects with the test succeeding. If no test is specified, the attribute's value will be evaluated as a boolean. Example usage: .. sourcecode:: jinja {{ users|selectattr("is_active") }} {{ users|selectattr("email", "none") }} Similar to a generator comprehension such as: .. code-block:: python (u for user in users if user.is_active) (u for user in users if test_none(user.email)) .. versionadded:: 2.7 c|Sr#r$rs r'rz$sync_do_selectattr..<rr)Trrs r'sync_do_selectattrr!s6 GUD&++t L LLr)c0Kt||||ddS)Nc|Sr#r$rs r'rzdo_selectattr..Frr)Trrs r' do_selectattrr?s" "'5$ T R RRr)c,t||||ddS)aFFilters a sequence of objects by applying a test to the specified attribute of each object, and rejecting the objects with the test succeeding. If no test is specified, the attribute's value will be evaluated as a boolean. .. sourcecode:: jinja {{ users|rejectattr("is_active") }} {{ users|rejectattr("email", "none") }} Similar to a generator comprehension such as: .. code-block:: python (u for user in users if not user.is_active) (u for user in users if not test_none(user.email)) .. versionadded:: 2.7 c| Sr#r$rs r'rz$sync_do_rejectattr..brr)Trrs r'sync_do_rejectattrrIs2 GUD&//4 P PPr)c0Kt||||ddS)Nc| Sr#r$rs r'rzdo_rejectattr..lrr)Trrs r' do_rejectattrres# "'5$QU V VVr)indentc|jj}|d}|d}||}||d<t|fd|i|S)aSerialize an object to a string of JSON, and mark it safe to render in HTML. This filter is only for use in HTML documents. The returned string is safe to render in HTML documents and ``