kfh~ UdZddlmZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z ddlmZddlmZddlmZmZmZmZmZddlmZmZdd lmZmZmZer dd lmZm Z dd l!m"Z"m#Z#m$Z$dd l%m&Z&m'Z'm(Z(Gd de(dZ)Gdde(dZ*Gdde#e+e$e+e Z,e-e.e-e.e.fze-e.e/fzdfdzZ0de1d<e-e/e.e/e-e/dfze2e/e/dzfZ3de1d<e-e.e/e-e/dfze2e/e/dzfZ4de1d<ee,ee+ze e/e0fe e/e e/efge e4fZ5de1d<e5e/zZ6de1d<dZ7de1d<dddddd d!dd"d#d$ Z8d%e1d&<d'gZ9d(e1d)<dbd.Z:dcd3Z;de9de8d4dddfdddEZ< dedfdHZ=e8d4ddfdgdNZ>e8d4ddfdhdQZ?didSZ@djdUZAdkd\ZB dldmd_ZC dldndaZDdS)oaf babel.messages.extract ~~~~~~~~~~~~~~~~~~~~~~ Basic infrastructure for extracting localizable messages from source files. This module defines an extensible system for collecting localizable message strings from a variety of sources. A native extractor for Python source files is builtin, extractors for other sources can be added using very simple plugins. The main entry points into the extraction functionality are the functions `extract_from_dir` and `extract_from_file`. :copyright: (c) 2013-2023 by the Babel Team. :license: BSD, see LICENSE for more details. ) annotationsN)Callable Collection GeneratorIterableMappingMutableSequence)relpath)dedent)COMMENTNAMEOPSTRINGgenerate_tokens) TYPE_CHECKINGAny)parse_encodingparse_future_flags pathmatch)IOProtocol) SupportsItems SupportsReadSupportsReadline)Final TypeAlias TypedDictceZdZUded<dS) _PyOptionsstrencodingN__name__ __module__ __qualname____annotations__v/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/babel/messages/extract.pyrr-s r(rF)totalc8eZdZUded<ded<ded<ded<dS) _JSOptionsr r!booljsxtemplate_stringparse_template_stringNr"r'r(r)r,r,0s<  ######r(r,c eZdZd d dZd dZdS) _FileObj._FileObj__offsetint_FileObj__whencereturncdSNr')selfr3r5s r)seekz _FileObj.seek7r(cdSr8r')r9s r)tellz _FileObj.tell8r;r(N).)r3r4r5r4r6r4)r6r4)r#r$r%r:r=r'r(r)r2r26s+FFFFF""""""r(r2.r_Keyword_FileExtractionResult_ExtractionResult_CallableExtractionMethod_ExtractionMethodzbabel.extractorsz Final[str] GROUP_NAME))rE)rE)rDcrE)rGrErF) _gettextngettextugettext ungettextdgettext dngettextN_pgettext npgettextzdict[str, _Keyword]DEFAULT_KEYWORDS)z**.pypythonzlist[tuple[str, str]]DEFAULT_MAPPINGcommentsMutableSequence[str]tags Iterable[str]c>dfd }t|||dd<dS)zHelper function for `extract` that strips comment tags from strings in a list of comment lines. This functions operates in-place. liner cD]B}||r+|t|dcSC|Sr8) startswithlenstrip)r[tagrXs r)_stripz#_strip_comment_tags.._stripasV / /Cs## /CHHII,,..... / r(N)r[r )map)rVrXras ` r)_strip_comment_tagsrc]s> fh''HQQQKKKr(dirpathstr | os.PathLike[str]r6r-ctj|}|dp|d S)N.rI)ospathbasenamer])rdsubdirs r)default_directory_filterrlisA W  g & &F!!#&&@&*;*;C*@*@ AAr(r'dirnamestr | os.PathLike[str] | None method_mapIterable[tuple[str, str]] options_map)SupportsItems[str, dict[str, Any]] | NonekeywordsMapping[str, _Keyword] comment_tagsCollection[str]callback3Callable[[str, str, dict[str, Any]], object] | Nonestrip_comment_tagsdirectory_filterCallable[[str], bool] | None,Generator[_FileExtractionResult, None, None]c # K|tj}|i}ttj|}tj|D]\ } }  fd| D| dd<| | | D]]} tj | tj d} t| |||||||Ed{V^dS)a$ Extract messages from any source files found in the given directory. This function generates tuples of the form ``(filename, lineno, message, comments, context)``. Which extraction method is used per file is determined by the `method_map` parameter, which maps extended glob patterns to extraction method names. For example, the following is the default mapping: >>> method_map = [ ... ('**.py', 'python') ... ] This basically says that files with the filename extension ".py" at any level inside the directory should be processed by the "python" extraction method. Files that don't match any of the mapping patterns are ignored. See the documentation of the `pathmatch` function for details on the pattern syntax. The following extended mapping would also use the "genshi" extraction method on any file in "templates" subdirectory: >>> method_map = [ ... ('**/templates/**.*', 'genshi'), ... ('**.py', 'python') ... ] The dictionary provided by the optional `options_map` parameter augments these mappings. It uses extended glob patterns as keys, and the values are dictionaries mapping options names to option values (both strings). The glob patterns of the `options_map` do not necessarily need to be the same as those used in the method mapping. For example, while all files in the ``templates`` folders in an application may be Genshi applications, the options for those files may differ based on extension: >>> options_map = { ... '**/templates/**.txt': { ... 'template_class': 'genshi.template:TextTemplate', ... 'encoding': 'latin-1' ... }, ... '**/templates/**.html': { ... 'include_attrs': '' ... } ... } :param dirname: the path to the directory to extract messages from. If not given the current working directory is used. :param method_map: a list of ``(pattern, method)`` tuples that maps of extraction method names to extended glob patterns :param options_map: a dictionary of additional options (optional) :param keywords: a dictionary mapping keywords (i.e. names of functions that should be recognized as translation functions) to tuples that specify which of their arguments contain localizable strings :param comment_tags: a list of tags of translator comments to search for and include in the results :param callback: a function that is called for every file that message are extracted from, just before the extraction itself is performed; the function is passed the filename, the name of the extraction method and and the options dictionary as positional arguments, in that order :param strip_comment_tags: a flag that if set to `True` causes all comment tags to be removed from the collected comments. :param directory_filter: a callback to determine whether a directory should be recursed into. Receives the full directory path; should return True if the directory is valid. :see: `pathmatch` Ncfg|]-}tj|+|.Sr')rhrijoin).0rkrzroots r) z$extract_from_dir..sJ    T6 : :;;    r(/)rd) rhgetcwdrlriabspathwalksortrreplacesepcheck_and_call_extract_file)rmrorqrsrurwryrzabsnamedirnames filenamesfilenamefilepathrs ` @r)extract_from_dirrosP^)++ 3goog&&G%'WW%5%5!h      !)      !  Hw||D(33;;BFCHHH2"            r(r"SupportsItems[str, dict[str, Any]]c #Kt||}|D]u\} } t| |si} |D]\} } t| |r| } |r ||| | t| |||| |D] }|g|RV dSdS)aChecks if the given file matches an extraction method mapping, and if so, calls extract_from_file. Note that the extraction method mappings are based relative to dirpath. So, given an absolute path to a file `filepath`, we want to check using just the relative path from `dirpath` to `filepath`. Yields 5-tuples (filename, lineno, messages, comments, context). :param filepath: An absolute path to a file that exists. :param method_map: a list of ``(pattern, method)`` tuples that maps of extraction method names to extended glob patterns :param options_map: a dictionary of additional options (optional) :param callback: a function that is called for every file that message are extracted from, just before the extraction itself is performed; the function is passed the filename, the name of the extraction method and and the options dictionary as positional arguments, in that order :param keywords: a dictionary mapping keywords (i.e. names of functions that should be recognized as translation functions) to tuples that specify which of their arguments contain localizable strings :param comment_tags: a list of tags of translator comments to search for and include in the results :param strip_comment_tags: a flag that if set to `True` causes all comment tags to be removed from the collected comments. :param dirpath: the path to the directory to extract messages from. :return: iterable of 5-tuples (filename, lineno, messages, comments, context) :rtype: Iterable[tuple[str, int, str|tuple[str], list[str], str|None] )rsruoptionsryN)r ritemsextract_from_file)rrorqrwrsruryrdrpatternmethodropatternodict message_tuples r)rrsPx))H%(++  *0022  OHe8,,   0 HXvw / / /. H%1     - -M,m,, , , , , 'r(rrrMapping[str, Any] | Nonelist[_ExtractionResult]c |dkrgSt|d5}tt||||||cdddS#1swxYwYdS)aExtract messages from a specific file. This function returns a list of tuples of the form ``(lineno, message, comments, context)``. :param filename: the path to the file to extract messages from :param method: a string specifying the extraction method (.e.g. "python") :param keywords: a dictionary mapping keywords (i.e. names of functions that should be recognized as translation functions) to tuples that specify which of their arguments contain localizable strings :param comment_tags: a list of translator tags to search for and include in the results :param strip_comment_tags: a flag that if set to `True` causes all comment tags to be removed from the collected comments. :param options: a dictionary of additional options (optional) :returns: list of tuples of the form ``(lineno, message, comments, context)`` :rtype: list[tuple[int, str|tuple[str], list[str], str|None] ignorerbN)openlistextract)rrrsrurryfileobjs r)rrs4 h  :GFGX|#%799::::::::::::::::::::s!AA A r(Generator[_ExtractionResult, None, None]c#HKd}t|r|}nd|vsd|vrld|vr-|d}|d|||dzd} }n|dd\}} tt |ii| g| }nx ddlm} | t|D]} | d}n#t$rYnwxYw|*tttd } | |}|td ||||||pi } | D]d\}}}}|r ||pd nd }t#|t$t&fs|g}|s8d}g}d }t)|}|D]Y}t#|t&r||ddz })||krd}n'||dz }|d}n||Z|rt#|dt&r |ddz }n |ddz }||s:t|ddpd}t,j|d|d t'|}t)|dkr|d}|rt3||||||fVfdS)aExtract messages from the given file-like object using the specified extraction method. This function returns tuples of the form ``(lineno, message, comments, context)``. The implementation dispatches the actual extraction to plugins, based on the value of the ``method`` parameter. >>> source = b'''# foo module ... def run(argv): ... print(_('Hello, world!')) ... ''' >>> from io import BytesIO >>> for message in extract('python', BytesIO(source)): ... print(message) (3, u'Hello, world!', [], None) :param method: an extraction method (a callable), or a string specifying the extraction method (.e.g. "python"); if this is a simple name, the extraction function will be looked up by entry point; if it is an explicit reference to a function (of the form ``package.module:funcname`` or ``package.module.funcname``), the corresponding function will be imported and used :param fileobj: the file-like object the messages should be extracted from :param keywords: a dictionary mapping keywords (i.e. names of functions that should be recognized as translation functions) to tuples that specify which of their arguments contain localizable strings :param comment_tags: a list of translator tags to search for and include in the results :param options: a dictionary of additional options (optional) :param strip_comment_tags: a flag that if set to `True` causes all comment tags to be removed from the collected comments. :raise ValueError: if the extraction method is not registered :returns: iterable of tuples of the form ``(lineno, message, comments, context)`` :rtype: Iterable[tuple[int, str|tuple[str], list[str], str|None] N:rgrDr) working_setT)require)rrT javascriptzUnknown extraction method )rrDFnamez (unknown)z: warning: Empty msgid. It is reserved by GNU gettext: gettext("") returns the header entry with meta information, not the empty string. )callablerfindsplitgetattr __import__ pkg_resourcesriter_entry_pointsrCload ImportErrorextract_nothingextract_pythonextract_javascriptget ValueErrorkeys isinstancertupler^appendsysstderrwriterc)rrrsrurryfunclastdotmoduleattrnamer entry_pointbuiltinresultslinenofuncnamemessagesrVspeccontextmsgsinvalid last_indexindexmessagefirst_msg_indexrs r)rr>s^ D' #-- f  ll3''G%hwh/! 1EHFF%||C33 FHz&"b8*==xHH  1 1 1 1 1 1 +<z extract_python..s!((**11(;;r()defclassT(rDrr)cg|] }|d Srr'rcomments r)rz"extract_python..$sFFFw FFFr(,)rrrrr rr r_rr]rr^rr_parse_python_stringpop)rrsrurrrmessage_lineno call_stackbufrtranslator_commentsin_defin_translator_comments comment_tag future_flags next_linetokenstokvaluerInestedval old_lineno old_commentr!s` @r)rrs7(*.-H-vJ CH&++F #Kg&&J'++j'*J*JH%gx88L;;;;;I Y ' 'F)/OO%UKVQA   t 9I0I0IFF BYY5C<<  !'a C r esllF  2  #..!""IOO%%E% '+A.&1*<<#**FE?;;; ,   ##K00-1*'..???E0 *//Tk7ex&7Fr esllvl*OOBGGCLL111AAAOOD))).1(mma.?.?5???Xa['-+B/2^a5GGG*,'%xFF2EFFFHHHH6:996N &(#).&%$H*5(LII?JJsOOOu||*OOBGGCLL111AAAOOD)))&N /B.E.E.G.G+J '.. Q /LMMM !^^r esll !OJJ  ***HH D[[Uh..H_OOr(rr r!rr4 str | Nonec*tdt|d|ddtj|z}t |tjr|j}t |tjr|jSt |tj rtd|j Dr$d d|j DStd|j Dr$d d |j DSdS) Nz # coding= zevalc3JK|]}t|tjVdSr8)rastStrrnodes r) z'_parse_python_string..Ts.EE:dCG,,EEEEEEr(rc3$K|] }|jV dSr8)srs r)rz'_parse_python_string..Us$>>$tv>>>>>>r(c3JK|]}t|tjVdSr8)rrConstantrs r)rz'_parse_python_string..Vs.JJd:dCL11JJJJJJr(c3>K|]}t|jVdSr8)r rrs r)rz'_parse_python_string..Ws*GG4s4:GGGGGGr() compiler r PyCF_ONLY_ASTr Expressionbodyrr JoinedStrallvaluesr)rr!rcoder s r)rrFs ,CMM,,U,, L(   D $''Hy dCG $ $ 6M dCM * * HEEEEEEE ?ww>>$+>>>>>>JJdkJJJJJ HwwGG4;GGGGGG 4r(rDrc #0 Kddlm}m}m}dx}} g} d} g} d} |dd}d}d}t d|D}||||d d |d d || D]}|rD|rB|jd kr7|jd kr,|j } ||j g} d}|dd|j }|dr2|s0|jd kr%t|j ||||j Ed{VnY|jdkr|j dkr|r |j } |dz }n3|dkr|jdkr|j dd }| r8| dd|j dz kr| |j |f"|D]G}||r0| |j | fnHn{|jdkrg} |j dd }|D]}||r|}|r|d |d<t!d|dd|dd<t%|D]$\}}| |j |z|f%nn|r|dkr|jdkr|j dkr| | | t'| dkrt)| } n | r | d} nd} | r| dd| dz krg} | | || d| DfVdx}x} } d} g} g} d}n|jdvr||j }| r | pd|z} d} n|} n|jdkrJ|j dkr2| | | d} n| dd} nt|j dkrd } nf|dkr|jdkr|j dkr|dz}nD|r |dkrd}n9|dkr3|jd kr(|j |vr||jd ks |j dkr|j }|}dS)aExtract messages from JavaScript source code. :param fileobj: the seekable, 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) Supported options are: * `jsx` -- set to false to disable JSX/E4X support. * `template_string` -- if `True`, supports gettext(`key`) * `parse_template_string` -- if `True` will parse the contents of javascript template strings. :param lineno: line number offset (for parsing embedded fragments) r)Tokentokenizeunquote_stringNFr!zutf-8rc3K|]}d|vV dS)rgNr')rkws r)rz%extract_javascript..}s&..r......r(r.Tr/)r.r/dottedrroperatorrr0rrD linecommentrEmultilinecommentrcg|] }|d Srr'rs r)rz&extract_javascript..sJJJ7GAJJJJr()stringr/rr+function)babel.messages.jslexerrrrranyreadrtyperrr0r_rr] splitlinesr r enumerater^r)rrsrurrrrrrrr last_argumentrconcatenate_nextr! last_tokenrrtokenrrlinesoffsetr[ new_values r)rr\s0GFFFFFFFFF $$H~HM{{:w//HJJ ..X... . .F h'' KKt $ $ $5t<< oo  9  9&Ov55 J+ + +"\N&u{334HJE*c5<88E ;;. / /\ #\ #UZSdEdEd,U[(LRY[`[ghh h h h h h h h h Z: % %%+*<*< !&a 2  %* "="=KO))++E" "2&q)U\A-===#**EL%+@AAA+   ##K00'.. ekkmm/LMMMEZ- - -"$ K"%++--E+   ##K00!,,..E?#(8>>#3#3a$*499U122Y+?+?$@$@$K$K$M$Mabb ,5e,<,<??LFD/66 v8M8<8>????E9 #*//zZ''EK3,>,> ,OOM222x==1$$$XHH$'{HH#H'-&r*1-0BBB*,'')8XJJ6IJJJLLLL=A@@>M#( &(# <<<*N5;77 #.%2%8bI$EM',$$$-MMz));#%%$0  666(,  ---',$$[C'''+$ !^^ j 8 8K3&& !OJJ  #***HH 2  %*"6"6 K8 # #  :?f#<#<   + +{H _oor(r/c#Kddlm}d}d}d}d} |ddD]} |s| dvr| }n|| kr|d krd}|r| | z } |s| d kr |d kr|dz }n|r| d kr}|dz}|dkrr| rp| dd} tj| } t | ||||Ed{V|t || z }d} | }dS) aParse JavaScript template string. :param template_string: the template string to be parsed :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) :param lineno: starting line number (optional) r)line_reNFrrDr)"'`z\\{$})rr+ioBytesIOencoderr^findall) r/rsrurrr+prev_characterlevel inside_strexpression_contents character fake_file_objs r)r0r0si"/.....N EJ$QrT*##  i?::"JJ 9 $ $5)@)@J  - 9 ,  -CNc$9$9  -9++ A::"5:*=ad*C'$&J/B/I/I/K/K$L$LM1-r&rr?r@rArBrCrSrUrcrlrrrrrrrrr0r'r(r)rFs"#""""" ??????????????%%%%%%%%DDDDDDDDDD"C########GGGGGGGGGG==========Ye$$$$$Ye$$$$ #####<&(8(?### eCHo 5c3h G LMPTTHTTTT(-S#sU38_7LdSViY\_cYc-c'ddddd$)cE#s(O.CT#YPSVZPZ)Z#[[[[[,4 BuI wsH}5z#PSUXPXHYZ"# %, $=s#BBBBB+ ++++  ! ) )    +>)>>>>> ( ( ( (BBBB.2,;=A'7$&DH$59jjjjjj.2=====F(8$&(,$ :::::J(8$&(,$ F2F2F2F2F2R    ppppf6 QQQQQr (#(#(#(#(#(#(#r(