a
    ÇZEg|±  ã                   @  sN  d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlmZ ddlmZ ddlmZ ddlmZmZmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZm Z  ddl!m"Z"m#Z#m$Z$m%Z% ddl&m'Z' ddl(m)Z)m*Z* ddl+m,Z, e -d¡Z.G dd„ de/ƒZ0G dd„ de0ƒZ1G dd„ de0ƒZ2G dd„ de0ƒZ3dIdd„Z4G dd„ dƒZ5G dd„ de5ƒZ6dd „ Z7G d!d"„ d"e5ƒZ8G d#d$„ d$e5ƒZ9G d%d&„ d&e5ƒZ:G d'd(„ d(ƒZ;d)d*„ Z<dJd+d,„Z=dKd-d.„Z>d/d0œd1d2œd3d4„Z?dLd6d7d8d9œd:d;„Z@d7d<d=œd>d?„ZAdMdAdBœdCdD„ZBd7dEœdFdG„ZCeDdHk�rJe<ƒ  dS )NzÕ
    babel.messages.frontend
    ~~~~~~~~~~~~~~~~~~~~~~~

    Frontends for the message extraction functionality.

    :copyright: (c) 2013-2024 by the Babel Team.
    :license: BSD, see LICENSE for more details.
é    )ÚannotationsN)ÚOrderedDict)ÚRawConfigParser)ÚStringIO)ÚBinaryIOÚIterableÚLiteral)ÚLocaleÚ
localedata)Ú__version__)ÚUnknownLocaleError)ÚDEFAULT_HEADERÚCatalog)ÚDEFAULT_KEYWORDSÚDEFAULT_MAPPINGÚcheck_and_call_extract_fileÚextract_from_dir)Úwrite_mo)Úread_poÚwrite_po)ÚLOCALTZÚbabelc                   @  s   e Zd ZdS )Ú	BaseErrorN©Ú__name__Ú
__module__Ú__qualname__© r   r   úP/var/www/sistema_ama/venv/lib/python3.9/site-packages/babel/messages/frontend.pyr   -   s   r   c                   @  s   e Zd ZdS )ÚOptionErrorNr   r   r   r   r   r   1   s   r   c                   @  s   e Zd ZdS )Ú
SetupErrorNr   r   r   r   r   r    5   s   r    c                   @  s   e Zd ZdZdS )ÚConfigurationErrorz3
    Raised for errors in configuration files.
    N)r   r   r   Ú__doc__r   r   r   r   r!   9   s   r!   c                 C  s†   g }t | ttfƒs| g} | D ]N}|du r*qt |ttfƒrL| t||d�¡ q| dd„ t|ƒ |¡D ƒ¡ qtdd„ |D ƒƒs‚J ‚|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:
    N©Úsplitc                 s  s   | ]}|  ¡ V  qd S ©N©Ústrip)Ú.0Úsr   r   r   Ú	<genexpr>d   ó    z listify_value.<locals>.<genexpr>c                 s  s   | ]}t |tƒV  qd S r%   )Ú
isinstanceÚstr)r(   Úvalr   r   r   r*   e   r+   )r,   ÚlistÚtupleÚextendÚlistify_valuer-   r$   Úall)Úargr$   Úoutr.   r   r   r   r2   ?   s     r2   c                   @  sF   e Zd ZdZdZdZi Zi ZeZddd„Z	dd„ Z
dd„ Zd	d
„ ZdS )ÚCommandMixinNr   c                 C  s0   || _ |  ¡  d | _d| _d | _d| _d| _d S )NFr   )ÚdistributionÚinitialize_optionsÚ_dry_runÚverboseÚforceÚhelpÚ	finalized)ÚselfÚdistr   r   r   Ú__init__‡   s    zCommandMixin.__init__c                 C  s   d S r%   r   ©r>   r   r   r   r8   ‘   s    zCommandMixin.initialize_optionsc                 C  s   | j s|  ¡  d| _ d S )Né   )r=   Úfinalize_optionsrA   r   r   r   Úensure_finalized”   s    zCommandMixin.ensure_finalizedc                 C  s   t d| j› d�ƒ‚d S )Nzabstract method -- subclass z must override)ÚRuntimeErrorÚ	__class__rA   r   r   r   rC   ™   s    ÿzCommandMixin.finalize_options)N)r   r   r   Úas_argsÚmultiple_value_optionsÚboolean_optionsÚoption_aliasesÚoption_choicesÚlogr@   r8   rD   rC   r   r   r   r   r6   i   s   

