B
    ûgÅb›  ã               @   sx  d Z dZddlZddlZddl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
mZmZ dd„ Zdd	„ Zd6d
d„Zd7dd„Zd8dd„Zd9dd„Zd:dd„Zd;dd„Zd<dd„Zd=dd„Zd>dd„Zd?dd„Zd@dd„ZdAd d!„ZdBd"d#„ZdCd$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!e
j"ƒZ!G d0d1„ d1ej#ƒZ$G d2d3„ d3e%ƒZ&d4d5„ Z'dS )Da  
Command-line and common processing for Docutils front-end tools.

This module is provisional.
Major changes will happen with the switch from the deprecated
"optparse" module to "arparse".

Applications should use the high-level API provided by `docutils.core`.
See https://docutils.sourceforge.io/docs/api/runtime-settings.html.

Exports the following classes:

* `OptionParser`: Standard Docutils command-line processing.
  Deprecated. Will be replaced by an ArgumentParser.
* `Option`: Customized version of `optparse.Option`; validation support.
  Deprecated. Will be removed.
* `Values`: Runtime settings; objects are simple structs
  (``object.attribute``).  Supports cumulative list settings (attributes).
  Deprecated. Will be removed.
* `ConfigParser`: Standard Docutils config file processing.
  Provisional. Details will change.

Also exports the following functions:

Interface function:
   `get_default_settings()`.  New in 0.19.

Option callbacks:
   `store_multiple()`, `read_config_file()`. Deprecated.

Setting validators:
  `validate_encoding()`, `validate_encoding_error_handler()`,
  `validate_encoding_and_error_handler()`,
  `validate_boolean()`, `validate_ternary()`,
  `validate_nonnegative_int()`, `validate_threshold()`,
  `validate_colon_separated_string_list()`,
  `validate_comma_separated_list()`,
  `validate_url_trailing_slash()`,
  `validate_dependency_file()`,
  `validate_strip_class()`
  `validate_smartquotes_locales()`.

  Provisional.

Misc:
  `make_paths_absolute()`, `filter_settings_spec()`. Provisional.
ZreStructuredTexté    N)ÚSUPPRESS_HELP)ÚioÚutilsc             O   sD   x|D ]}t |j|dƒ qW x"| ¡ D ]\}}t |j||ƒ q&W dS )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Úitems)ÚoptionÚoptÚvalueÚparserÚargsÚkwargsZ	attributeÚkey© r   ú0lib/python3.7/site-packages/docutils/frontend.pyÚstore_multipleE   s    
r   c          
   C   sN   y|  |¡}W n, tk
r: } z| |¡ W dd}~X Y nX |j ||¡ dS )zQ
    Read a configuration file during option processing.  (Option callback.)
    N)Úget_config_file_settingsÚ
ValueErrorÚerrorr   Úupdate)r   r	   r
   r   Znew_settingsÚerrr   r   r   Úread_config_fileR   s
    r   c             C   s8   yt  |¡ W n$ tk
r2   td| |f ƒ‚Y nX |S )Nz$setting "%s": unknown encoding: "%s")ÚcodecsÚlookupÚLookupError)Úsettingr
   Úoption_parserÚconfig_parserÚconfig_sectionr   r   r   Úvalidate_encoding]   s    r   c             C   s4   yt  |¡ W n  tk
r.   td| ƒ‚Y nX |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_handlerg   s    r!   c             C   sn   d|krV|  d¡\}}t| d ||||ƒ |rB| || 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   ÚencodingZhandlerr   r   r   Ú#validate_encoding_and_error_handlert   s    
r&   c             C   sF   t |tƒr|S y|j| ¡  ¡  S  tk
r@   td| ƒ‚Y nX dS )z|Check/normalize boolean settings:
         True:  '1', 'on', 'yes', 'true'
         False: '0', 'off', 'no','false', ''
    zunknown boolean value: "%s"N)Ú
isinstanceÚboolÚbooleansÚstripÚlowerÚKeyErrorr   )r   r
   r   r   r   r   r   r   Úvalidate_boolean‹   s    
