ƪbChdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl m Z ddlmZddlmZddlmZmZdd lmZdd lmZmZdd lmZmZmZmZdd lm Z dd l!m"Z"m#Z#ddl$m%Z%ejLdZ' ddl(m)Z*e'Z+ ddl,m-Z-m.Z.m/Z/d'dZ8Gdde*Z)Gdde)Z9dZ:Gdde)Z;dZ<Gdde)Z=Gdd e)Z>Gd!d"Z?d#Z@d'd$ZAgfd%ZBeCd&k(re@yy#e0$r e1xZ-xZ.Z/YrwxYw#e0$rddl2m'Z+ddl3m)Z*ddl4m5Z-m6Z.m7Z/YwxYw)(z babel.messages.frontend ~~~~~~~~~~~~~~~~~~~~~~~ Frontends for the message extraction functionality. :copyright: (c) 2013-2022 by the Babel Team. :license: BSD, see LICENSE for more details. N) OrderedDict)RawConfigParser)datetime)StringIO) __version__)Locale localedata)UnknownLocaleError)CatalogDEFAULT_HEADER)DEFAULT_KEYWORDSDEFAULT_MAPPINGcheck_and_call_extract_fileextract_from_dir)write_mo)read_powrite_po)LOCALTZbabel)Command) OptionError SetupError BaseError)log)DistutilsOptionErrorDistutilsSetupErrorDistutilsErrorc>g}t|ttfs|g}|D]h}|t|ttfr|jt ||9|jdt |j |Djtd|DsJ|S)a Make a list out of an argument. Values from `distutils` argument parsing are always single strings; values from `optparse` parsing may be lists of strings that may need to be further split. No matter the input, this function returns a flat list of whitespace-trimmed strings, with `None` values filtered out. >>> listify_value("foo bar") ['foo', 'bar'] >>> listify_value(["foo bar"]) ['foo', 'bar'] >>> listify_value([["foo"], "bar"]) ['foo', 'bar'] >>> listify_value([["foo"], ["bar", None, "foo"]]) ['foo', 'bar', 'foo'] >>> listify_value("foo, bar, quux", ",") ['foo', 'bar', 'quux'] :param arg: A string or a list of strings :param split: The argument to pass to `str.split()`. :return: )splitc3<K|]}|jywNstrip).0ss 9/usr/lib/python3/dist-packages/babel/messages/frontend.py z listify_value..Ys<1779<c3<K|]}t|tywr!) isinstancestr)r$vals r&r'z listify_value..Zs3z#s#3r()r*listtupleextend listify_valuer+rall)argroutr,s r&r0r04s4 C cD%= )e= ;  cD%= ) JJ}S6 7  domains of PO files (space separated list, default 'messages'))z directory=d.path to base directory containing the catalogsz input-file=izname of the input file) output-file=ozQname of the output file (default '//LC_MESSAGES/.mo')locale=lz locale of the catalog to compile) use-fuzzyfzalso include fuzzy translations) statisticsNz#print statistics about translationsrXrZcfd|_d|_d|_d|_d|_d|_d|_yNmessagesF)domain directory input_file output_filelocale use_fuzzyrZr?s r&r9z"compile_catalog.initialize_optionss4   r4ct|j|_|js|js t d|j s|js t dyy)Nz ?%1%r4c g}g}|jso|jr|j|jtjj |j |jd|dzf|jtjj |j |jd|dzn\tj|j D]}tjj |j |d|dz}tjj|sR|j||f|jtjj |j |d|dzn|j|j|jf|jr|j|jnH|jtjj |j |jd|dz|s tdi}t|D]~\}\}}||}t|d5} t| |} ddd|jrmd} t ddD]} | j s| dz } d} t#| r| dzt#| z} |j$j'd | t#| | | j(r)|j*s|j$j'd |t| j-x|| <}|D]4\} }|D]*}|j$j/d || j0|,6|j$j'd ||t|d 5}t3|| |j*ddd|S#1swY^xYw#1swYxYw)N LC_MESSAGES.poz.mono message catalogs foundrbrrhdz)%d of %d messages (%d%%) translated in %sz'catalog %s is marked as fuzzy, skippingzerror: %s:%d: %szcompiling catalog %s to %swb)rc)r`rbappendospathjoinr_listdirexistsrar enumerateopenrrZr-stringrkrinfofuzzyrccheckrllinenor)r?r^po_filesmo_filesrbpo_filecatalogs_and_errorsidxmo_fileinfilern translatedmessage percentagecatalog_errorsrorloutfiles r&rizcompile_catalog._run_domainsG{{!#dnndkk.;.4un">!?@ T^^T[[-:-3e^!=>!jj8FF ggll4>>6+8&5.JGww~~g. (9:  T^^V5B5;e^)EF F OOT[[$//: ; 0 01 T^^T[[-:-3e^!=>9: : &/&9 E "C"&'smGgt$ 2!&&1 2 #G}QR0(G~~"a ( w#1 #EHHNN*GW^^U  HHMM6 Igt$ E'T^^D E E? ED#"A 2 2: E Es N6O6O O N) rBrCrD__doc__ description user_optionsrGr9rfrprir6r4r&rLrLs8 @KL"#L1O _&F#r4rLcfd}|S)zO Build a directory_filter function based on a list of ignore patterns. cntjj|tfdD S)Nc3JK|]}tj|ywr!)fnmatch)r$ignore_patternbasenames r&r'zG_make_directory_filter..cli_directory_filter..s$  OOHn 5 s #)ryrzrany)dirnamerignore_patternss @r&cli_directory_filterz4_make_directory_filter..cli_directory_filters877##G,     r4r6)rrs` r&_make_directory_filterrs  r4cZeZdZdZdZgdZgdZdZdZddd d d Z d d iZ dZ dZ dZ dZy)extract_messagesaMessage extraction command for use in ``setup.py`` scripts. If correctly installed, this command is available to Setuptools-using setup scripts automatically. For projects using plain old ``distutils``, the command needs to be registered explicitly in ``setup.py``:: from babel.messages.frontend import extract_messages setup( ... cmdclass = {'extract_messages': extract_messages} ) z1extract localizable strings from the project code))zcharset=Nz3charset to use in the output file (default "utf-8"))z keywords=kzispace-separated list of keywords to look for in addition to the defaults (may be repeated multiple times))no-default-keywordsNz#do not include the default keywords)z mapping-file=Fz&path to the mapping configuration file) no-locationNz>do not include location comments with filename and line number)z add-location=Nzlocation lines format. If it is not given or "full", it generates the lines with both file name and line number. If it is "file", the line number part is omitted. If it is "never", it completely suppresses the lines (same as --no-location).) omit-headerNz'do not include msgid "" entry in header)rSrTzname of the output filezwidth=wz"set output line width (default 76)no-wrapNzVdo not break long message lines, longer than the output line width, into several lines) sort-outputNz&generate sorted output (default False)) sort-by-fileNz,sort output by file location (default False))zmsgid-bugs-address=Nzset report address for msgid)zcopyright-holder=Nzset copyright holder in output)zproject=Nzset project name in output)zversion=Nzset project version in output)z add-comments=czuplace comment block with TAG (or those preceding keyword lines) in output file. Separate multiple TAGs with commas(,))strip-commentsr%z)strip the comment TAGs from the comments.)z input-paths=Nzofiles or directories that should be scanned for messages. Separate multiple files or directories with commas(,))z input-dirs=Nz@alias for input-paths (does allow files as well as directories).)z ignore-dirs=NzwPatterns for directories to ignore when scanning for messages. Separate multiple patterns with spaces (default ".* ._"))zheader-comment=Nzheader comment for the catalog)rrrrrrrz input-paths)z add-commentskeywordsz ignore-dirs)z --keyword)z --mapping)z--output)z--strip-comment-tags)rz mapping-filez output-filerz add-location)fullfilenevercFd|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_d|_d|_d|_d|_y)Nzutf-8FT)charsetrno_default_keywords mapping_file no_location add_location omit_headerra input_dirs input_pathswidthno_wrap sort_output sort_by_filemsgid_bugs_addresscopyright_holderprojectversion add_commentsstrip_commentsinclude_lineno ignore_dirsheader_commentrds r&r9z#extract_messages.initialize_optionsvs  #(        !"& $   #""r4c |jr)|js|j|_n td|jri}nt j }|j tt|j||_ |js td|js td|jr|jr td|js|jsd|_ n&|jt|j|_ |jr|jr td|jr@t!|jt"rt%j&d|j|_nu|j(bt*j-|j(j.xsdDcgc]}|j'd d d c}j1|_ng|_|js td |jD]/}t2j4j7|r#td |zt|j8xsdd|_|j(rV|j:s|j(j=|_|j>s|j(jA|_|jBdk(rd|_"n|jBdk(rd|_#t|jH}|rtK|jH|_&yd|_&ycc}w)Nz1input-dirs and input-paths are mutually exclusivez=you must specify new keywords if you disable the default oneszno output file specified0'--no-wrap' and '--width' are mutually exclusiveLz;'--sort-output' and '--sort-by-file' are mutually exclusivez,\s*r6.rhrz'no input files or directories specifiedzInput path: %s does not exist,rTrF)'rrrrr copyupdateparse_keywordsr0rrarrintrrr*r+rerr8dictfromkeyspackageskeysryrzr}rrget_namer get_versionrrrrrdirectory_filter)r?rrrzrs r&rfz!extract_messages.finalize_optionss ??###'?? !G  # #H',,.H}T]]'CDE  }}O 89 9 <>$'!"AD"HII J*$*;*;*Ar3G   <<#0099; <<#00<<>    '#D    & ("'D #D$4$45 $:4;K;K$LD !$(D !?.s Mc j}tjd5}tjj j jjjxst}|D]1\}}fd}tjjrEtj}t|||j j"j$|}n;t'||j j"|j$j(}|D]\} } } } } tjjr| }n=tjj+tjj-| }|j/| d|| fg| | 4j0j3djt5||j6j8j:j<j>j@dddy#1swYyxYw)Nrw)rrrrrrc |dk(rytjjr}n=tjjtjj |}d}|r;ddj |j Dcgc] \}}|d|dc}}z}j jd||ycc}}w)Nignorez (%s)z, z=""zextracting messages from %s%s)ryrzisfilenormpathr{rjrr) filenamemethodoptionsfilepathoptstrrvrzr?s r&callbackz&extract_messages.run..callbacks) ww~~d+#'#%77#3#3BGGLLx4P#QF!(499>Emmo6O6:aDEa6H6O,P"PHHMM"A8VT6Os C )r comment_tagsrstrip_comment_tagsr) auto_commentscontextzwriting PO template file to %s)rrrrrr)! _get_mappingsrrar rrrrrrr ryrzrgetcwdrrrrrrrr{addrrrrrrrrr)r?mappingsrrn method_map options_mapr current_dir extractedrrrcommentsrrrzs` @r&rpzextract_messages.runs%%' $""D ); 9Wdll&*ll151H1H/3/D/D&*ll.2.A.A.S^ VG2:+ I-j+U&77>>$'"$))+K ;j+ $--1B1B++[!I !1j+!%%)%6%6!)+/+>+>)-)>)> !IENI@Hfgxww~~d+#+#%77#3#3BGGLLx4P#QKK60B/C.6 I II+ IZ HHMM:D//LC_MESSAGES/.po'))rVrWz$locale for the new localized catalogrrrcfd|_d|_d|_d|_d|_d|_d|_yr\) output_dirrar`rbr^rrrds r&r9zinit_catalog.initialize_optionsks4     r4c|js td|js td tj|j|_|js|js td|jsHtjj|j|jd|jdz|_tjjtjj|js.>?@ KK(8(89 : <@Gww~~g. (9: ; OOT[[$*:*:; <9: :WW%%bgg&6&6t&GHKF $//4 ( 'FvH '!)? # FH  )A::-2L* 5x$//40BF&fT[[AGB "&(0 W(=% % (D)/WWg./ HHMM;Xt Wh% H!&G H NN$00&*&@&@   ggll277??8#<#+#9#9#;#%77#3#3H#=$>?G '4(OGWg)-)9)9-1-A-A.2mm4::OOzz(D)9X'.x'8$9'4(7G&-g&6O70@0N0N-)8)E)EFV)W X& '" # '8,m? #B ::(4(:(:(< M$*HHMM"=xHHH$$%A8L  M |**,- @AA @A  I ' 'BB// H HOO   '"9977 #  (# GX. '" #s. T.T;' U/U U/*:U"$U/ V $ V5V$.T8;U U U "U, 'U//V V V! $A W10W1Nrr6r4r&rrs- hr4rcXeZdZdZdZdezZdddddZee e e dZ d Z dd Zd Zd Zd Zy )CommandLineInterfacezCommand-line interface. This class provides a simple command-line interface to the message extraction and PO file generation functionality. z%%prog %s [options] %sz %%prog %sz$compile message catalogs to MO filesz:extract messages from source files and generate a POT filez+create new message catalogs from a POT filez0update existing message catalogs from a POT file)compileextractinitrNc|tj}tj|jdz|j |_|j j|j|j _ |j jdddd|j jd d d d tjd |j jddd d tjd|j jdtj|j j!|dd\}}|j#|j$|j&rut)j*}t-d|D}|j/d|dzz}|D]1}t1j2|}t5|||j6fz3y|s|j j9d|d} | |j:vr|j j9d| z|j=| |dd} | j?S)z{Main entry point of the command-line interface. :param argv: list of arguments passed on the command-line N)commandz[args])usagerz--list-locales list_locales store_truez print all known locales and exit)destactionr=z-vz --verbose store_constloglevelzprint as much as possible)r?r>constr=z-qz--quietzprint as little as possibleF)r<rArhc32K|]}t|ywr!rk)r$ identifiers r&r'z+CommandLineInterface.run..sHj#j/Hz %%-%ds %%srzQno valid command or option passed. Try the -h/--help option for more information.zunknown command "%s") sysargvoptparse OptionParserr;rparserdisable_interspersed_args_help print_help add_optionloggingDEBUGERROR set_defaultsINFO parse_args_configure_loggingrAr<r locale_identifiersmaxsortrrprint english_namerlcommands_configure_commandrp) r?rHrargs identifierslongestformatrErbcmdnamecmdinsts r&rpzCommandLineInterface.runs <88D++$**?T2T48LLB  --/!%  /n&2$F  H t[$.gmm$?  A tY}$.gmm$A  C   egll K ..tABx8   0 01   $779KHKHHG    "gk2F) B j1f F,?,?@@A B KK  O Pq' $-- ' KK  4w> ?))'48<{{}r4c|t|_|jj||jjr|jjd}n/tj}|jj ||j|tj d}|j|y)Nrz %(message)s)rsetLevelhandlersrP StreamHandler addHandler Formatter setFormatter)r?rAhandler formatters r&rVz'CommandLineInterface._configure_loggings (# 88  hh''*G++-G HH   ("%%m4 Y'r4c6t|jjtdtd|jD}dtd|dzz}t |jj }|D]\}}t|||fzy)Nz commands:c32K|]}t|ywr!rD)r$r:s r&r'z-CommandLineInterface._help..s@wc'l@rFz %%-%ds %%srh)rZrK format_helprXr\sortedrj)r?r`rar\rrs r&rMzCommandLineInterface._helps dkk%%'( k@$--@@#a1"55$----/0!) 0 D+ &D+.. / 0r4c|j|}|}|jr|j|_t|tsJ|j t j |j|dfz|j|}t|dd}|jD]\}}} |jd} t|| jdd} d| zg} |r| jd |z| j|jj!| d|j"j!| d } | |k(r|xjd | zz c_| |j$vr|j&| d | d | |j(vr|j&| d| | d|j&| | | | d|j+|\}}|rt-||jdd|t/|j1D]\}}t-||| |j3|S#t4$r%}|j7t9|Yd }~|Sd }~wwxYw)zB :type cmdname: str :type argv: list[str] r)r;rrEr6=-_z--%sz-%sNz<%s>r=)r?r=rx)r?r=choices)r=defaultrv)command_classesrr*rr9rIrJr;r\rrr#replacerxr/rHgetrIrGrOrFrUsetattrvarsrjensure_finalizedrrlr+)r?rbrHcmdclassrcrKrElongshortr=rrwstrsrvrr^keyrerrs r&r]z'CommandLineInterface._configure_commands/ ''0* 88((GK'7+++""$&&**}, g. (Ir2!)!6!6 V D%::c?Dgt||C'=>GTM?D EEM* KK//33D"= >--11$=Gw  - 111!!!4 4H888!!!4tWU!!!4dGWU V ))$/   GW__S#6 =w---/ )JC GS% ( ) #  $ $ & # LLS " " #sH(( I1IIr!)rBrCrDrr;VERSIONrr\rLrrrrxrrprVrMr]r6r4r&r5r5ts\ %EG#G9O=D H## O C.` (0.r4r5cPtjtjSr!)r5rprGrHr6r4r&mainrs  ! % %chh //r4ci}g}i}t}t|j|_|j|||j D]n}|dk(rt |j |}#d|jddD\}}|j||ft |j |||<p|r&t|D]\} \}}||vr||}||f|| <||fS)aParse an extraction method mapping from a file-like object. >>> buf = StringIO(''' ... [extractors] ... custom = mypackage.module:myfunc ... ... # Python source files ... [python: **.py] ... ... # Genshi templates ... [genshi: **/templates/**.html] ... include_attrs = ... [genshi: **/templates/**.txt] ... template_class = genshi.template:TextTemplate ... encoding = latin-1 ... ... # Some custom extractor ... [custom: **/custom/*.*] ... ''') >>> method_map, options_map = parse_mapping(buf) >>> len(method_map) 4 >>> method_map[0] ('**.py', 'python') >>> options_map['**.py'] {} >>> method_map[1] ('**/templates/**.html', 'genshi') >>> options_map['**/templates/**.html']['include_attrs'] '' >>> method_map[2] ('**/templates/**.txt', 'genshi') >>> options_map['**/templates/**.txt']['template_class'] 'genshi.template:TextTemplate' >>> options_map['**/templates/**.txt']['encoding'] 'latin-1' >>> method_map[3] ('**/custom/*.*', 'mypackage.module:myfunc') >>> options_map['**/custom/*.*'] {} :param fileobj: a readable file-like object containing the configuration text to parse :see: `extract_from_directory` extractorsc3<K|]}|jywr!r")r$parts r&r'z parse_mapping..GsNtzz|Nr(:rh) rr _sections read_filesectionsrrjrrxr~) rrrrrrKsectionrrrs r&rr sbJJK  F"6#3#34F Wh'??$? l "fll734JN c18MNOFG   w/ 0#' W(=#>K ?&/ &; 0 "C"'6##F+&/JsO 0 { ""r4c 4i}|D]}d|vr|jd\}}n|d}}||vs%|reg}|jdD]D}|ddk(r |jt|dddf+|jt|Ft|}|||<|S)aQParse keywords specifications from the given list of strings. >>> kw = sorted(parse_keywords(['_', 'dgettext:2', 'dngettext:2,3', 'pgettext:1c,2']).items()) >>> for keyword, indices in kw: ... print((keyword, indices)) ('_', None) ('dgettext', (2,)) ('dngettext', (2, 3)) ('pgettext', ((1, 'c'), 2)) rNrr)rrxrr.)stringsrrfuncnameindicesindsxs r&rrTsH) &= & S 1 Hg &gH 8 # s+,Au| S3B[#$67 CF+ ,  +!(HX ) Or4__main__r!)DrrrPrIryrr(rGr" collectionsr configparserrriorrrrrr babel.corer babel.messages.catalogr r babel.messages.extractr rrrbabel.messages.mofilerbabel.messages.pofilerr babel.utilr getLoggerr setuptoolsr_CommandrJsetuptools.errorsrrr ImportError Exception distutils distutils.cmddistutils.errorsrrrr0rLrrrrrr5rrrrBr6r4r&rsK #(($):ss*3g  E.M9HH'T&h&RD#gD#N  WwWt "V97V9rQWQhOOd0G#T< zFQ" 9/88 8j99E.1EEEs0 D D D DDDD10D1