r6   c                   @  s@   e Zd ZdZg d¢ZddgZdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚCompileCatalogz+compile message catalogs to binary MO files))údomain=ÚDz>domains of PO files (space separated list, default 'messages'))z
directory=Údú.path to base directory containing the catalogs©zinput-file=Úizname of the input file)úoutput-file=ÚozQname of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.mo')©úlocale=Úlz locale of the catalog to compile)ú	use-fuzzyÚfzalso include fuzzy translations)Ú
statisticsNz#print statistics about translationsrY   r[   c                 C  s.   d| _ d | _d | _d | _d | _d| _d| _d S ©NÚmessagesF)ÚdomainÚ	directoryÚ
input_fileÚoutput_fileÚlocaleÚ	use_fuzzyr[   rA   r   r   r   r8   ´   s    z!CompileCatalog.initialize_optionsc                 C  s8   t | jƒ| _| js | js tdƒ‚| js4| js4tdƒ‚d S )Nz<you must specify either the input file or the base directoryz=you must specify either the output file or the base directory)r2   r^   r`   r_   r   ra   rA   r   r   r   rC   ½   s
    zCompileCatalog.finalize_optionsc                 C  sN   d}| j D ]$}|  |¡ ¡ D ]}|t|ƒ7 }qq
|rB| j d|¡ |rJdS dS )Nr   z%d errors encountered.rB   )r^   Ú_run_domainÚvaluesÚlenrL   Úerror)r>   Zn_errorsr^   Úerrorsr   r   r   ÚrunÄ   s    
zCompileCatalog.runc              
   C  sš  g }g }| j sÈ| jr`| | jtj | j| jd|› d�¡f¡ | tj | j| jd|› d�¡¡ nft | j¡D ]X}tj | j|d|› d�¡}tj |¡rl| ||f¡ | tj | j|d|› d�¡¡ qlnH| | j| j f¡ | j	rî| | j	¡ n"| tj | j| jd|› d�¡¡ |�st
dƒ‚i }t|ƒD �]h\}\}}|| }t|dƒ�}	t|	|ƒ}
W d   ƒ n1 �sl0    Y  | j�ràd}t|
ƒdd … D ]}|j�r’|d7 }�q’d}t|
ƒ�rÈ|d t|
ƒ }| j d	|t|
ƒ||¡ |
j�r| j�s| j d
|¡ �q*t|
 ¡ ƒ ||
< }|D ]*\}}|D ]}| j d||j|¡ �q&�q| j d||¡ t|dƒ� }t||
| jd� W d   ƒ n1 �sˆ0    Y  �q*|S )NÚLC_MESSAGESú.poz.moúno message catalogs foundÚrbr   rB   éd   z)%d of %d messages (%d%%) translated in %sz'catalog %s is marked as fuzzy, skippingzerror: %s:%d: %szcompiling catalog %s to %sÚwb)rc   )r`   rb   ÚappendÚosÚpathÚjoinr_   ÚlistdirÚexistsra   r   Ú	enumerateÚopenr   r[   r/   Ústringrf   rL   ÚinfoÚfuzzyrc   Úcheckrg   Úlinenor   )r>   r^   Úpo_filesZmo_filesrb   Úpo_fileZcatalogs_and_errorsÚidxZmo_fileÚinfileÚcatalogZ
translatedÚmessageÚ
percentageZcatalog_errorsrh   rg   Úoutfiler   r   r   rd   Í   s~    þÿþ
ÿþ
þ*
þ
ÿ4zCompileCatalog._run_domainN)
r   r   r   ÚdescriptionÚuser_optionsrI   r8   rC   ri   rd   r   r   r   r   rM   Ÿ   s   		rM   c                   s   ‡ fdd„}|S )zO
    Build a directory_filter function based on a list of ignore patterns.
    c                   s$   t j | ¡‰ t‡ fdd„ˆD ƒƒ S )Nc                 3  s   | ]}t   ˆ |¡V  qd S r%   )Úfnmatch)r(   Zignore_pattern©Úbasenamer   r   r*     s   ÿzG_make_directory_filter.<locals>.cli_directory_filter.<locals>.<genexpr>)rq   rr   r‰   Úany)Údirname©Úignore_patternsrˆ   r   Úcli_directory_filter  s    ýz4_make_directory_filter.<locals>.cli_directory_filterr   )r�   rŽ   r   rŒ   r   Ú_make_directory_filter  s    r�   c                   @  sn   e Zd ZdZg d¢Zg d¢ZdZdZdddd	d