r-   c             C   sB   t |tƒs|dkr|S y|j| ¡  ¡  S  tk
r<   |S X dS )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    r.   c             C   s   t |ƒ}|dk rtdƒ‚|S )Nr   z(negative value; must be positive or zero)Úintr   )r   r
   r   r   r   r   r   r   Úvalidate_nonnegative_int¨   s    r0   c             C   sV   yt |ƒS  tk
rP   y|j| ¡  S  ttfk
rJ   td| ƒ‚Y nX Y nX d S )Nzunknown threshold: %r.)r/   r   Ú
thresholdsr+   r,   ÚAttributeErrorr   )r   r
   r   r   r   r   r   r   Úvalidate_threshold°   s    r3   c             C   s2   t |tƒs| d¡}n| ¡ }| | d¡¡ |S )Nr"   )r'   Úlistr#   ÚpopÚextend)r   r
   r   r   r   Úlastr   r   r   Ú$validate_colon_separated_string_list»   s
    
r8   c             C   s:   t |tƒs|g}| ¡ }dd„ | d¡D ƒ}| |¡ |S )zHCheck/normalize list arguments (split at "," and strip whitespace).
    c             S   s    g | ]}|  d ¡r|  d ¡‘qS )z 	
)r*   )Ú.0Úir   r   r   ú
<listcomp>Ð   s    z1validate_comma_separated_list.<locals>.<listcomp>ú,)r'   r4   r5   r#   r6   )r   r
   r   r   r   r7   r   r   r   r   Úvalidate_comma_separated_listÅ   s    

r=   c             C   s"   |sdS |  d¡r|S |d S d S )Nz./ú/)Úendswith)r   r
   r   r   r   r   r   r   Úvalidate_url_trailing_slashÕ   s
    
r@   c             C   s*   y
t  |¡S  tk
r$   t  d ¡S X d S )N)r   ÚDependencyListÚOSError)r   r
   r   r   r   r   r   r   Úvalidate_dependency_fileß   s    
rC   c             C   sF   t | ||||ƒ}x0|D ](}tj |¡}||krtd||f ƒ‚qW |S )Nz$Invalid class value %r (perhaps %r?))r=   ÚdocutilsZnodesZmake_idr   )r   r
   r   r   r   ÚclsZ
normalizedr   r   r   Úvalidate_strip_classè   s    
rF   c       
   
   C   sÔ   t | ||||ƒ}g }xº|D ]²}y| dd¡\}}W nF tk
rR   | |¡ wY n( tk
rx   td| dd¡ ƒ‚Y nX | ¡ }| d¡}	t|	ƒdkrž|	}n t|ƒdkr¾td| dd¡ ƒ‚| ||f¡ qW |S )z~Check/normalize a comma separated list of smart quote definitions.

    Return a list of (language-tag, quotes) string tuples.r"   é   z4Invalid value "%s". Format is "<language>:<quotes>".ÚasciiÚbackslashreplaceé   z[Invalid value "%s". Please specify 4 quotes
    (primary open/close; secondary open/close).)r=   r#   r2   Úappendr   Úencoder*   Úlen)
r   r
   r   r   r   Z	lc_quotesÚitemZlangZquotesZmultichar_quotesr   r   r   Úvalidate_smartquotes_localesö   s*    


rO   c                sf   ˆ dkrt  ¡ ‰ xP|D ]H}|| kr| | }t|tƒrH‡ fdd„|D ƒ}n|rVtˆ |ƒ}|| |< qW dS )zÉ
    Interpret filesystem path settings relative to the `base_path` given.

    Paths are values in `pathdict` whose keys are in `keys`.  Get `keys` from
    `OptionParser.relative_path_settings`.
    Nc                s   g | ]}t ˆ |ƒ‘qS r   )Úmake_one_path_absolute)r9   Úpath)Ú	base_pathr   r   r;   '  s   z'make_paths_absolute.<locals>.<listcomp>)ÚosÚgetcwdr'   r4   rP   )ZpathdictÚkeysrR   r   r
   r   )rR   r   Úmake_paths_absolute  s    




