B
    á<[  ã               @   sˆ  d Z d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ZddlZddlZddlmZmZmZmZ dd„ Zdd	„ Zd4d
d„Zd5d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"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,dS )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`.
ZreStructuredTexté    N)ÚSUPPRESS_HELP)Úlocale_encodingÚ
SafeStringÚErrorOutputÚErrorStringc             O   sH   x|D ]}t |j|dƒ qW x&t| ¡ ƒ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ÚlistÚitems)ÚoptionÚoptÚvalueÚparserÚargsÚkwargsZ	attributeÚkey© r   ú0lib/python3.7/site-packages/docutils/frontend.pyÚstore_multiple/   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_settingsr   r   r   r   Úread_config_file;   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_encodingE   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_handlerN   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_handlerZ   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_booleanp   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    r0   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    r2   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.)r1   r   Ú
thresholdsr-   r.   ÚAttributeErrorr   )r   r   r   r   r    r   r   r   Úvalidate_threshold’   s    r5   c             C   s2   t |tƒs| d¡}n| ¡ }| | d¡¡ |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}| ¡ }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)   r	   r6   r%   r7   )r   r   r   r   r    r8   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
    
rA   c             C   s.   yt j |¡S  tk
r(   t j d ¡S X d S )N)ÚdocutilsÚutilsÚDependencyListÚIOError)r   r   r   r   r    r   r   r   Úvalidate_dependency_file½   s    rF   c             C   sF   t | ||||ƒ}x0|D ](}tj |¡}||krtd||f ƒ‚qW |S )Nz$Invalid class value %r (perhaps %r?))r>   rB   ZnodesZmake_idr   )r   r   r   r   r    ÚclsZ
normalizedr   r   r   Úvalidate_strip_classÄ   s    
rH   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%   r4   Úappendr   Úencoder,   Úlen)
r   r   r   r   r    Z	lc_quotesÚitemZlangZquotesZmultichar_quotesr   r   r   Úvalidate_smartquotes_localesÑ   s*    


rQ   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)r:   Úpath)Ú	base_pathr   r   r<     s   z'make_paths_absolute.<locals>.<listcomp>)ÚosÚgetcwdr)   r	   rR   )ZpathdictÚkeysrT   r   r   r   )rT   r   Úmake_paths_absoluteô   s    




rX   c             C   s   t j t j | |¡¡S )N)rU   rS   ÚabspathÚjoin)rT   rS   r   r   r   rR     s    rR   c             O   s–   t | ƒ}x„tdt|ƒdƒD ]p}g }xZ|| D ]N}dd„ |d D ƒd }||krPq,|t | ¡ ƒkrp| || ¡ q,| |¡ q,W t|ƒ||< qW t|ƒS )a  Return a copy of `settings_spec` excluding/replacing some settings.

    `settings_spec` is a tuple of configuration settings with a structure
    described for 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--r[   Nú-Ú_)Ú