dœZddiZ	dd„ Z
dd„ Zddœdd„Zdd„ Zdd„ ZdS )ÚExtractMessagesz1extract localizable strings from the project code))zcharset=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=Nzðlocation 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)rT   rU   zname of the output file©zwidth=Ú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))zmsgid-bugs-address=Nzset report address for msgid)zcopyright-holder=Nzset copyright holder in output)zproject=Nzset project name in output)zversion=Nzset 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 ".* ._"))zheader-comment=Nzheader comment for the catalog)zlast-translator=Nz7set the name and email of the last translator in output)r’   r”   r•   r™   rš   r›   r�   zinput-paths)zadd-commentsÚkeywordszignore-dirs)z	--keyword)z	--mapping)z--output)z--strip-comment-tags)z--last-translator)rž   zmapping-filezoutput-filer�   zlast-translatorzadd-location)ÚfullÚfileÚneverc                 C  s”   d| _ d | _d| _d | _d| _d | _d| _d | _d | _d | _	d | _
d| _d| _d| _d | _d | _d | _d | _d | _d| _d| _d | _d | _d | _d S )Nzutf-8FT)Úcharsetrž   Úno_default_keywordsÚmapping_fileÚno_locationÚadd_locationÚomit_headerra   Ú
input_dirsÚinput_pathsÚwidthÚno_wrapÚsort_outputÚsort_by_fileÚmsgid_bugs_addressÚcopyright_holderÚprojectÚversionÚadd_commentsÚstrip_commentsÚinclude_linenoÚignore_dirsÚheader_commentÚlast_translatorrA   r   r   r   r8   u  s0    z"ExtractMessages.initialize_optionsc                 C  sÞ  | j r| js| j | _ntdƒ‚| jr(i nt ¡ }| tt| j	ƒƒ¡ || _	| j	sXtdƒ‚| j
sftdƒ‚| jrz| jrztdƒ‚| jsŽ| jsŽd| _n| jd ur¤t| jƒ| _| jr¸| jr¸tdƒ‚| jrÜt| jtƒrÚt d| j¡| _n6| jd u�rt dd	„ | jjpüd
D ƒ¡ ¡ | _ng | _| j�s"tdƒ‚| jD ]$}tj |¡�s(td|› d�ƒ‚�q(t| j�pZd
dƒ| _| j�r’| j�s~| j ¡ | _| j�s’| j  ¡ | _| j!dk�r¦d| _"n| j!dk�r¸d| _#t| j$ƒ}|�rÔt%|ƒ| _&nd | _&d S )Nz1input-dirs and input-paths are mutually exclusivez=you must specify new keywords if you disable the default oneszno output file specifiedú0'--no-wrap' and '--width' are mutually exclusiveéL   z;'--sort-output' and '--sort-by-file' are mutually exclusivez,\s*c                 S  s   g | ]}|  d d¡d ‘qS )Ú.rB   r   r#   )r(   r‘   r   r   r   Ú
<listcomp>·  s   ÿz4ExtractMessages.finalize_options.<locals>.<listcomp>r   z'no input files or directories specifiedzInput path: z does not existú,r¡   Tr    F)'r¨   r©   r   r£   r   ÚcopyÚupdateÚparse_keywordsr2   rž   ra   r«   rª   Úintr¬   r­   r,   r-   Úrer$   r7   ÚdictÚfromkeysÚpackagesÚkeysrq   rr   ru   r²   r°   Úget_namer±   Úget_versionr¦   r¥   r´   rµ   r�   Údirectory_filter)r>   rž   rr   rµ   r   r   r   rC   �  sl    
ÿÿÿ
ÿ

þ