rV   c             C   s   t j t j | |¡¡S )N)rS   rQ   ÚabspathÚjoin)rR   rQ   r   r   r   rP   .  s    rP   c             O   s’   t | ƒ}x€tdt|ƒdƒD ]l}g }xV|| D ]J}dd„ |d D ƒd }||krPq,|| ¡ krl| || ¡ q,| |¡ q,W t|ƒ||< qW t|ƒS )aj  Return a copy of `settings_spec` excluding/replacing some settings.

    `settings_spec` is a tuple of configuration settings
    (cf. `docutils.SettingsSpec.settings_spec`).

    Optional positional arguments are names of to-be-excluded settings.
    Keyword arguments are option specification replacements.
    (See the html4strict writer for an example.)
    é   é   c             S   s*   g | ]"}|  d ¡r|dd…  dd¡‘qS )z--rY   Nú-Ú_)Ú
startswithÚreplace)r9   Z
opt_stringr   r   r   r;   B  s   z(filter_settings_spec.<locals>.<listcomp>rG   r   )r4   ÚrangerM   rU   rK   Útuple)Úsettings_specZexcluder^   Úsettingsr:   ZnewoptsZopt_specZopt_namer   r   r   Úfilter_settings_spec2  s    

rc   c                   s8   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Z‡  ZS )
ÚValueszÒStorage for option values.

    Updates list attributes by extension rather than by replacement.
    Works in conjunction with the `OptionParser.lists` instance attribute.

    Deprecated. Will be removed.
    c                s<   t jdtdd tƒ j||Ž t| dd ƒd kr8t ¡ | _d S )Nz@frontend.Values class will be removed in Docutils 0.21 or later.rY   )Ú
stacklevelÚrecord_dependencies)	ÚwarningsÚwarnÚDeprecationWarningÚsuperÚ__init__Úgetattrr   rA   rf   )Úselfr   r   )Ú	__class__r   r   rk   X  s
    
zValues.__init__c             C   sl   t |tƒr|j}t|ƒ}xD|j ¡ D ]6}t| |ƒr$||kr$t| |ƒ}|r$||| 7 }||= q$W |  |¡ d S )N)	r'   rd   Ú__dict__ÚdictÚlistsrU   Úhasattrrl   Z_update_loose)rm   Z
other_dictr   r   r
   r   r   r   r   a  s    


zValues.updatec          	   C   s0   t  ¡  t jdtd | j| jdS Q R X dS )z Return a shallow copy of `self`.Úignore)Úcategory)ÚdefaultsN)rg   Úcatch_warningsÚfilterwarningsri   rn   ro   )rm   r   r   r   Úcopym  s    
zValues.copyc             C   s&   t | |dƒdkrt| ||ƒ t | |ƒS )zUV.setdefault(n[,d]) -> getattr(V,n,d), also set D.n=d if n not in D or None.
        N)rl   r   )rm   ÚnameÚdefaultr   r   r   Ú
