P}e%ej*fdej9ej$e.e%ej!ej:e%ej$ej:e%dffej?e%ff d9Z@e2ZAe3ZBe4ZCe5ZDdS):z2Extension API for adding custom tags and behavior.N)Markup)defaults)nodes) Environment)TemplateAssertionError)TemplateSyntaxError)concat)Context) Undefined) import_string) pass_context)Token) TokenStream)Parserc6eZdZdedefdZdedededefdZdS) _TranslationsBasicmessagereturncdSN)selfrs ,/usr/lib/python3/dist-packages/jinja2/ext.pygettextz_TranslationsBasic.gettext CsingularpluralncdSrr)rrrr s rngettextz_TranslationsBasic.ngettexts DrN)__name__ __module__ __qualname__strrintr"rrrrrsf 3 3     S # # #      rrc >eZdZdededefdZdededededef dZd S) _TranslationsContextcontextrrcdSrr)rr*rs rpgettextz_TranslationsContext.pgettext!rrrrr cdSrr)rr*rrr s r npgettextz_TranslationsContext.npgettext$rrN)r#r$r%r&r,r'r.rrrr)r) su C # #     S C   QT      rr))_rr"r,r..GETTEXT_FUNCTIONSz\s*\n\s*ceZdZUdZejeed<ddZe Z ej eed<dZ de ddfd Zde ddfd Z dd ed ejed ejedefdZdddejdejdffdZdddejejejejffdZ dd edejedejfdZ dd edejejejdejejejdejejdejejdejedejfdZdS) ExtensionagExtensions can be used to add extra functionality to the Jinja template system at the parser level. Custom extensions are bound to an environment but may not store environment specific data on `self`. The reason for this is that an extension can be bound to another environment (for overlays) by creating a copy and reassigning the `environment` attribute. As extensions are created by the environment they cannot accept any arguments for configuration. One may want to work around that by using a factory function, but that is not possible as extensions are identified by their import name. The correct way to configure the extension is storing the configuration values on the environment. Because this way the environment ends up acting as central configuration storage the attributes may clash which is why extensions have to ensure that the names they choose for configuration are not too generic. ``prefix`` for example is a terrible name, ``fragment_cache_prefix`` on the other hand is a good name as includes the name of the extension (fragment cache). identifierrNc2|jd|j|_dS)N.)r$r#r3)clss r__init_subclass__zExtension.__init_subclass__KsN;;S\;;rtagsd environmentc||_dSr)r:)rr:s r__init__zExtension.__init__Xs&rct|j}|j|j||_|S)z=Create a copy of this extension bound to another environment.)object__new__ __class____dict__updater:)rr:rvs rbindzExtension.bind[s9 ^^DN + + 4=)))$ rsourcenamefilenamec|S)zThis method is called before the actual lexing and can be used to preprocess the source. The `filename` is optional. The return value must be the preprocessed source. r)rrErFrGs r preprocesszExtension.preprocessbs  rstreamrrc|S)a It's passed a :class:`~jinja2.lexer.TokenStream` that can be used to filter tokens returned. This method has to return an iterable of :class:`~jinja2.lexer.Token`\s, but it doesn't have to return a :class:`~jinja2.lexer.TokenStream`. r)rrJs r filter_streamzExtension.filter_streamks  rparserrct)aIf any of the :attr:`tags` matched this method is called with the parser as first argument. The token the parser stream is pointing at is the name token that matched. This method has to return one or a list of multiple nodes. )NotImplementedError)rrMs rparsezExtension.parseus "###rlinenoc:tj|j||S)zReturn an attribute node for the current extension. This is useful to pass constants on extensions to generated template code. :: self.attr('_my_attribute', lineno=lineno) rQ)rExtensionAttributer3)rrFrQs rattrzExtension.attr}s'fMMMMrargskwargsdyn_args dyn_kwargscp|g}|g}tj||||||||S)zsCall a method of the extension. This is a shortcut for :meth:`attr` + :class:`jinja2.nodes.Call`. NrS)rCallrU)rrFrVrWrXrYrQs r call_methodzExtension.call_methodsS <D >Fz IId6I * *         r)rNr)NNNNN) r#r$r%__doc__tClassVarr&__annotations__r7setr8Setpriorityrr<rDOptionalrIUnionIterablerLrNodeListrPr'rTrUExprKeywordr[r\rrrr2r26s\$ 3<<<<suuD!%*H'K'D''''  OS!"C<=JsO #  7 33 4$H$QVEJ=O1O)P$$$$48 N N N!"C N  ! N N N N0448+/-1"&   j +,  16%-01  *UZ(  Juz*   3        rr2 __contextrVrWrcJ|j|dg|Ri|S)Nr)callresolve)rkrVrWs r_gettext_aliasros4 9>)++I66 H H H H H HHrfuncc ptdtdtdtjdtffd }|S)Nrk__string variablesrcp||}|jjrt|}||zSr)rmeval_ctx autoescaper)rkrrrsrCrps rrz"_make_new_gettext..gettexts; ^^D( + +   ( BI~rrr r&r^Any)rprs` r_make_new_gettextrysP7c#\ Nrc tdtdtdtdtdtjdtf fd }|S)Nrk __singular__plural__numrsrc|d|||||}|jjrt |}||zS)Nnum setdefaultrmrurvr)rkr{r|r}rsrCrps rr"z$_make_new_ngettext..ngettextsU UE*** ^^D*h > >   ( BI~rrr r&r'r^rx)rpr"s` r_make_new_ngettextrsl      U      \  Orc ~tdtdtdtdtjdtf fd }|S)Nrk __string_ctxrrrsrc|d||||}|jjrt |}||zS)Nr*r)rkrrrrsrCrps rr,z$_make_new_pgettext..pgettextsU Y 555 ^^D, 9 9   ( BI~rrw)rpr,s` r_make_new_pgettextrs\  *- 9< KL5       \  Orctdtdtdtdtdtdtjdtffd }|S) Nrkrr{r|r}rsrc|d||d||||||}|jjrt |}||zS)Nr*rr)rkrr{r|r}rsrCrps rr.z&_make_new_npgettext..npgettextso Y 555UE*** ^^D, He L L   ( BI~rr)rpr.s` r_make_new_npgettextrsy    U  \$ rceZdZdZdhZdeddffd Z d&ddd eje ddfd Z d&d eje ddfd Z d'd ej e ge fd ej e e ege fd eje dejej e e ge fdejej e e e ege fddf dZd(dZefdeje ejfdeje dejejee ejeje ejeje dffffdZdddejejejejffdZefde deje de fdZddde dejeje e ffdZde deje d eje d!ej e ej!fd"ejej!d#e d$e dej"fd%Z#xZ$S))InternationalizationExtensionz-This extension adds gettext support to Jinja.transr:rNct|t|jd<||j|j|j|j|j ddS)Nr/F)install_gettext_translationsinstall_null_translationsinstall_gettext_callablesuninstall_gettext_translationsextract_translationsnewstyle_gettext) superr<roglobalsextend_install _install_null_install_callables _uninstall_extract)rr:r@s rr<z&InternationalizationExtension.__init__sm %%%#1 C )-&*&8&*&=+/?!%"      r translations_SupportedTranslationsnewstylect|dd}||j}t|dd}||j}t|dd}t|dd}||||||dS)Nugettext ungettextr,r.)rr,r.)getattrrr"r)rrrrr"r,r.s rrz&InternationalizationExtension._install s , D99 ?"*G<d;;  #,H<T::L+t<<   X8y      rc ^ddl}|}t|dr|j}ndtdtdtfd}t|dr|j}n'dtdtdtd t dtf d }||j|j||| dS) Nrr,csrc|Srr)rrs rr,z=InternationalizationExtension._install_null..pgettext)srr.pr c|dkr|n|S)Nrr)rrrr s rr.z>InternationalizationExtension._install_null..npgettext0sFFqq)r)rr"rr,r.) rNullTranslationshasattrr,r&r.r'rr")rrrrr,r.s rrz+InternationalizationExtension._install_nulls//11 < , , #,HH C C C     < - - *$.II *S *S *S *S *S * * * *  (!*      rrr"r,r.c| ||j_|jjr@t|}t|}|t |}|t |}|jj||||dSN)rr"r,r.)r:rryrrrrrB)rrr"rr,r.s rrz0InternationalizationExtension._install_callables;s  08D  -   , ;'00G)(33H#-h77$/ ::   ''hY (     rcPdD]"}|jj|d#dSr)r:rpop)rrkeys rrz(InternationalizationExtension._uninstallSs:C 4 4C   $ ( (d 3 3 3 3 4 4rrEgettext_functions.ct|tr|j|}t ||Sr) isinstancer&r:rPextract_from_ast)rrErs rrz&InternationalizationExtension._extractWs= fc " " 4%++F33F(9:::rrMrc t|jj}d}|jd}||j}d}d}d}i}d} |jjjdkr|r|jd|jdrnX|jd} | j|vr+| d| jd | jt |jjjd kr3t|j| x|| j<} n;| | jd vr | jd k} tj | jdx|| j<} |ot| tjrHtj dd}||| j<tjtj dd| }n| }| jdk}|jjjdk|jdd} d} t#}||d\}}|r>|||'tj |dd}|ddk}|jjdrd} t|j|jjjdkrf|jd} | j|vr+| d| jd| jt || j}| jdk}|jd||d\}} t|j||nt|j|D]}||vrtj |d||<| sd}n|| d|| |jjd} | r,||}| r|| } ||| |||t3||o| }|||||gS|S)zParse a translatable tag.NstringF block_endcommacolonrFztranslatable variable z defined twice.)excassign)trimmed notrimmedrload_transstorerTrname:pluralizezunknown variable z for pluralizationzpluralize without variablesext.i18n.trimmed)nextrJrQnext_ifvaluecurrenttypeexpectskip_iffailrparse_expressionrNamerr[Assignra _parse_blockrBtestr:policies_trim_whitespace _make_nodebool set_lineno)rrMrQr* context_token plural_exprplural_expr_assignmentnum_called_numrsrtokenvarr have_plural referencedsingular_namesr plural_namesrFnodes rrPz#InternationalizationExtension.parsebsfm$$+ --h77  $#)G /3 ;?-/ m#(K77 . $$W---}$$W-- M((00E{i'' KU[KKKL.}$)X55V]###/5/F/F/H/HH %+&U[4L%L%L+2/4z%+v/N/NN %+&"c5:..&"'*Xv">">K-8Iek*-2\ 8W55s..**#&K!&!5Gm#(K77J  [))) UU $(#4#4VT#B#B   <   n - - -"#j):FCC !/!2e!; = % %&6 7 7 K    }$)[88 ,,V44;i//KKMEKMMM 2  ( 4 !&!5 M  - - -#'#4#4VU#C#C L&       l + + + +     ; ;D9$$"'*T6":": $ ?KK  KK5v > > > ?&/0BCG  7,,X66H 7..v66          *{    ! -*D1 1Krr_ws_recR|d|S)N )substrip)rrrs rrz.InternationalizationExtension._trim_whitespaceszz#v||~~...rallow_pluralizecg}g} |jjjdkrN||jjjddt |jnX|jjjdkr|t |j|jdj}|||d|d|jd n|jjjd krt |j|jjd rn|jjd r|rn^| d | dn1|jj r| dntd|t|fS)z1Parse until the next block tag with a given name.Tdata%%%variable_beginrFz%(z)s variable_end block_beginz name:endtransrz:a translatable section can have only one pluralize sectionz;control structures in translatable sections are not allowedzunclosed translation blockzinternal parser error) rJrrappendrreplacerrrreos RuntimeErrorr )rrMrrbufrFs rrz*InternationalizationExtension._parse_blocks  <}$)V33 6=06>>sDIIJJJV]####&+/???V]###}++F339!!$''' ====))) $$^4444&+}<<V]###=(--o>>]*//0@AA&KKT Q" < 89999"#:;;;5 <86#;;&&rrrr*rsrvars_referencedrcB|jj}|s0|s.|dd}|r|dd}d} tj|g} |-| dtj|d| } |.d| } | tj||ftjtj| d| gdd} |rQ| D];\} } |r| d kr| j tj | | z.:sB *U"Ju{3'7'7??r)r:rrrrinsertrr[ritemsrWrrjMarkSafeIfAutoescapeModDictOutput)rrrr*rsrrrr func_name func_argsrrrs rrz(InternationalizationExtension._make_nodes#4  3x 3''c22H 3c22 ).X)>)>(?     Q G 4 4 5 5 5'II  "'II   ek&11;? @ @ @z%*Y77BdSS  'oo// > > U"cUll ""5=e#<#<====  >-d33D yJ.7oo.?.?|TF###rr)NNN)rrrN)%r#r$r%r]r8rr<r^rdrrrCallabler&r'rrr0rerTemplateSequenceIteratorTuplerrgrhrPrPatternrrrrirr __classcell__)r@s@rrrs[77 9D  K  D       TX  4 @A 4@P     $  aj&6 $    @&*<@GK   SE3J' *c3_c12 *T"  *QZc C89  :aj#sC)=s)BCD       04444.? ; ;U^+, ;:c? ;  S!'!*S/171:c?C;O3P"PQQR  ; ; ; ;xHxQVEJ=O1O)PxxxxtFL//s/AIcN/PS////#'#'15#' c! "#'#'#'#'J<$<$ 3<$C <$ 6#uz/* <$ Z + <$<$<$ <$<$<$<$<$<$<$<$rrc2eZdZdZdhZdddejfdZdS)ExprStmtExtensionzrAdds a `do` tag to Jinja that works like the print statement just that it doesn't print the return value. dorMrrctjt|jj}||_|S)NrS)rExprStmtrrJrQ parse_tupler)rrMrs rrPzExprStmtExtension.parseJs9~T&-%8%8%?@@@&&((  rN)r#r$r%r]r8rr rPrrrr r CsK 6DHrr cXeZdZdZddhZdddejejej ffdZ dS) LoopControlExtensionz/Adds break and continue to the template engine.breakcontinuerMrrct|j}|jdkrtj|jStj|jS)NrrS)rrJrrBreakrQContinue)rrMrs rrPzLoopControlExtension.parseUsHV]## ;' ! !;el333 3~U\2222rN) r#r$r%r]r8r^rerrrrPrrrrrPsV99 Z D3H3en1L)M333333rrcBeZdZdZdhZdddejfdZdede fdZ d S) DebugExtensionaA ``{% debug %}`` tag that dumps the available variables, filters, and tests. .. code-block:: html+jinja
{% debug %}
.. code-block:: text {'context': {'cycler': , ..., 'namespace': }, 'filters': ['abs', 'attr', 'batch', 'capitalize', 'center', 'count', 'd', ..., 'urlencode', 'urlize', 'wordcount', 'wordwrap', 'xmlattr'], 'tests': ['!=', '<', '<=', '==', '>', '>=', 'callable', 'defined', ..., 'odd', 'sameas', 'sequence', 'string', 'undefined', 'upper']} .. versionadded:: 2.11.0 debugrMrrc|jdj}tj}|d|g|}tj|g|S)Nz name:debug_renderrS)rJrrQrContextReferencer\r)rrMrQr*results rrPzDebugExtension.parsess[%%l33:(**!!)gYv!FF|VHV4444rr*c|t|jjt|jjd}t j|ddS)N)r*filterstestsT)depthcompact)get_allsortedr:rkeysrpprintpformat)rr*rs rrzDebugExtension._renderysn((d.6;;==>>D,27799::  ~fAt<<<>> from jinja2 import Environment >>> env = Environment() >>> node = env.parse('{{ (_("foo"), _(), ngettext("foo", "bar", 42)) }}') >>> list(extract_from_ast(node)) [(1, '_', 'foo'), (1, '_', ()), (1, 'ngettext', ('foo', 'bar', None))] >>> list(extract_from_ast(node, babel_style=False)) [(1, '_', ('foo',)), (1, 'ngettext', ('foo', 'bar'))] For every string found this function yields a ``(lineno, function, message)`` tuple, where: * ``lineno`` is the number of the line on which the string was found, * ``function`` is the name of the ``gettext`` function used (if the string was extracted from embedded Python code), and * ``message`` is the string, or a tuple of strings for functions with multiple string arguments. This extraction function operates on the AST and is because of that unable to extract any comments. For comment support you have to use the babel extraction interface or extract comments yourself. Nc3K|]}||V dSrr)rxs r z#extract_from_ast..s"<3.....C!/!/rceZdZdZdejejeeefdejeddfdZ dedej efdZ d edej efd Z dS) _CommentFinderzHelper class to find comments in a token stream. Can only find comments for gettext calls forwards. Once the comment from line 4 is found, a comment for line 1 will not return a usable value. tokens comment_tagsrNc>||_||_d|_d|_dS)Nr)r5r6offset last_lineno)rr5r6s rr<z_CommentFinder.__init__s( ( rr8c* t|j|j|D]\\}}}|dvrR |dd\}}n#t$rY1wxYw||jvr|gc||_S]g||_S#||_wxYw)N)comment linecommentr)reversedr5r8split ValueErrorr6rstrip)rr8r/ token_type token_valueprefixr;s rfind_backwardsz_CommentFinder.find_backwardss !.6 DK&01// 2 2*:{!;;;!*5*;*;D!*D*D%!!! !!222 ' 0 0111!DKK DKK&DK s4+B AB  AB A"B ?B BrQc|jr |j|krgSt|j|jdD].\}\}}}||kr||j|zcS/|t |jSr)r6r9 enumerater5r8rDr/)rrQidx token_linenor/s r find_commentsz_CommentFinder.find_commentss  D$4v$=$=I)24;t{}}3M)N)N > > %C%,1f$$**4;+<=====%""3t{#3#3444r) r#r$r%r]r^rrr'r&r<rhrDrIrrrr4r4s jc3!78HI SV !S!QVC[!!!! 5C5AF3K555555rr4fileobjkeywordsr6optionsc#@Ki}|dddD]+}|}|sd|t|<,t|vr d|t<ddt jttfdtdtd tfd }||d d }t|d tj |dtj |dtj |dtj|dtj|dtj|dp tj|dp tj||dtj||dtjtj||dtjt/|dd}||dr d |jd<||drd |_||dd} || } t;||| } n#t@$r|sYdSwxYwtC| |} tE| |D]!\} }}| ||| #| fV"dS) aBabel extraction method for Jinja templates. .. versionchanged:: 2.3 Basic support for translation comments was added. If `comment_tags` is now set to a list of keywords for extraction, the extractor will try to find the best preceding comment that begins with one of the keywords. For best results, make sure to not have more than one gettext call in one line of code and the matching comment in the same line or the line before. .. versionchanged:: 2.5.1 The `newstyle_gettext` flag can be set to `True` to enable newstyle gettext calls. .. versionchanged:: 2.7 A `silent` option can now be provided. If set to `False` template syntax errors are propagated instead of being ignored. :param fileobj: the file-like object the messages should be extracted from :param keywords: a list of keywords (i.e. function names) that should be recognized as translation functions :param comment_tags: a list of translator tags to search for and include in the results. :param options: a dictionary of additional options (optional) :return: an iterator over ``(lineno, funcname, message, comments)`` tuples. (comments will be empty currently) extensions,NFrLrdefaultrcp||t|dvS)N>1onyestrue)getr&lower)rLrrQs rgetboolzbabel_extract..getbool-s.{{3G --33559SSSrsilentTblock_start_stringblock_end_stringvariable_start_stringvariable_end_stringcomment_start_stringcomment_end_stringline_statement_prefixline_comment_prefix trim_blocks lstrip_blockskeep_trailing_newliner) cache_size auto_reloadrrrencodingzutf-8)F)$rWr>rr rr^Mappingr&rrrBLOCK_START_STRINGBLOCK_END_STRINGVARIABLE_START_STRINGVARIABLE_END_STRINGCOMMENT_START_STRINGCOMMENT_END_STRINGLINE_STATEMENT_PREFIXLINE_COMMENT_PREFIX TRIM_BLOCKS LSTRIP_BLOCKSNEWLINE_SEQUENCEKEEP_TRAILING_NEWLINEr.rrreaddecoderPlistlexrIr r4rrI)rJrKr6rLrNextension_namerYrZr:rErr5finderrQrprs r babel_extractr|s2J35J!++lB77==cBB99'--//  48 =0011$J6648 01TT38,T3TTRVTTTTWWh - -F ((*EFF &(ABB +X-KLL )8+GHH *H,IJJ ((*EFF +,,N0N )**Jh.J(<==(*@AA!0(2PQQ jK$ww ""837 /0ww*++,'+ $ \\^^ " "7;;z7#C#C D DF  ((kook&<&rs888 $$$$$$......++++++ ?O""""""""""R[1W%79M%MN (1738$ K j j j j j j j j ZII uI01IWQUI IIII AJucz2 qz#s(7K    QZc3(<=!*SRUXBV&QZc C8QZS=Q" *c3S)3. /ZS2K$K$K$K$K$IK$K$K$\         3 3 3 3 39 3 3 3%=%=%=%=%=Y%=%=%=T*;L/L/ L/z#L/L/ZGCagajoqwqz#7K/LLM MN L/L/L/L/^%5%5%5%5%5%5%5%5PYB ZYBjoYB*S/YBVCJ  YB ZG S!'!*S/171:c?C3G+HHI16RU;V YBYBYBYBz%# r