a P}e%ej*fej9ej$e.e%ej!ej:e%ej$ej:e%dffej?e%fd6d7d8Z@e2ZAe3ZBe4ZCe5ZDdS)9z2Extension API for adding custom tags and behavior.N)Markup)defaults)nodes) Environment)TemplateAssertionError)TemplateSyntaxError)concat)Context) Undefined) import_string) pass_context)Token) TokenStream)Parserc@s0eZdZeedddZeeeedddZdS)_TranslationsBasic)messagereturncCsdSN)selfrrr>/usr/lib/python3.9/site-packages/ansible/_vendor/jinja2/ext.pygettextsz_TranslationsBasic.gettext)singularpluralnrcCsdSrr)rrrrrrrngettextsz_TranslationsBasic.ngettextN)__name__ __module__ __qualname__strrintrrrrrrsrc@s4eZdZeeedddZeeeeedddZdS)_TranslationsContext)contextrrcCsdSrr)rr#rrrrpgettext!sz_TranslationsContext.pgettext)r#rrrrcCsdSrr)rr#rrrrrr npgettext$sz_TranslationsContext.npgettextN)rrrr r$r!r%rrrrr" sr")_rrr$r%.GETTEXT_FUNCTIONSz\s*\n\s*c @s8eZdZUdZejeed<ddddZe Z ej eed<dZ e dd d d Ze dd d d Zd eejeejeedddZdejdejdfdddZdejejejejfdddZd!eejeejdddZd"eejejejejejejejejejejejeejdddZdS)# 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). identifierN)rcCs|jd|j|_dS)N.)rrr))clsrrr__init_subclass__KszExtension.__init_subclass__tagsd environmentrcCs ||_dSr)r0rr0rrr__init__XszExtension.__init__cCs$t|j}|j|j||_|S)z=Create a copy of this extension bound to another environment.)object__new__ __class____dict__updater0)rr0rvrrrbind[s zExtension.bind)sourcenamefilenamercCs|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)rr:r;r<rrr preprocessbszExtension.preprocessrr)streamrcCs|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)rr>rrr filter_streamkszExtension.filter_streamrparserrcCs tdS)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. N)NotImplementedError)rrArrrparseuszExtension.parse)r;linenorcCstj|j||dS)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) rD)rExtensionAttributer))rr;rDrrrattr}s zExtension.attr)r;argskwargsdyn_args dyn_kwargsrDrcCs8|dur g}|durg}tj|j||d|||||dS)zsCall a method of the extension. This is a shortcut for :meth:`attr` + :class:`jinja2.nodes.Call`. NrE)rCallrG)rr;rHrIrJrKrDrrr call_methods  zExtension.call_method)N)N)NNNNN) rrr__doc__tClassVarr __annotations__r,setr-Setpriorityrr2r9Optionalr=UnionIterabler?rNodeListrCr!rFrGExprKeywordrLrMrrrrr(6sF   $     r() __contextrHrIrcOs|j|dg|Ri|S)Nr)callresolve)r\rHrIrrr_gettext_aliassr_)funcrcs"ttttjtdfdd }|S)N)r\__string variablesrcs$||}|jjrt|}||Sr)r]eval_ctx autoescaper)r\rarbr8r`rrrs z"_make_new_gettext..gettextr r r rOAny)r`rrrer_make_new_gettexts rhcs&ttttttjtdfdd }|S)N)r\ __singular__plural__numrbrcs4|d|||||}|jjr,t|}||S)Nnum setdefaultr]rcrdr)r\rirjrkrbr8rerrrs  z$_make_new_ngettext..ngettextr r r r!rOrg)r`rrrer_make_new_ngettextsrpcs$tttttjtdfdd }|S)N)r\ __string_ctxrarbrcs2|d||||}|jjr*t|}||S)Nr#rm)r\rqrarbr8rerrr$s  z$_make_new_pgettext..pgettextrf)r`r$rrer_make_new_pgettexts   rrc s(tttttttjtdfdd }|S)N)r\rqrirjrkrbrcsB|d||d||||||}|jjr:t|}||S)Nr#rlrm)r\rqrirjrkrbr8rerrr%s  z&_make_new_npgettext..npgettextro)r`r%rrer_make_new_npgettextsrsc seZdZdZdhZeddfdd Zd%deje ddd d Z d&eje dd d d Z d'ej e ge fej e e ege feje ejej e e ge fejej e e e ege fddddZdddddZefeje ejfeje ejejee ejeje ejeje dfffdddZdejejejejfdddZefe eje e dddZde ejeje e fdd d!Ze eje eje ej e ej!fejej!e e ej"d"d#d$Z#Z$S)(InternationalizationExtensionz-This extension adds gettext support to Jinja.ZtransNr/cs:t|t|jd<|j|j|j|j|j|j dddS)Nr&F)Zinstall_gettext_translationsZinstall_null_translationsZinstall_gettext_callablesZuninstall_gettext_translationsZextract_translationsnewstyle_gettext) superr2r_globalsextend_install _install_null_install_callables _uninstall_extractr1r5rrr2s  z&InternationalizationExtension.__init___SupportedTranslations) translationsnewstylercCsdt|dd}|dur|j}t|dd}|dur4|j}t|dd}t|dd}|j|||||ddS)NZugettextZ ungettextr$r%)rr$r%)getattrrrr{)rrrrrr$r%rrrry s     z&InternationalizationExtension._install)rrcCsxddl}|}t|dr"|j}ntttddd}t|drF|j}ntttttddd }|j|j|j|||d dS) Nrr$)csrcSs|Srr)rrrrrr$)sz=InternationalizationExtension._install_null..pgettextr%)rrprrcSs|dkr |S|S)Nrr)rrrrrrrr%0sz>InternationalizationExtension._install_null..npgettext)rrrr$r%) rNullTranslationshasattrr$r r%r!r{r)rrrrr$r%rrrrzs  z+InternationalizationExtension._install_null)rrrr$r%rcCsb|dur||j_|jjrHt|}t|}|dur8t|}|durHt|}|jjj||||ddSN)rrr$r%)r0rurhrprrrsrwr7)rrrrr$r%rrrr{;sz0InternationalizationExtension._install_callables)rrcCsdD]}|jj|dqdSr)r0rwpop)rrkeyrrrr|Ssz(InternationalizationExtension._uninstall.)r:gettext_functionsrcCs t|tr|j|}t||Sr) isinstancer r0rCextract_from_ast)rr:rrrrr}Ws  z&InternationalizationExtension._extractrr@c Cs*t|jj}d}|jd}|dur*|j}d}d}d}i}d} |jjjdkrV|r^|jd|jdrnqV|jd} | j|vr|j d| jd | jt d |jjjd krt|j| || j<} n8| dur| jd vr| jd k} q>nt | jd|| j<} |dur>t| t jrFt dd}||| j<t t dd| }n| }| jdk}q>|jdd} d} t}||d\}}|r|||durt |dd}|ddk}|jjdr^d} t|j|jjjdkr,|jd} | j|vr|j d| jd| jt d || j}| jdk}|jd||d\}} t|j||n t|j|D] }||vrlt |d||<ql| sd}n|dur| d|| dur|jjd} | r||}| r|| } ||| |||t||o| }|||dur"||gS|SdS)zParse a translatable tag.NstringFZ block_endZcommacolonr;ztranslatable variable z defined twice.)excZassign)trimmedZ notrimmedrloadZ_transstorerlTrname:pluralizezunknown variable z for pluralizationzpluralize without variablesext.i18n.trimmed)nextr>rDZnext_ifvaluecurrenttypeexpectZskip_iffailrZparse_expressionrNamerrLZAssignrR _parse_blockr7testr0policies_trim_whitespace _make_nodeboolZ set_lineno)rrArDr#Z context_token plural_exprZplural_expr_assignmentnum_called_numrbrtokenvarrZ have_plural referencedZsingular_namesrZ plural_namesr;noderrrrCbs                                    z#InternationalizationExtension.parse)r_ws_rercCs|d|S)N )substrip)rrrrrrrsz.InternationalizationExtension._trim_whitespace)rAallow_pluralizercCsg}g}|jjjdkr:||jjjddt|jq|jjjdkrt|j|jdj}|||d|d|jdq|jjjd krt|j|jjd rqn|jjd r|rq| d | d q|jj r| dqt dq|t |fS)z1Parse until the next block tag with a given name.data%%%Zvariable_beginr;z%(z)sZ variable_endZ 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) r>rrappendrreplacerrrrZeos RuntimeErrorr )rrArrbufr;rrrrs8      z*InternationalizationExtension._parse_block)rrr#rbrvars_referencedrrcCs|jj}|s,|s,|dd}|r,|dd}d} t|g} |dur`| dt|d| } |durd| } | t||ftt| d| gdd} |r| D]*\} } |r| d krq| j t | | qn0t | } |r t| td d | D} t| gS) z/Generates a useful node from the data provided.rrrNrrrrrlcSs"g|]\}}tt||qSr)rZPairConst).0rrrrr :sz.)r0rurrrinsertrxrLritemsrIrr[ZMarkSafeIfAutoescapeZModDictOutput)rrrr#rbrrrrZ func_nameZ func_argsrrrrrrrs<         z(InternationalizationExtension._make_node)N)N)NNN)%rrrrNr-rr2rOrUrryrzCallabler r!r{r|r'rVrTemplateSequenceIteratorTupler}rXrYrCrPatternrrrrZrr __classcell__rrr~rrtsV      . $z ' rtc@s(eZdZdZdhZdejdddZdS)ExprStmtExtensionzrAdds a `do` tag to Jinja that works like the print statement just that it doesn't print the return value. dorr@cCs"tjt|jjd}||_|S)NrE)rExprStmtrr>rDZ parse_tupler)rrArrrrrCJs zExprStmtExtension.parseN)rrrrNr-rrrCrrrrrCsrc@s6eZdZdZddhZdejejej fdddZ dS) LoopControlExtensionz/Adds break and continue to the template engine.breakcontinuerr@cCs0t|j}|jdkr"tj|jdStj|jdS)NrrE)rr>rrBreakrDContinue)rrArrrrrCUs  zLoopControlExtension.parseN) rrrrNr-rOrVrrrrCrrrrrPsrc@s8eZdZdZdhZdejdddZee ddd Z 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 debugrr@cCs8|jdj}t}|jd|g|d}tj|g|dS)Nz name:debug_renderrE)r>rrDrZContextReferencerMr)rrArDr#resultrrrrCsszDebugExtension.parse)r#rcCs8|t|jjt|jjd}tj|dddS)N)r#filterstestsT)depthZcompact)Zget_allsortedr0rkeysrpprintZpformat)rr#rrrrrys zDebugExtension._renderN) rrrrNr-rrrCr r rrrrrr\srT)astr babel_stylerccs|tjD]}t|jtjr |jj|vr,q g}|jD]4}t|tjr`t|j t r`| |j q6| dq6|j D]}| dqr|j dur| d|jdur| d|stdd|D}|sq nt|dkr|d}nt|}|j|jj|fVq dS)aExtract localizable strings from the given template node. Per default this function returns matches in babel style that means non string parameters as well as keyword arguments are returned as `None`. This allows Babel to figure out what you really meant if you are using gettext functions that allow keyword arguments for placeholder expansion. If you don't want that behavior set the `babel_style` parameter to `False` which causes only strings to be returned and parameters are always stored in tuples. As a consequence invalid gettext calls (calls without a single string parameter or string parameters after non-string parameters) are skipped. This example explains the behavior: >>> 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. Ncss|]}|dur|VqdSrr)rxrrr z#extract_from_ast..rr)Zfind_allrrLrrrr;rHrrr rrIrJrKtuplelenrD)rrrrstringsargr&outrrrrs2+            rc@sfeZdZdZejejeeefejeddddZ eej edddZ eej ed d d 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. N)tokens comment_tagsrcCs||_||_d|_d|_dS)Nr)rroffset last_lineno)rrrrrrr2sz_CommentFinder.__init__)rrc Cszt|j|j|D]^\}}}|dvrz|dd\}}WntyRYqYn0||jvr|gW||_SqgW||_S||_0dS)N)commentZ linecommentr)reversedrrsplit ValueErrorrrstrip)rrr& token_typeZ token_valueprefixrrrrfind_backwardss"   z_CommentFinder.find_backwards)rDrcCsd|jr|j|krgSt|j|jdD]*\}\}}}||kr(||j|Sq(|t|jSr)rr enumeraterrrr)rrDidxZ token_linenor&rrr find_commentss "z_CommentFinder.find_comments) rrrrNrOrrr!r r2rYrrrrrrrs  r)fileobjkeywordsroptionsrccsi}|dddD]}|}|s(qd|t|<qt|vrFd|t<dtjttftttddd}||d d }t |d t j |d t j |d t j |dt j|dt j|dt j|dpt j|dpt j||dt j||dt jt j||dt jt|ddd}||dr&d |jd<||dr8d |_||dd} z"|| } t||| } Wnt y|sYdS0t!| |} t"| |D] \} }}| ||| #| fVqdS)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,NF)rrdefaultrcSs||t|dvS)N>1ZyestrueZon)getr lower)rrrrrrgetbool-szbabel_extract..getboolsilentTZblock_start_stringZblock_end_stringZvariable_start_stringZvariable_end_stringZcomment_start_stringZcomment_end_stringZline_statement_prefixZline_comment_prefixZ trim_blocksZ lstrip_blocksZkeep_trailing_newliner)Z cache_sizeZ auto_reloadrrruencodingzutf-8)F)$rrrr rtrOMappingr rrrZBLOCK_START_STRINGZBLOCK_END_STRINGZVARIABLE_START_STRINGZVARIABLE_END_STRINGZCOMMENT_START_STRINGZCOMMENT_END_STRINGZLINE_STATEMENT_PREFIXZLINE_COMMENT_PREFIXZ TRIM_BLOCKSZ LSTRIP_BLOCKSZNEWLINE_SEQUENCEZKEEP_TRAILING_NEWLINErrrureaddecoderClistZlexr=rrrr)rrrrrZextension_namerrr0r:rrfinderrDr`rrrr babel_extractsT%                r)ErNrretypingrOZ markupsaferrrrr0r exceptionsrrZruntimer r r Zutilsr r TYPE_CHECKINGZtyping_extensionsteZlexerrrrArProtocolrr"rVrr'rr rQcompilerr(rgr_rrhr!rprrrsrtrrrrrrrrUrrBinaryIOrrYrZi18nrZ loopcontrolsrrrrrs               m &*( P  *. O)0 ]