setdefaults  s    zValues.setdefault)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__rk   r   rx   r{   Ú__classcell__r   r   )rn   r   rd   O  s
   	rd   c                   s<   e Zd ZdZejjddg Z‡ fdd„Z‡ fdd„Z‡  Z	S )ÚOptionz`Add validation and override support to `optparse.Option`.

    Deprecated. Will be removed.
    Ú	validatorÚ	overridesc                s"   t jdtdd tƒ j||Ž d S )NzDThe frontend.Option class will be removed in Docutils 0.21 or later.rY   )re   )rg   rh   ri   rj   rk   )rm   r   r   )rn   r   r   rk   ƒ  s    
zOption.__init__c       	   
      sž   t ƒ  ||||¡}| j}|rš| jr†t||ƒ}y|  |||¡}W n: tk
rx } zt d|t 	|¡f ¡‚W dd}~X Y nX t
|||ƒ | jršt
|| jdƒ |S )zœ
        Call the validator function on applicable settings and
        evaluate the 'overrides' option.
        Extends `optparse.Option.process`.
        zError in option "%s":
    %sN)rj   ÚprocessÚdestr‚   rl   Ú	ExceptionÚoptparseZOptionValueErrorr   Úerror_stringr   rƒ   )	rm   r	   r
   r   r   Úresultr   Ú	new_valuer   )rn   r   r   r„   ‰  s    
$zOption.process)
r|   r}   r~   r   r‡   r   ZATTRSrk   r„   r€   r   r   )rn   r   r   {  s   r   c            8       s‚  e Zd ZdZdddgZd ¡ Zdddd	d
dœZddddddddddœ	Ze	e
jddƒp\ejp\dZdZddddgi fdddgdedœfddgdddœfd d!d"gd#d$d%d&œfd'd(d)gd#d*d%d&œfd+d,gd#dd%d&œfd-d.d/gdedœfd0d1gd2d3ifd4d5gd6ed7d8œfd9d:gd;d#d<d<d=œfd>d?gd;d#d@dAœfdBdCgd;ddDœfdEdFgddedGœfdHdIgdJddDœfdKdLgddMdedNœfdOdPgddMdœfdQdRgdedœfdSdTgddUdœfdVdWgdXdYdZed[œfd\d]gdXd^dZed[œfd_d`dageddbdceddœfdedfdggd#ddbd&œfdhdidjgd#d
dbd&œfdkdlgedmd	dcednœfdodpgd#ddmd&œfdqdrgedsd
dcednœfdtdugdedœfdvdwgddxdœfdydzgd{d|d}œfd~dgddedGœfd€dgd‚ddDœfdƒd„d…gd†ed‡œfdˆd‰gdŠed‹œfdŒddŽgd†dedœfd‘d’gdŠed‹œfd“eef d”d•gd†eedœfd–e d—geed‹œfd˜d™dšgd›dœddžœfdŸd gd|edd¡œfd¢d£gd|d¤d6ed¥œfd¦d§d¨gd©dªifd«d¬d­gd©d®ifed¯gd°d±ifed²gd°d³ifed´gd©difedµgd©difed¶gd©difed·gd©difed¸gdXd¹edºœfed»gd©diff2fZddddd¼œZd½Zd¾ejejrd¿ej p
d±e
j  ¡ dÀ e
j!f Z"dÖ‡ fdÂdÃ„	Z#dÄdÅ„ Z$e%dÆdÇ„ ƒZ&dÈdÉ„ Z'dÊdË„ Z(dÌdÍ„ Z)dÎdÏ„ Z*dÐdÑ„ Z+dÒdÓ„ Z,dÔdÕ„ Z-‡  Z.S )×ÚOptionParsera  
    Settings parser for command-line and library use.

    The `settings_spec` specification here and in other Docutils components
    are merged to build the set of command-line options and runtime settings
    for this process.

    Common settings (defined below) and component-specific settings must not
    conflict.  Short options are reserved for common settings, and components
    are restricted to using long options.

    Deprecated.
    Will be replaced by a subclass of `argparse.ArgumentParser`.
    z/etc/docutils.confz./docutils.confz~/.docutilsz(info 1 warning 2 error 3 severe 4 none 5rG   rY   rZ   rJ   é   )ÚinfoZwarningr   ZsevereZnoneTF)	Ú1ZonZyesÚtrueÚ0ZoffZnoZfalseÚ r%   NrH   rI   zGeneral Docutils Optionsz'Specify the document title as metadata.z--titlez2Include a "Generated by Docutils" credit and link.z--generatorz-gÚ