z ExtractMessages.finalize_optionsr-   )rr   c                   s   ddddœ‡ ‡fdd„}|S )Nr-   rÂ   )ÚfilenameÚmethodÚoptionsc                   st   |dkrd S t j ˆ ¡rˆ }nt j t j ˆ | ¡¡}d}|r`d dd„ | ¡ D ƒ¡}d|› d�}ˆj d||¡ d S )	NÚignoreÚ z, c                 s  s"   | ]\}}|› d |› d�V  qdS )z="ú"Nr   )r(   r‘   Úvr   r   r   r*   è  r+   zDExtractMessages._build_callback.<locals>.callback.<locals>.<genexpr>z (ú)zextracting messages from %s%s)rq   rr   ÚisfileÚnormpathrs   ÚitemsrL   ry   )rÉ   rÊ   rË   ÚfilepathZoptstrZ
opt_values©rr   r>   r   r   ÚcallbackÙ  s    z1ExtractMessages._build_callback.<locals>.callbackr   )r>   rr   rÖ   r   rÕ   r   Ú_build_callbackØ  s    zExtractMessages._build_callbackc                 C  sZ  |   ¡ }t| jdƒ��.}t| j| j| j| j| j| j	p6t
| jd�}|D ]¼\}}}|  |¡}tj |¡rŠt ¡ }t||||| j| j| j|ƒ}	n t|||| j| j|| j| jd�}	|	D ]P\}
}}}}tj |¡rÎ|
}ntj tj ||
¡¡}|j|d ||fg||d� q®qD| j d| j¡ t||| j| j| j| j | j!| j"d� W d   ƒ n1 �sL0    Y  d S )Nro   )r°   r±   r®   r¯   r¢   r¶   r·   )rž   Zcomment_tagsrÖ   Zstrip_comment_tagsrÈ   )Zauto_commentsÚcontextzwriting PO template file to %s)rª   r¥   r§   r¬   r­   r´   )#Ú_get_mappingsrw   ra   r   r°   r±   r®   r¯   r¢   r¶   r   r·   r×   rq   rr   rÑ   Úgetcwdr   rž   r²   r³   r   rÈ   rÒ   rs   ÚaddrL   ry   r   rª   r¥   r§   r¬   r­   r´   )r>   Úmappingsr„   r�   rr   Ú
method_mapÚoptions_maprÖ   Zcurrent_dirZ	extractedrÉ   r|   r‚   ÚcommentsrØ   rÔ   r   r   r   ri   î  sT    ú

ýúÿ

ûzExtractMessages.runc                 C  s€  g }| j rÌ| j  d¡rrt| j dƒ�>}tj | j ¡dkr:dnd}t|| j |d�\}}W d   ƒ q®1 sf0    Y  n<t| j ƒ�"}t|| j d�\}}W d   ƒ n1 s¤0    Y  | jD ]}| 	|||f¡ q´n°t
| jdd ƒ�r^| jj}| ¡ D ]n\}}t|tƒ�rtt|ƒƒ\}}n8g i  }}|D ](\}	}
}| 	|	|
f¡ |�p@i ||	< �q | 	|||f¡ qìn| jD ]}| 	|ti f¡ �qd|S )Nz.tomlrm   úpyproject.tomlÚ
standalone)rÉ   Ústyle©rÉ   Úmessage_extractors)r¤   Úendswithrw   rq   rr   r‰   Ú_parse_mapping_tomlÚparse_mapping_cfgr©   rp   Úgetattrr7   rä   rÓ   r,   r-   r   r   )r>   rÜ   ÚfileobjZ
file_stylerÝ   rÞ   rr   rä   ÚmappingÚpatternrÊ   rË   r   r   r   rÙ     s<    ÿýý*0


zExtractMessages._get_mappingsN)r   r   r   r…   r†   rI   rG   rH   rJ   rK   r8   rC   r×   ri   rÙ   r   r   r   r   r�   &  s$   8ûÿI.r�   c                   @  s6   e Zd ZdZg d¢ZdgZdd„ Zdd„ Zdd	„ Zd
S )ÚInitCatalogz(create a new catalog based on a POT file)©rN   rO   z&domain of PO file (default 'messages')rR   )úoutput-dir=rP   zpath to output directory©rT   rU   zQname of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po'))rW   rX   z$locale for the new localized catalogr–   r˜   r™   c                 C  s.   d | _ d | _d | _d | _d| _d| _d | _d S r\   )Ú
output_dirra   r`   rb   r^   r«   rª   rA   r   r   r   r8   [  s    zInitCatalog.initialize_optionsc              
   C  s  | j stdƒ‚| jstdƒ‚zt | j¡| _W n. ty\ } zt|ƒ|‚W Y d }~n
