File: //lib/python3.9/site-packages/babel/messages/__pycache__/frontend.cpython-39.opt-1.pyc
a
�`I� � @ s d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl Z ddl
mZ ddlmZ ddl
mZ ddlmZ ddlmZmZ dd lmZmZmZmZ dd
lmZ ddlmZ ddlmZmZm Z m!Z! dd
l"m#Z# ddl$m%Z%m&Z& ddl'm(Z( ddl)m*Z+ ddl,m-Z. ddl/m0Z0m1Z1 zddl2m3Z3 W n e4�yP ddl5m3Z3 Y n0 e�r\dndZ6d-dd�Z7G dd� de.�Z-G dd� de-�Z8G dd� de-�Z9dd� Z:G d d!� d!e-�Z;G d"d#� d#e-�Z<G d$d%� d%e=�Z>d&d'� Z?d.d(d)�Z@g fd*d+�ZAeBd,k�r e?� dS )/z�
babel.messages.frontend
~~~~~~~~~~~~~~~~~~~~~~~
Frontends for the message extraction functionality.
:copyright: (c) 2013-2021 by the Babel Team.
:license: BSD, see LICENSE for more details.
� )�print_functionN)�OrderedDict)�datetime)�getpreferredencoding)�__version__)�Locale�
localedata)�StringIO�string_types� text_type�PY2)�UnknownLocaleError)�Catalog)�DEFAULT_KEYWORDS�DEFAULT_MAPPING�check_and_call_extract_file�extract_from_dir)�write_mo)�read_po�write_po)�LOCALTZ)�log)�Command)�DistutilsOptionError�DistutilsSetupError)�RawConfigParserZrU�rc C sp g }t | ttf�s| g} | D ]N}|du r*qt |ttf�rL|�t||d�� q|�dd� t|��|�D �� q|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 qd S �N��strip)�.0�s� r$ �;/usr/lib/python3.9/site-packages/babel/messages/frontend.py� <genexpr>S � z listify_value.<locals>.<genexpr>)�
isinstance�list�tuple�extend�
listify_valuer r )�argr �out�valr$ r$ r% r, . s r, c @ s. e Zd ZdZdZdZi Zi ZeZ ddd�Z
dS )r Nr$ c C s0 || _ | �� d | _d| _d | _d| _d| _d S )NFr )�distribution�initialize_optionsZ_dry_run�verbose�force�helpZ finalized)�self�distr$ r$ r% �__init__v s zCommand.__init__)N)�__name__�
__module__�__qualname__�as_args�multiple_value_options�boolean_options�option_aliases�option_choices�
distutils_logr r7 r$ r$ r$ r% r X s r c @ sD e Zd ZdZdZg d�ZddgZdd� Zdd � Zd
d� Z dd
� Z
dS )�compile_cataloga� Catalog compilation 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 compile_catalog
setup(
...
cmdclass = {'compile_catalog': compile_catalog}
)
.. versionadded:: 0.9
z+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�zinput-file=�izname 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�fzalso include fuzzy translations)�
statisticsNz#print statistics about translationsrM rO c C s. d| _ d | _d | _d | _d | _d| _d| _d S �N�messagesF)�domain� directory�
input_file�output_file�locale� use_fuzzyrO �r5 r$ r$ r% r1 � s z"compile_catalog.initialize_optionsc C s8 t | j�| _| js | js td��| js4| js4td��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)r, rR rT rS r rU rX r$ r$ r% �finalize_options� s
z compile_catalog.finalize_optionsc C sT d}| j D ](}| �|��� D ]\}}|t|�7 }qq
|rH| j�d| � |rPdS dS )Nr z%d errors encountered.� )rR �_run_domain�items�lenr �error)r5 Zn_errorsrR �catalog�errorsr$ r$ r% �run� s
zcompile_catalog.runc
C s� g }g }| j s�| jr\|�| jtj�| j| jd|d �f� |�tj�| j| jd|d �� nbt�| j�D ]T}tj�| j|d|d �}tj�|�rh|�||f� |�tj�| j|d|d �� qhnF|�| j| j f� | j r�|�| j � n |�tj�| j| jd|d �� |�st
d��i }t|�D �]h\}\}}|| }t|d��} t
| |�}
W d � n1 �sb0 Y | j�r�d}t|
�dd � D ]}|j�r�|d7 }�q�d}
t|
��r�|d t|
� }
| j�d |t|
�|
|� |
j�r�| j�s�| j�d
|� �q t|
�� � ||
<