store_true)Úactionr‚   z"Do not include a generator credit.z--no-generatorZstore_falseÚ	generator)r“   r…   z2Include the date at the end of the document (UTC).z--datez-dZstore_constz%Y-%m-%dZ	datestamp)r“   Úconstr…   zInclude the time & date (UTC).z--timez-tz%Y-%m-%d %H:%M UTCz'Do not include a datestamp of any kind.z--no-datestampz&Include a "View document source" link.z--source-linkz-sz3Use <URL> for a source link; implies --source-link.z--source-urlÚmetavarz<URL>z-Do not include a "View document source" link.z--no-source-linkÚcallback)Zsource_linkZ
source_url)r“   r—   Zcallback_argsz4Link from section headers to TOC entries.  (default)z--toc-entry-backlinksZtoc_backlinksÚentry)r…   r“   r•   rz   z0Link from section headers to the top of the TOC.z--toc-top-backlinksÚtop)r…   r“   r•   z+Disable backlinks to the table of contents.z--no-toc-backlinks)r…   r“   z6Link from footnotes/citations to references. (default)z--footnote-backlinks)r“   rz   r‚   z/Disable backlinks from footnotes and citations.z--no-footnote-backlinksZfootnote_backlinksz0Enable section numbering by Docutils.  (default)z--section-numberingZsectnum_xform)r“   r…   rz   r‚   z&Disable section numbering by Docutils.z--no-section-numberingz/Remove comment elements from the document tree.z--strip-commentsz6Leave comment elements in the document tree. (default)z--leave-commentsZstrip_commentsz‹Remove all elements with classes="<class>" from the document tree. Warning: potentially dangerous; use with caution. (Multiple-use option.)z--strip-elements-with-classrK   Zstrip_elements_with_classesz<class>)r“   r…   r–   r‚   z”Remove all classes="<class>" attributes from elements in the document tree. Warning: potentially dangerous; use with caution. (Multiple-use option.)z--strip-classZstrip_classeszReport system messages at or higher than <level>: "info" or "1", "warning"/"2" (default), "error"/"3", "severe"/"4", "none"/"5"z--reportz-rZreport_levelz<level>)Úchoicesrz   r…   r–   r‚   z4Report all system messages.  (Same as "--report=1".)z	--verbosez-vz3Report no system messages.  (Same as "--report=5".)z--quietz-qzdHalt execution at system messages at or above <level>.  Levels as in --report.  Default: 4 (severe).z--haltZ
halt_level)rš   r…   rz   r–   r‚   z6Halt at the slightest problem.  Same as "--halt=info".z--strictzjEnable a non-zero exit status for non-halting system messages at or above <level>.  Default: 5 (disabled).z--exit-statusZexit_status_levelz3Enable debug-level system messages and diagnostics.z--debugz Disable debug output.  (default)z
--no-debugÚdebugz-Send the output of system messages to <file>.z
--warningsÚwarning_streamz<file>)r…   r–   z1Enable Python tracebacks when Docutils is halted.z--tracebackz%Disable Python tracebacks.  (default)z--no-tracebackÚ	tracebackzdSpecify the encoding and optionally the error handler of input text.  Default: <auto-detect>:strict.z--input-encodingz-iz<name[:handler]>)r–   r‚   zlSpecify the error handler for undecodable characters.  Choices: "strict" (default), "ignore", and "replace".z--input-encoding-error-handlerÚstrict)rz   r‚   z^Specify the text encoding and optionally the error handler for output.  Default: utf-8:strict.z--output-encodingz-ozutf-8)r–   rz   r‚   zŠSpecify error handler for unencodable output characters; "strict" (default), "ignore", "replace", "xmlcharrefreplace", "backslashreplace".z--output-encoding-error-handlerzUSpecify text encoding and optionally error handler for error output.  Default: %s:%s.z--error-encodingz-ezSSpecify the error handler for unencodable characters in error output.  Default: %s.z--error-encoding-error-handlerz<Specify the language (as BCP 47 language tag).  Default: en.z
--languagez-lZlanguage_codeZenz<name>)r…   rz   r–   z)Write output file dependencies to <file>.z--record-dependencies)r–   r‚   rz   z6Read configuration settings from <file>, if it exists.z--configÚstring)r–   Útyper“   r—   z,Show this program's version number and exit.z	--versionz-Vr“   Úversionz Show this help message and exit.z--helpz-hÚhelpz--id-prefixrz   r‘   z--auto-id-prefixú%z--dump-settingsz--dump-internalsz--dump-transformsz--dump-pseudo-xmlz--expose-internal-attributeZexpose_internals)r“   r…   r‚   z--strict-visitor)Ú_disable_configÚ_sourceÚ_destinationÚ_config_filesÚgeneralz(%%prog (Docutils %s%s, Python %s, on %s)z [%s]r   r   c          
      sÖ   i | _ g | _dg| _tjdtdd tƒ j|tdt	j