d }~0 0 | jsr| jsrtdƒ‚| js˜t	j
 | j| jd| j› d�¡| _t	j
 t	j
 | j¡¡sÂt	 t	j
 | j¡¡ | jrÖ| jrÖtdƒ‚| jsê| jsêd| _n| jd u�rt| jƒ| _d S )Núyou must specify the input filez-you must provide a locale for the new catalogz%you must specify the output directoryrj   rk   r¸   r¹   )r`   r   rb   r	   ÚparseÚ_localer   ra   rð   rq   rr   rs   r^   ru   r‹   Úmakedirsr«   rª   rÀ   ©r>   Úer   r   r   rC   d  s,     ÿzInitCatalog.finalize_optionsc                 C  sª   | j  d| j| j¡ t| jdƒ�}t|| jd�}W d   ƒ n1 sD0    Y  | j|_tj 	t
¡|_d|_t| jdƒ� }t||| jd� W d   ƒ n1 sœ0    Y  d S )Núcreating catalog %s based on %srm   ©rb   Fro   )rª   )rL   ry   ra   r`   rw   r   rb   ró   ÚdatetimeÚnowr   Úrevision_daterz   r   rª   )r>   r€   r�   r„   r   r   r   ri   ~  s    
ÿ,zInitCatalog.runN©	r   r   r   r…   r†   rI   r8   rC   ri   r   r   r   r   rì   E  s   	rì   c                   @  s8   e Zd ZdZg d¢Zg d¢Zdd„ Zdd„ Zdd	„ Zd
S )ÚUpdateCatalogz'update message catalogs from a POT file)rí   rR   )rî   rP   rQ   rï   )r•   Nz%do not include msgid  entry in headerrV   r–   r˜   )zignore-obsolete=Nz1whether to omit obsolete messages from the output)zinit-missing=Nz6if any output files are missing, initialize them first)úno-fuzzy-matchingÚNzdo not use fuzzy matching)úupdate-header-commentNzupdate target header comment)ÚpreviousNz+keep previous msgids of translated messages)zcheck=Nz‘don't update the catalog, just return the status. Return code 0 means nothing would change. Return code 1 means that the catalog would be updated)zignore-pot-creation-date=Nz=ignore changes to POT-Creation-Date when updating or checking)	r•   r™   zignore-obsoletezinit-missingrþ   r  r   r{   zignore-pot-creation-datec                 C  s^   d| _ d | _d | _d | _d| _d | _d | _d| _d| _d| _	d| _
d| _d| _d| _d| _d S r\   )r^   r`   rð   ra   r§   rb   rª   r«   Úignore_obsoleteÚinit_missingÚno_fuzzy_matchingÚupdate_header_commentr  r{   Úignore_pot_creation_daterA   r   r   r   r8   ¼  s    z UpdateCatalog.initialize_optionsc              
   C  sè   | j stdƒ‚| js"| js"tdƒ‚| jr6| js6tdƒ‚| jrŽ| jsJtdƒ‚zt | j¡| _W q” t	yŠ } zt|ƒ|‚W Y d }~q”d }~0 0 nd | _| j
r¨| jr¨tdƒ‚| j
s¼| js¼d| _n| jd urÒt| jƒ| _| jrä| jräd| _d S )Nrñ   z-you must specify the output file or directoryzyou must specify the localez?you must specify the locale for the init-missing option to workr¸   r¹   F)r`   r   ra   rð   rb   r  r	   rò   ró   r   r«   rª   rÀ   r  r  rõ   r   r   r   rC   Í  s0    ÿ"
zUpdateCatalog.finalize_optionsc              
   C  s  i }g }| j sŠ| jr@| | jtj | j| jd| j› d�¡f¡ qœt | j¡D ]:}tj | j|d| j› d�¡}tj 	|¡rL| ||f¡ qLn| | j| j f¡ |s¨t