startswithÚreplace)r:   Z
opt_stringr   r   r   r<     s   z(filter_settings_spec.<locals>.<listcomp>rI   r   )r	   ÚrangerO   rW   rM   Útuple)Úsettings_specZexcluder`   Úsettingsr;   ZnewoptsZopt_specZopt_namer   r   r   Úfilter_settings_spec  s    

re   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚValuesz•
    Updates list attributes by extension rather than by replacement.
    Works in conjunction with the `OptionParser.lists` instance attribute.
    c             O   s8   t jj| f|ž|Ž t| dƒr(| jd kr4tj ¡ | _d S )NÚrecord_dependencies)Úoptparserf   Ú__init__Úhasattrrg   rB   rC   rD   )Úselfr   r   r   r   r   ri   0  s    

zValues.__init__c             C   sp   t |tƒr|j}| ¡ }xHt|j ¡ ƒD ]6}t| |ƒr(||kr(t| |ƒ}|r(||| 7 }||= q(W |  	|¡ d S )N)
r)   rf   Ú__dict__Úcopyr	   ÚlistsrW   rj   ÚgetattrZ_update_loose)rk   Z
other_dictr   r   r   r   r   r   r   7  s    


zValues.updatec             C   s   | j | jdS )z Return a shallow copy of `self`.)Údefaults)Ú	__class__rl   )rk   r   r   r   rm   C  s    zValues.copyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ri   r   rm   r   r   r   r   rf   )  s   rf   c               @   s$   e Zd Zejjddg Zdd„ ZdS )ÚOptionÚ	validatorÚ	overridesc       	   
   C   sž   t j | ||||¡}| j}|rš| jr†t||ƒ}y|  |||¡}W n8 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)rh   rv   ÚprocessÚdestrw   ro   Ú	ExceptionZOptionValueErrorr   r   rx   )	rk   r   r   r   r   Úresultr   Ú	new_valuer   r   r   r   ry   L  s    
"zOption.processN)rr   rs   rt   rh   rv   ZATTRSry   r   r   r   r   rv   H  s   rv   c            8   @   sx  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ƒpZepZd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¾Zd¿ejejr
dÀej pd±e
j  ¡ dÁ e
j!f Z"d×dÃdÄ„Z#dÅdÆ„ Z$dÇdÈ„ Z%dÉdÊ„ Z&dËdÌ„ Z'dÍdÎ„ Z(dÏdÐ„ Z)dÑdÒ„ Z*dÓdÔ„ Z+dÕdÖ„ Z,dS )ØÚOptionParsera¢  
    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 restrict to using long options.
    z/etc/docutils.confz./docutils.confz~/.docutilsz(info 1 warning 2 error 3 severe 4 none 5rI   r[   r\   rL   é   )ÚinfoZwarningr   ZsevereZnoneTF)	Ú1ZonZyesÚtrueÚ0ZoffZnoZfalseÚ r'   NrJ   rK   zGeneral Docutils Optionsz'Specify the document title as metadata.z--titlez2Include a "Generated by Docutils" credit and link.z--generatorz-gÚ
store_true)Úactionrw   z"Do not include a generator credit.z--no-generatorZstore_falseÚ	generator)r†   rz   z2Include the date at the end of the document (UTC).z--datez-dZstore_constz%Y-%m-%dZ	datestamp)r†   Úconstrz   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)rz   r†   rˆ   Údefaultz0Link from section headers to the top of the TOC.z--toc-top-backlinksÚtop)rz   r†   rˆ   z+Disable backlinks to the table of contents.z--no-toc-backlinks)rz   r†   z6Link from footnotes/citations to references. (default)z--footnote-backlinks)r†   rŒ   rw   z/Disable backlinks from footnotes and citations.z--no-footnote-backlinksZfootnote_backlinksz0Enable section numbering by Docutils.  (default)z--section-numberingZsectnum_xform)r†   rz   rŒ   rw   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-classrM   Zstrip_elements_with_classesz<class>)r†   rz   r‰   rw   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>)ÚchoicesrŒ   rz   r‰   rw   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Ž   rz   rŒ   r‰   rw   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>)rz   r‰   z1Enable Python tracebacks when Docutils is halted.z--tracebackz%Disable Python tracebacks.  (default)z--no-tracebackÚ	tracebackziSpecify the encoding and optionally the error handler of input text.  Default: <locale-dependent>:strict.z--input-encodingz-iz<name[:handler]>)r‰   rw   zlSpecify the error handler for undecodable characters.  Choices: "strict" (default), "ignore", and "replace".z--input-encoding-error-handlerÚstrict)rŒ   rw   z^Specify the text encoding and optionally the error handler for output.  Default: UTF-8:strict.z--output-encodingz-ozutf-8)r‰   rŒ   rw   zŠSpecify error handler for unencodable output characters; "strict" (default), "ignore", "replace", "xmlcharrefreplace", "backslashreplace".z--output-encoding-error-handlerzJSpecify text encoding and 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>)rz   rŒ   r‰   z)Write output file dependencies to <file>.z--record-dependencies)r‰   rw   rŒ   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-prefixrŒ   r„   z--auto-id-prefixÚidz--dump-settingsz--dump-internalsz--dump-transformsz--dump-pseudo-xmlz--expose-internal-attributeZexpose_internals)r†   rz   rw   z--strict-visitor)Ú_disable_configÚ_sourceÚ_destinationÚ_config_files)r   Úgeneralz(%%prog (Docutils %s%s, Python %s, on %s)z [%s]r   r   c          
   O   sÔ   i | _ g | _tjj| f|žtdtjdddœ|—Ž | jsB| j| _t	| j
ƒ| _
| ft|ƒ | _|  | j¡ |  |pti ¡ |rÐ| jd sÐy|  ¡ }W n0 tk
rÂ } z|  t|ƒ¡ W dd}~X Y nX |  |j¡ dS )z¶
        `components` is a list of Docutils components each containing a
        ``.settings_spec`` attribute.  `defaults` is a mapping of setting
        default overrides.
        NéN   )Úwidth)Zoption_classZadd_help_optionZ	formatterr˜   )rn   Úconfig_filesrh   r~   ri   rv   ZTitledHelpFormatterr•   Úversion_templater	   Úrelative_path_settingsrb   Ú
componentsÚpopulate_from_componentsÚset_defaults_from_dictrp   Úget_standard_config_settingsr   r   r   rl   )rk   r¢   rp   Zread_config_filesr   r   Zconfig_settingsr   r   r   r   ri   ?  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 )aE  
        For each component, first 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   r\   r–   r†   rM   rI   )rc   r¡   r7   ra   rO   rh   ZOptionGroupZadd_option_groupZ
add_optionÚgetrn   rz   Úsettings_defaultsrp   r   Zsettings_default_overrides)rk   r¢   Ú	componentrc   r;   ÚtitleZdescriptionZoption_specÚgroupZ	help_textZoption_stringsr   r   r   r   r   r£   _  s,    


z%OptionParser.populate_from_componentsc                s€   yt jd  t j¡}W n tk
r0   | j}Y nX t jj‰ dt jkrnyddl}W n t	k
rl   dd„ ‰ Y nX ‡ fdd„|D ƒS )	z:Return list of config files, from environment or standard.ZDOCUTILSCONFIGÚHOMEr   Nc             S   s   | S )Nr   )Úxr   r   r   Ú<lambda>  s    z8OptionParser.get_standard_config_files.<locals>.<lambda>c                s   g | ]}|  ¡ rˆ |ƒ‘qS r   )r,   )r:   Úf)Úexpandr   r   r<     s    z:OptionParser.get_standard_config_files.<locals>.<listcomp>)
rU   Úenvironr%   Úpathsepr.   Ústandard_config_filesrS   Ú
expanduserÚpwdÚImportError)rk   rŸ   r´   r   )r¯   r   Úget_standard_config_files~  s    
z&OptionParser.get_standard_config_filesc             C   s.   t ƒ }x"|  ¡ D ]}| |  |¡| ¡ qW |S )N)rf   r¶   r   r   )rk   rd   Úfilenamer   r   r   r¥   ’  s    z)OptionParser.get_standard_config_settingsc             C   s¦   t ƒ }| || ¡ | j |j¡ tj |¡}i }tƒ }xX| j	D ]N}|sHq>xBt
|jpTdƒ|jf D ](}||krnq`d||< | | |¡| ¡ q`W q>W t|j| j|ƒ |jS )zAReturns a dictionary containing appropriate config file settings.r   rI   )ÚConfigParserÚreadrŸ   r7   Ú_filesrU   rS   Údirnamerf   r¢   rb   Zconfig_section_dependenciesr    r   Úget_sectionrX   rl   r¡   )rk   Zconfig_filer   rT   Zappliedrd   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š   rX   rl   r¡   rŸ   r›   )rk   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.)r6   r   )rk   r   ÚsourceZdestinationr   r   r   r¾   ´  s    



zOptionParser.check_argsc             C   s   | j  |¡ d S )N)rp   r   )rk   rp   r   r   r   r¤   Å  s    z#OptionParser.set_defaults_from_dictc             C   s   t | jƒ}| j|_|S )z(Needed to get custom `Values` instances.)rf   rp   rŸ   r›   )rk   rp   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_listrz   r.   )rk   rz   rª   r   r   r   r   Úget_option_by_destÎ  s
    

zOptionParser.get_option_by_dest)r   NN)-rr   rs   rt   ru   r²   r%   Zthreshold_choicesr3   r+   ro   ÚsysÚstderrr   Zdefault_error_encodingZ$default_error_encoding_error_handlerr/   r   rH   r5   r(   r#   rF   r   r   r9   rc   r§   r¡   r    rB   Ú__version__Z__version_details__r•   Úplatformr    ri   r£   r¶   r¥   r   r¿   r¾   r¤   rÁ   rÂ   r   r   r   r   r~   c  sf  

















 r~   c               @   sP   e Zd ZddddœZdZdZdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )r¸   )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 may be removed in a future Docutils release.  Please revise your
configuration files.  See <http://docutils.sf.net/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.
c             O   s&   t jj| f|ž|Ž g | _tƒ | _d S )N)ÚCPÚRawConfigParserri   rº   r   Ú_stderr)rk   r   r   r   r   r   ri   ô  s    zConfigParser.__init__c          	   C   sì   t |ƒttfkr|g}xÐ|D ]È}yt |dd¡}W n tk
rH   wY nX y0tjdk rhtj 	| ||¡ ntj 
| ||¡ W n4 tk
r®   | j | j||f ¡ | ¡  wY nX | ¡  | j |¡ |  d¡rØ|  |¡ |  ||¡ qW d S )NÚrzutf-8)r\   r[   Úoptions)r”   Ústrr   ÚopenrE   rÃ   Úversion_inforÈ   rÉ   ZreadfpZ	read_fileÚUnicodeDecodeErrorrÊ   ÚwriteÚnot_utf8_errorÚcloserº   rM   Úhas_sectionÚhandle_old_configÚvalidate_settings)rk   Ú	filenamesr   r·   Úfpr   r   r   r¹   ý  s(    



zConfigParser.readc             C   s¨   t  | jt|d¡ |  d¡}|  d¡s0|  d¡ xht| ¡ ƒD ]X\}}|| j	krt| j	| \}}|  |¡s||  |¡ nd}|}|  
||¡s>|  |||¡ q>W |  d¡ d S )Nr   rÌ   rœ   )ÚwarningsÚwarn_explicitÚold_warningÚConfigDeprecationWarningr¼   rÔ   Zadd_sectionr	   r
   Úold_settingsZ
has_optionr&   Zremove_section)rk   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 n< tk
rª } ztd||t|ƒ||f ƒ‚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    zAError in config file "%s", section "[%s]":
    %s
        %s = %sN)ZsectionsrÌ   rÂ   r.   rw   r¦   r{   r   r   r&   rx   )	rk   r·   r   r½   r   r   r   r}   r   r   r   r   rÖ   '  s(    
zConfigParser.validate_settingsc             C   s   |  ¡  dd¡S )zW
        Transform '-' to '_' so the cmdline form of option names can be used.
        r]   r^   )r-   r`   )rk   Z	optionstrr   r   r   ÚoptionxformC  s    zConfigParser.optionxformc             C   s6   i }|   |¡r2x"|  |¡D ]}|  ||¡||< qW |S )zf
        Return a given section as a dictionary (empty if the section
        doesn't exist).
        )rÔ   rÌ   r¦   )rk   r½   Zsection_dictr   r   r   r   r¼   I  s
    
zConfigParser.get_sectionN)rr   rs   rt   rÝ   rÛ   rÒ   ri   r¹   rÕ   rÖ   rÞ   r¼   r   r   r   r   r¸   ß  s   		r¸   c               @   s   e Zd ZdZdS )rÜ   z3Warning for deprecated configuration file features.N)rr   rs   rt   ru   r   r   r   r   rÜ   U  s   rÜ   )NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)N)-ru   Z__docformat__rU   Úos.pathrÃ   rÙ   ZconfigparserrÈ   r   rh   r   rB   Zdocutils.utilsZdocutils.nodesZdocutils.utils.error_reportingr   r   r   r   r   r   r!   r#   r(   r/   r0   r2   r5   r9   r>   rA   rF   rH   rQ   rX   rR   re   rf   rv   r~   ZSettingsSpecrÉ   r¸   ÚDeprecationWarningrÜ   r   r   r   r   Ú<module>   sL   
	







	

	


"
  ~v