dddœ|—Ž | jsT| j| _| f|˜| _|  | j¡ | j |pxi ¡ |rÒ| jd	 sÒy|  ¡ }W n, tk
rÂ } z|  |¡ W dd}~X Y nX | j |j¡ dS )
zÓSet up OptionParser instance.

        `components` is a list of Docutils components each containing a
        ``.settings_spec`` attribute.
        `defaults` is a mapping of setting default overrides.
        rœ   ztThe frontend.OptionParser class will be replaced by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.rY   )re   NéN   )Úwidth)Zoption_classZadd_help_optionZ	formatterr¤   )rq   Úconfig_filesÚrelative_path_settingsrg   rh   ri   rj   rk   r   r‡   ZTitledHelpFormatterr¡   Úversion_templateÚ
componentsÚpopulate_from_componentsru   r   Úget_standard_config_settingsr   r   ro   )rm   r®   ru   Zread_config_filesr   r   Zconfig_settingsr   )rn   r   r   rk   …  s$    	
zOptionParser.__init__c             C   sþ   xÒ|D ]Ê}|dkrq|j }| j |j¡ x¦tdt|ƒdƒD ]’}|||d … \}}}|rrt | ||¡}|  |¡ n| }x@|D ]8\}	}
}|j|
d|	i|—Ž}| 	d¡dkr|d| j
|j< q|W |jr:| j |j¡ q:W qW x$|D ]}|rÚ|jrÚ| j |j¡ qÚW dS )ao  Collect settings specification from components.

        For each component, populate from the `SettingsSpec.settings_spec`
        structure, then from the `SettingsSpec.settings_defaults` dictionary.
        After all components have been processed, check for and populate from
        each component's `SettingsSpec.settings_default_overrides` dictionary.
        Nr   rZ   r¢   r“   rK   T)ra   r¬   r6   r_   rM   r‡   ZOptionGroupZadd_option_groupZ
add_optionÚgetrq   r…   Úsettings_defaultsru   r   Zsettings_default_overrides)rm   r®   Ú	componentra   r:   ÚtitleZdescriptionZoption_specÚgroupZ	help_textZoption_stringsr   r   r   r   r   r¯   ©  s,    