dƒ‚| j}|sÌtj tj | j¡¡d }t| jdƒ�}t|ƒ}W d   ƒ n1 sö0    Y  |D �]¨\}}| j�rØtj 	|¡�sØ| j�r8d||< �q| j d|| j¡ t| jdƒ�}t|| jd�}	W d   ƒ n1 �s|0    Y  | j|	_tj t¡|	_d|	_t|d	ƒ�}
t|
|	ƒ W d   ƒ n1 �sÎ0    Y  | j d
|| j¡ t|dƒ�}t|||d�}	W d   ƒ n1 �s0    Y  |	j|| j| j| j d� tj tj |¡t  !¡ tj |¡ ¡}zLt|d	ƒ�,}t||	| j"| j#| j$| j%d� W d   ƒ n1 �s¤0    Y  W n  t&�yÐ   t '|¡ ‚ Y n0 | j�rft|dƒ�}t|ƒ}W d   ƒ n1 �s0    Y  t|dƒ�}t|ƒ}W d   ƒ n1 �s80    Y  |j|_| (|¡||< t '|¡ �qzt )||¡ W n4 t*�yª   t '|¡ t+ ,||¡ t '|¡ Y n0 �q| j�r| -¡ D ].\}}|�rÞ| j d|¡ n| j .d|¡ �qÀt/| 0¡ ƒ�st1dƒ‚n| j d¡ d S d S )Nrj   rk   rl   r   rm   Fr÷   rø   ro   zupdating catalog %s based on %s)rb   r^   )r  Zupdate_creation_date)r§   r  Zinclude_previousrª   zCatalog %s is up to date.zCatalog %s is out of date.zSome catalogs are out of date.z All the catalogs are up-to-date.)2ra   rb   rp   rq   rr   rs   rð   r^   rt   ru   r   Úsplitextr‰   r`   rw   r   r  r{   rL   ry   ró   rù   rú   r   rû   rz   r   r¾   r  r  r  r‹   ÚtempfileÚgettempprefixr§   r  r  rª   Ú	ExceptionÚremoveZis_identicalÚrenameÚOSErrorÚshutilr½   rÓ   Úwarningr3   re   r   )r>   Zcheck_statusr}   rb   r~   r^   r€   ÚtemplaterÉ   r�   r„   ZtmpnameZtmpfileZorigfileZoriginal_catalogÚnewfileZupdated_catalogZ
up_to_dater   r   r   ri   ì  s®    
þÿ
þ&ÿ.*.ý
ÿÿý*
((


zUpdateCatalog.runNrü   r   r   r   r   rý   �  s   $rý   c                   @  s`   e Zd ZdZdZde› �ZdddddœZee	e
edœZd	Zdd
d„Zdd„ Zdd„ Zdd„ Zd	S )ÚCommandLineInterfacez™Command-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 z$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)ÚcompileÚextractÚinitr¾   Nc           
      C  sl  |du rt j}tj| jd | jd�| _| j ¡  | j| j_	| jj
ddddd� | jj
d	d
ddtjdd� | jj
ddddtjdd� | jjdtjd� | j |dd… ¡\}}|  |j¡ |j�rt ¡ }tdd„ |D ƒƒd }t|ƒD ]*}t |¡}t|d|› �›d|j› �ƒ qædS |�s(| j d¡ |d }|| jv�rP| j d|› d�¡ |  ||dd… ¡}	|	 ¡ S )z{Main entry point of the command-line interface.

        :param argv: list of arguments passed on the command-line
        N)Úcommandz[args])Úusager±   z--list-localesÚlist_localesÚ
store_truez print all known locales and exit)ÚdestÚactionr<   z-vz	--verboseÚstore_constÚloglevelzprint as much as possible)r  r  Úconstr<   z-qz--quietzprint as little as possibleF)r  r  rB   c                 s  s   | ]}t |ƒV  qd S r%   ©rf   )r(   Ú
identifierr   r   r   r*   Ž  r+   z+CommandLineInterface.run.<locals>.<genexpr>ú<ú r   zQno valid command or option passed. Try the -h/--help option for more information.zunknown command "rÎ   ) ÚsysÚargvÚoptparseÚOptionParserr  r±   ÚparserÚdisable_interspersed_argsÚ_helpÚ
print_helpÚ
add_optionÚloggingÚDEBUGÚERRORÚset_defaultsÚINFOÚ
parse_argsÚ_configure_loggingr  r  r
   Zlocale_identifiersÚmaxÚsortedr	   rò   ÚprintZenglish_namerg   ÚcommandsÚ_configure_commandri   )
r>   r$  rË   ÚargsZidentifiersZid_widthr   rb   ÚcmdnameÚcmdinstr   r   r   ri   q  sH    ÿ


þþþ
zCommandLineInterface.runc                 C  s^   t | _ | j  |¡ | j jr(| j jd }nt ¡ }| j  |¡ | |¡ t d¡}| |¡ d S )Nr   z%(message)s)rL   ÚsetLevelÚhandlersr,  ÚStreamHandlerÚ
addHandlerÚ	FormatterÚsetFormatter)r>   r  ÚhandlerÚ	formatterr   r   r   r2  Ÿ  s    

z'CommandLineInterface._configure_loggingc                 C  sl   t | j ¡ ƒ t dƒ tdtdd„ | jD ƒƒd ƒ}t| j ¡ ƒD ]$\}}t d|d|› �›d|› �ƒ qBd S )	Nz	commands:é   c                 s  s   | ]}t |ƒV  qd S r%   r  )r(   r  r   r   r   r*   ±  r+   z-CommandLineInterface._help.<locals>.<genexpr>rB   z  r!  r"  )r5  r'  Úformat_helpr3  r6  r4  rÓ   )r>   Z	cmd_widthÚnamer…   r   r   r   r)  ®  s
    zCommandLineInterface._helpc              
   C  sÖ  | j | }|ƒ }| jr| j|_t|tƒs,J ‚| ¡  tj| j|df | j| d�}t	|ddƒ}|j
D ]Þ\}}}	| d¡}
t	||
 dd¡ƒ}d|
› �g}|rª| d|› �¡ | |j |
d¡¡ |j |
d	¡}|
|krì| jd
|
› d�7  _qd|
|jv �r|j|d|	dœŽ qd|
|jv �r.|j|d|	|dœŽ qd|j||	||dœŽ qd| |¡\}}|�rlt|| dd¡|ƒ t|ƒ ¡ D ]\}}t|||ƒ �qxz| ¡  W n4 t�yÐ } z| t|ƒ¡ W Y d	}~n
d	}~0 0 |S )zB
        :type cmdname: str
        :type argv: list[str]
        rÍ   )r  r…   rG   r   ú=ú-Ú_z--Nr!  ú>r  )r  r<   rp   )r  r<   Úchoices)r<   ÚdefaultrJ  )Úcommand_classesrL   r,   r6   r8   r%  r&  r  r6  rè   r†   r'   Úreplacerp   r1   rJ   ÚgetrK   rI   r+  rH   r1  ÚsetattrÚvarsrÓ   rD   r   rg   r-   )r>   r9  r$  Úcmdclassr:  r'  rG   ÚlongÚshortr<   rE  rK  ÚstrsrJ  rË   r8  ÚkeyÚvalueÚerrr   r   r   r7  µ  sH    
þ
$z'CommandLineInterface._configure_command)N)r   r   r   r"   r  ÚVERSIONr±   r6  rM   r�   rì   rý   rL  rL   ri   r2  r)  r7  r   r   r   r   r  X  s$   
üü
.r  c                   C  s   t ƒ  tj¡S r%   )r  ri   r#  r$  r   r   r   r   Úmainæ  s    rY  c                 C  s   t jdtdd� t| |ƒS )Nz:parse_mapping is deprecated, use parse_mapping_cfg insteadé   )Ú
stacklevel)ÚwarningsÚwarnÚDeprecationWarningrç   )ré   rÉ   r   r   r   Úparse_mappingê  s    ýr_  c           
      C  sÈ   i }g }i }t ƒ }t|jƒ|_| | |¡ | ¡ D ]V}|dkrNt| |¡ƒ}q2dd„ | dd¡D ƒ\}}| ||f¡ t| |¡ƒ||< q2|rÀt	|ƒD ](\}	\}}||v r²|| }||f||	< q–||fS )z°Parse an extraction method mapping from a file-like object.

    :param fileobj: a readable file-like object containing the configuration
                    text to parse
    Ú
extractorsc                 s  s   | ]}|  ¡ V  qd S r%   r&   )r(   Úpartr   r   r   r*     r+   z$parse_mapping_cfg.<locals>.<genexpr>ú:rB   )
r   r   Ú	_sectionsÚ	read_fileÚsectionsrÂ   rÓ   r$   rp   rv   )
ré   rÉ   r`  rÝ   rÞ   r'  ÚsectionrÊ   rë   r   r   r   r   rç   ó  s$    rç   ú	(unknown)rã   rÂ   )Úconfigc                C  sà  i }g }i }|   di ¡}t|tƒs8t|› dt|ƒ›�ƒ‚| ¡ D ]H\}}t|tƒsdt|› d|›�ƒ‚t|tƒs€t|› d|›�ƒ‚|||< q@d| v r t|› d�ƒ‚|   dg ¡}t|tƒsÌt|› dt|ƒ›�ƒ‚t|ƒD �] \}	}
t|
tƒ�st|› d	|	› d
t|
ƒ›�ƒ‚|
 	¡ }
|
 
dd ¡}t|tƒ�s>t|› d	|	› d|›�ƒ‚|  ||¡}|
 
