File: //lib/python3.6/site-packages/docutils/__pycache__/frontend.cpython-36.pyc
3
s2�e� � @ s� d Z dZddlZddlZddlZddlZddlZddlZddl Z ddl m
Z
ddlZddlZddl
ZddlmZmZmZmZ dd� Zdd � Zd4d
d�Zd5dd
�Zd6dd�Zd7dd�Zd8dd�Zd9dd�Zd:dd�Zd;dd�Zd<dd�Zd=dd�Zd>dd�Zd?d d!�Z d@d"d#�Z!dAd$d%�Z"d&d'� Z#d(d)� Z$G d*d+� d+e j%�Z%G d,d-� d-e j&�Z&G d.d/� d/e j'ej(�Z'G d0d1� d1ej)�Z*G d2d3� d3e+�Z,dS )Ba�
Command-line and common processing for Docutils front-end tools.
Exports the following classes:
* `OptionParser`: Standard Docutils command-line processing.
* `Option`: Customized version of `optparse.Option`; validation support.
* `Values`: Runtime settings; objects are simple structs
(``object.attribute``). Supports cumulative list settings (attributes).
* `ConfigParser`: Standard Docutils config file processing.
Also exports the following functions:
* Option callbacks: `store_multiple`, `read_config_file`.
* Setting validators: `validate_encoding`,
`validate_encoding_error_handler`,
`validate_encoding_and_error_handler`,
`validate_boolean`, `validate_ternary`, `validate_threshold`,
`validate_colon_separated_string_list`,
`validate_comma_separated_string_list`,
`validate_dependency_file`.
* `make_paths_absolute`.
* SettingSpec manipulation: `filter_settings_spec`.
ZreStructuredText� N)�
SUPPRESS_HELP)�locale_encoding�
SafeString�ErrorOutput�ErrorStringc O sH x|D ]}t |j|d� qW x&t|j� �D ]\}}t |j||� q*W dS )z�
Store multiple values in `parser.values`. (Option callback.)
Store `None` for each attribute named in `args`, and store the value for
each key (attribute name) in `kwargs`.
N)�setattr�values�list�items)�option�opt�value�parser�args�kwargsZ attribute�key� r �/usr/lib/python3.6/frontend.py�store_multiple/ s
r c C sN y|j |�}W n, tk
r: } z|j|� W Y dd}~X nX |jj||� dS )zQ
Read a configuration file during option processing. (Option callback.)
N)�get_config_file_settings�
ValueError�errorr �update)r r r
r Znew_settingsr r r r �read_config_file; s
r c C s8 yt j|� W n$ tk
r2 td| |f ��Y nX |S )Nz$setting "%s": unknown encoding: "%s")�codecs�lookup�LookupError)�settingr
�
option_parser�
config_parser�config_sectionr r r �validate_encodingE s r! c C s4 yt j|� W n tk
r. td| ��Y nX |S )Nz�unknown encoding error handler: "%s" (choices: "strict", "ignore", "replace", "backslashreplace", "xmlcharrefreplace", and possibly others; see documentation for the Python ``codecs`` module))r �lookup_errorr )r r
r r r r r r �validate_encoding_error_handlerN s r# c C sn d|krV|j d�\}}t| d ||||� |rB|j|| d |� qZt|j| d |� n|}t| ||||� |S )z�
Side-effect: if an error handler is included in the value, it is inserted
into the appropriate place as if it was a separate setting/option.
�:Z_error_handler)�splitr# �setr r r! )r r
r r r �encodingZhandlerr r r �#validate_encoding_and_error_handlerZ s
r( c C sF t |t�r|S y|j|j� j� S tk
r@ td| ��Y nX dS )z|Check/normalize boolean settings:
True: '1', 'on', 'yes', 'true'
False: '0', 'off', 'no','false', ''
zunknown boolean value: "%s"N)�
isinstance�bool�booleans�strip�lower�KeyErrorr )r r
r r r r r r �validate_booleanp s
r/ c C sB t |t�s|dkr|S y|j|j� j� S tk
r< |S X dS )z�Check/normalize three-value settings:
True: '1', 'on', 'yes', 'true'
False: '0', 'off', 'no','false', ''
any other value: returned as-is.
N)r) r* r+ r, r- r. )r r
r r r r r r �validate_ternary} s r0 c C s t |�}|dk rtd��|S )Nr z(negative value; must be positive or zero)�intr )r r
r r r r r r �validate_nonnegative_int� s r2 c C sV yt |�S tk
rP y|j|j� S ttfk
rJ td| ��Y nX Y nX d S )Nzunknown threshold: %r.)r1 r �
thresholdsr- r. �AttributeErrorr )r r
r r r r r r �validate_threshold� s r5 c C s2 t |t�s|jd�}n|j� }|j|jd�� |S )Nr$ )r) r r% �pop�extend)r r
r r r �lastr r r �$validate_colon_separated_string_list� s
r9 c C s: t |t�s|g}|j� }dd� |jd�D �}|j|� |S )zHCheck/normalize list arguments (split at "," and strip whitespace).
c S s g | ]}|j d �r|j d ��qS )z
)r, )�.0�ir r r �
<listcomp>� s z1validate_comma_separated_list.<locals>.<listcomp>�,)r) r r6 r% r7 )r r
r r r r8 r
r r r �validate_comma_separated_list� s
r>