z%OptionParser.populate_from_componentsc             C   s2   dt jkrt jd  t j¡}n| j}dd„ |D ƒS )z:Return list of config files, from environment or standard.ZDOCUTILSCONFIGc             S   s    g | ]}|  ¡ rtj |¡‘qS r   )r*   rS   rQ   Ú
expanduser)r9   Úfr   r   r   r;   Ð  s    z:OptionParser.get_standard_config_files.<locals>.<listcomp>)rS   Úenvironr#   ÚpathsepÚstandard_config_files)rE   r«   r   r   r   Úget_standard_config_filesÉ  s    
z&OptionParser.get_standard_config_filesc          	   C   sP   t  ¡  t jdtd tƒ }W d Q R X x"|  ¡ D ]}| |  |¡| ¡ q2W |S )Nrs   )rt   )rg   rv   rw   ri   rd   r»   r   r   )rm   rb   Úfilenamer   r   r   r°   Ò  s    
z)OptionParser.get_standard_config_settingsc          	   C   sÌ   t ƒ }tƒ }t ¡ 0 tjdtd |  j| || ¡7  _tƒ }W dQ R X xb| j	D ]X}|s\qRxLt
|jphdƒ|jf D ]2}||kr‚qt| |¡ | |¡rt| || | ¡ qtW qRW t|j| jtj |¡ƒ |jS )zAReturns a dictionary containing appropriate config file settings.rs   )rt   Nr   )ÚConfigParserr$   rg   rv   rw   ri   r«   Úreadrd   r®   r`   Zconfig_section_dependenciesr   ÚaddÚhas_sectionr   rV   ro   r¬   rS   rQ   Údirname)rm   Zconfig_filer   Zappliedrb   r³   Úsectionr   r   r   r   Ú  s(    


z%OptionParser.get_config_file_settingsc             C   s,   |   |¡\|_|_t|j| jƒ | j|_|S )z/Store positional arguments as runtime settings.)Ú
check_argsr¥   r¦   rV   ro   r¬   r«   r§   )rm   r   r   r   r   r   Úcheck_valuesò  s    zOptionParser.check_valuesc             C   sh   d  }}|r"|  d¡}|dkr"d }|r<|  d¡}|dkr<d }|rJ|  d¡ |r`||kr`|  d¡ ||fS )Nr   r[   zMaximum 2 arguments allowed.z_Do not specify the same file for both source and destination.  It will clobber the source file.)r5   r   )rm   r   ÚsourceZdestinationr   r   r   rÃ   ù  s    



zOptionParser.check_argsc             C   s   | j  |¡ d S )N)ru   r   )rm   ru   r   r   r   Úset_defaults_from_dict
  s    z#OptionParser.set_defaults_from_dictc          	   C   s8   t  ¡  t jdtd t| jƒ}W dQ R X | j|_|S )z(Needed to get custom `Values` instances.rs   )rt   N)rg   rv   rw   ri   rd   ru   r«   r§   )rm   ru   r   r   r   Úget_default_values  s
    
zOptionParser.get_default_valuesc             C   sD   x2| j | g D ]"}x|jD ]}|j|kr|S qW qW td| ƒ‚dS )a  
        Get an option by its dest.

        If you're supplying a dest which is shared by several options,
        it is undefined which option of those is returned.

        A KeyError is raised if there is no option with the supplied
        dest.
        zNo option with dest == %r.N)Zoption_groupsZoption_listr…   r,   )rm   r…   rµ   r   r   r   r   Úget_option_by_dest  s
    

zOptionParser.get_option_by_dest)r   NF)/r|   r}   r~   r   rº   r#   Zthreshold_choicesr1   r)   rl   ÚsysÚstderrr   Z_locale_encodingZdefault_error_encodingZ$default_error_encoding_error_handlerr-   r   rF   r3   r&   r!   rC   r   r   r8   ra   r²   r   rD   Ú__version__Z__version_details__r¡   Úplatformr­   rk   r¯   Úclassmethodr»   r°   r   rÄ   rÃ   rÆ   rÇ   rÈ   r€   r   r   )rn   r   r‹      sh  
















$ 	r‹   c                   sV   e Zd ZdZddddœZdZdZd‡ fd	d
„	Zdd„ Zdd„ Z	dd„ Z
dd„ Z‡  ZS )r½   aZ  Parser for Docutils configuration files.

    See https://docutils.sourceforge.io/docs/user/config.html.

    Option key normalization includes conversion of '-' to '_'.

    Config file encoding is "utf-8". Encoding errors are reported
    and the affected file(s) skipped.

    This class is provisional and will change in future versions.
    )zpep_html writerZ
stylesheet)zpep_html writerZstylesheet_path)zpep_html writerÚtemplate)Zpep_stylesheetZpep_stylesheet_pathZpep_templatea  The "[option]" section is deprecated.
Support for old-format configuration files will be removed in Docutils 0.21 or later.  Please revise your configuration files.  See <https://docutils.sourceforge.io/docs/user/config.html>, section "Old-Format Configuration Files".zhUnable to read configuration file "%s": content not encoded as UTF-8.
Skipping "%s" configuration file.
Nc          	      sª   |d k	rt jdtdd g }t|tƒr,|g}xx|D ]p}y|tƒ j|dd7 }W n, tk
rz   tj	 
| j||f ¡ w2Y nX d| krŽ|  |¡ |d k	r2|  ||¡ q2W |S )Nzbfrontend.ConfigParser.read(): parameter "option_parser" will be removed in Docutils 0.21 or later.rY   )re   zutf-8)r%   Úoptions)rg   rh   ri   r'   Ústrrj   r¾   ÚUnicodeDecodeErrorrÉ   rÊ   ÚwriteÚnot_utf8_errorÚhandle_old_configÚvalidate_settings)rm   Ú	filenamesr   Zread_okr¼   )rn   r   r   r¾   H  s"    



zConfigParser.readc             C   s¤   t  | jt|d¡ |  d¡}|  d¡s0|  d¡ xd| ¡ D ]X\}}|| jkrp| j| \}}|  |¡sx|  |¡ nd}|}|  	||¡s:|  
|||¡ q:W |  d¡ d S )Nr   rÏ   r¨   )rg   Úwarn_explicitÚold_warningÚConfigDeprecationWarningÚget_sectionrÀ   Zadd_sectionr   Úold_settingsZ
has_optionr$   Zremove_section)rm   r¼   rÏ   r   r
   rÂ   r   r   r   r   rÔ   `  s    