dd ¡}t|ttfƒ�s~t|› d	|	› d|›�ƒ‚t|tƒ�s�|g}|D ]@}t|tƒ�s¼t|› d	|	› d|›�ƒ‚| ||f¡ |
||< �q”qÔ||fS )Nr`  z): extractors: Expected a dictionary, got z6: extractors: Extraction method must be a string, got z;: extractors: Callable specification must be a string, got rê   z8: 'mapping' is not a valid key, did you mean 'mappings'?rÜ   z!: mappings: Expected a list, got z: mappings[z]: Expected a dictionary, got rÊ   z"]: 'method' must be a string, got rë   z-]: 'pattern' must be a list or a string, got z+]: 'pattern' elements must be strings, got )rN  r,   rÂ   r!   ÚtyperÓ   r-   r/   rv   r½   Úpoprp   )rh  rÉ   r`  rÝ   rÞ   Zextractors_readrÊ   Zcallable_specZmappings_readr   Úentryrë   Úpatr   r   r   Ú_parse_config_object  sH    




rm  rá   r   r-   z'Literal['standalone', 'pyproject.toml'])ré   rÉ   râ   c                 C  s<  zddl }W nN tyZ   zddl}W n. tyT } ztdƒ|‚W Y d}~n
d}~0 0 Y n0 z| | ¡}W n: |jy¤ } z t|› d|› �ƒ|‚W Y d}~n
d}~0 0 |dkrúz|d d }W n8 ttfyö } zt|› d�ƒ|‚W Y d}~n
d}~0 0 n6|d	k�r"|}d|v �r0t|› d
�ƒ‚ntd|›�ƒ‚t	||d�S )aÃ  Parse an extraction method mapping from a binary file-like object.

    .. warning: As of this version of Babel, this is a private API subject to changes.

    :param fileobj: a readable binary file-like object containing the configuration TOML to parse
    :param filename: the name of the file being parsed, for error messages
    :param style: whether the file is in the style of a `pyproject.toml` file, i.e. whether to look for `tool.babel`.
    r   Nz0tomli or tomllib is required to parse TOML filesz: Error parsing TOML file: rà   Ztoolr   z': No 'tool.babel' section found in filerá   zC: 'babel' should not be present in a stand-alone configuration filezUnknown TOML style rã   )
ÚtomllibÚImportErrorZtomliÚloadZTOMLDecodeErrorr!   Ú	TypeErrorÚKeyErrorÚ
ValueErrorrm  )ré   rÉ   râ   rn  ZieZparsed_datarö   Z
babel_datar   r   r   ræ   A  s,    &*(

ræ   z4tuple[int | None, tuple[int | tuple[int, str], ...]])r)   Úreturnc                 C  sx   g }d }|   d¡D ]X}|d dkr4t|d d… ƒ}q|d dkr\| t|d d… ƒdf¡ q| t|ƒ¡ q|t|ƒfS )Nr¼   éÿÿÿÿÚtrœ   )r$   rÀ   rp   r0   )r)   ZindsÚnumberÚxr   r   r   Ú_parse_specj  s    ry  r   zIterable[str])Ústringsc           	      C  s~   i }| D ]D}d|v r0|  d¡\}}t|ƒ\}}n|}d}d}|| |i ¡|< q| ¡ D ]"\}}t|ƒdhkrV|d ||< qV|S )a¿  Parse keywords specifications from the given list of strings.

    >>> import pprint
    >>> keywords = ['_', 'dgettext:2', 'dngettext:2,3', 'pgettext:1c,2',
    ...             'polymorphic:1', 'polymorphic:2,2t', 'polymorphic:3c,3t']
    >>> pprint.pprint(parse_keywords(keywords))
    {'_': None,
     'dgettext': (2,),
     'dngettext': (2, 3),
     'pgettext': ((1, 'c'), 2),
     'polymorphic': {None: (1,), 2: (2,), 3: ((3, 'c'),)}}

    The input keywords are in GNU Gettext style; see :doc:`cmdline` for details.

    The output is a dictionary mapping keyword names to a dictionary of specifications.
    Keys in this dictionary are numbers of arguments, where ``None`` means that all numbers
    of arguments are matched, and a number means only calls with that number of arguments
    are matched (which happens when using the "t" specifier). However, as a special
    case for backwards compatibility, if the dictionary of specifications would
    be ``{None: x}``, i.e., there is only one specification and it matches all argument
    counts, then it is collapsed into just ``x``.

    A specification is either a tuple or None. If a tuple, each element can be either a number
    ``n``, meaning that the nth argument should be extracted as a message, or the tuple
    ``(n, 'c')``, meaning that the nth argument should be extracted as context for the
    messages. A ``None`` specification is equivalent to ``(1,)``, extracting the first
    argument.
    rb  N)r$   ry  Ú
setdefaultrÓ   Úset)	rz  rž   rx   ÚfuncnameÚspec_strrw  Úspecr‘   rÏ   r   r   r   r¿   w  s    r¿   )rE  c                 C  s6   | dv rddl m} t|| ƒS tdt›d| ›�ƒ‚d S )N>   Zcheck_message_extractorsZupdate_catalogZinit_catalogZextract_messagesZcompile_catalogr   )Úsetuptools_frontendzmodule z has no attribute )Zbabel.messagesr€  rè   ÚAttributeErrorr   )rE  r€  r   r   r   Ú__getattr__§  s    
r‚  Ú__main__)N)N)N)rg  rá   )r   )Er"   Ú
__future__r   rù   r‡   r,  r%  rq   rÁ   r  r#  r  r\  Úcollectionsr   Úconfigparserr   Úior   Útypingr   r   r   r   r	   r
   r   rX  Z
babel.corer   Zbabel.messages.catalogr   r   Zbabel.messages.extractr   r   r   r   Zbabel.messages.mofiler   Zbabel.messages.pofiler   r   Z
babel.utilr   Ú	getLoggerrL   r
  r   r   r    r!   r2   r6   rM   r�   r�   rì   rý   r  rY  r_  rç   rm  ræ   ry  r¿   r‚  r   r   r   r   r   Ú<module>   sh   


*6w  !K I 
	
1  ý)0