zConfigParser.handle_old_configc       	      C   sî   xè|   ¡ D ]Ü}xÖ|  |¡D ]È}y| |¡}W n tk
rB   wY nX |jrÌ|  ||¡}y|j|||| |d}W nN tk
r¼ } z0td|› d|› dt 	|¡› d|› d|› 
ƒ‚W dd}~X Y nX |  
|||¡ |jr|  
||jd¡ qW q
W dS )zi
        Call the validator function and implement overrides on all applicable
        settings.
        )r   r   zError in config file "z", section "[z]":
    z	
        z = N)ZsectionsrÏ   rÈ   r,   r‚   r±   r†   r   r   rˆ   r$   rƒ   )	rm   r¼   r   rÂ   r   r   r
   rŠ   r   r   r   r   rÕ   r  s"    >zConfigParser.validate_settingsc             C   s   |  ¡  dd¡S )z
        Lowercase and transform '-' to '_'.

        So the cmdline form of option names can be used in config files.
        r[   r\   )r+   r^   )rm   Z	optionstrr   r   r   ÚoptionxformŒ  s    zConfigParser.optionxformc             C   s6   t jdtdd yt| | ƒS  tk
r0   i S X dS )zØ
        Return a given section as a dictionary.

        Return empty dictionary if the section doesn't exist.

        Deprecated. Use the configparser "Mapping Protocol Access" and
        catch KeyError.
        zNfrontend.OptionParser.get_section() will be removed in Docutils 0.21 or later.rY   )re   N)rg   rh   ri   rp   r,   )rm   rÂ   r   r   r   rÚ   ”  s    	
zConfigParser.get_section)N)r|   r}   r~   r   rÛ   rØ   rÓ   r¾   rÔ   rÕ   rÜ   rÚ   r€   r   r   )rn   r   r½   '  s   	r½   c               @   s   e Zd ZdZdS )rÙ   z3Warning for deprecated configuration file features.N)r|   r}   r~   r   r   r   r   r   rÙ   ¦  s   rÙ   c           	   G   s.   t  ¡  t jdtd t| ƒ ¡ S Q R X dS )a|  Return default runtime settings for `components`.

    Return a `frontend.Values` instance with defaults for generic Docutils
    settings and settings from the `components` (`SettingsSpec` instances).

    This corresponds to steps 1 and 2 in the `runtime settings priority`__.

    __ https://docutils.sourceforge.io/docs/api/runtime-settings.html
       #settings-priority
    rs   )rt   N)rg   rv   rw   ri   r‹   rÇ   )r®   r   r   r   Úget_default_settingsª  s    
rÝ   )NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)N)(r   Z__docformat__r   Zconfigparserr‡   r   rS   Úos.pathrÉ   rg   rD   r   r   r   r   r   r!   r&   r-   r.   r0   r3   r8   r=   r@   rC   rF   rO   rV   rP   rc   rd   r   r‹   ZSettingsSpecZRawConfigParserr½   ÚFutureWarningrÙ   rÝ   r   r   r   r   Ú<module>3   sL   













	

#
,%   
