B
    ü‹dÌ‘  ã               @   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mZ ej	dkrhddl
mZ ddlmZ nddlm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 ej	dkr¾eZd
d„ Zd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&dDd&d'„Z'dEd(d)„Z(d*d+„ Z)d,d-„ Z*G d.d/„ d/ej+ƒZ+G d0d1„ d1ej,ƒZ,G d2d3„ d3ej-ej.ƒZ-G d4d5„ d5eƒZG d6d7„ d7e/ƒZ0dS )Fau  
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_list`,
  `validate_comma_separated_list`,
  `validate_dependency_file`.
* `make_paths_absolute`.
* SettingSpec manipulation: `filter_settings_spec`.
ÚreStructuredTexté    N)ÚSUPPRESS_HELP)é   r   )ÚRawConfigParser)Úgetcwd)Úgetcwdu)Úlocale_encodingÚ
SafeStringÚErrorOutputÚErrorStringc             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ÚkwargsÚ	attributeÚkey© r   ú^/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/docutils/frontend.pyÚstore_multiple8   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_fileD   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_encodingN   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_handlerW   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%   ÚencodingÚhandlerr   r   r   Ú#validate_encoding_and_error_handlerc   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_booleany   s    
r5   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/   r0   r1   r2   r3   r4   )r"   r   r#   r$   r%   r   r   r   Úvalidate_ternary†   s    r6   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    r8   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.)r7   r   Ú
thresholdsr3   r4   ÚAttributeErrorr!   )r"   r   r#   r$   r%   r   r   r   Úvalidate_threshold›   s    r;   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
    
r@   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 	
)r2   )Ú.0Úir   r   r   ú
<listcomp>¹   s    z1validate_comma_separated_list.<locals>.<listcomp>ú,)r/   r<   r=   r*   r>   )r"   r   r#   r$   r%   r?   r   r   r   r   Úvalidate_comma_separated_list®   s    

rE   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
    
rH   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    rM   c             C   sF   t | ||||ƒ}x0|D ](}tj |¡}||krtd||f ƒ‚qW |S )Nz$Invalid class value %r (perhaps %r?))rE   rI   ZnodesZmake_idr   )r"   r   r#   r$   r%   ÚclsÚ
normalizedr   r   r   Úvalidate_strip_classÍ   s    
rP   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).)rE   r*   r:   Úappendr   Úencoder2   Úlen)
r"   r   r#   r$   r%   Z	lc_quotesÚitemÚlangÚquotesZmultichar_quotesr   r   r   Úvalidate_smartquotes_localesÚ   s*    


r[   c                sd   ˆ dkrt ƒ ‰ xP|D ]H}|| kr| | }t|tƒrF‡ fdd„|D ƒ}n|rTtˆ |ƒ}|| |< 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)rA   Úpath)Ú	base_pathr   r   rC     s   z'make_paths_absolute.<locals>.<listcomp>)r   r/   r<   r\   )ZpathdictÚkeysr^   r   r   r   )r^   r   Úmake_paths_absoluteý   s    




r`   c             C   s   t j t j | |¡¡S )N)Úosr]   ÚabspathÚjoin)r^   r]   r   r   r   r\     s    r\   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 )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.)
    é   r   c             S   s*   g | ]"}|  d ¡r|dd…  dd¡‘qS )z--rd   Nú-Ú_)Ú
startswithÚreplace)rA   Z
opt_stringr   r   r   rC   $  s   z(filter_settings_spec.<locals>.<listcomp>rQ   r   )r<   ÚrangerW   r_   rU   Útuple)Úsettings_specÚexcluderh   ÚsettingsrB   ZnewoptsZopt_specÚopt_namer   r   r   Úfilter_settings_spec  s    

ro   c               @   s0   e Zd ZdZd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)Úoptparserp   Ú__init__Úhasattrrq   rI   rJ   rK   )Úselfr   r   r   r   r   rs   9  s    

zValues.__init__c             C   sl   t |tƒr|j}| ¡ }xD|j ¡ D ]6}t| |ƒr$||kr$t| |ƒ}|r$||| 7 }||= q$W |  |¡ d S )N)	r/   rp   Ú__dict__ÚcopyÚlistsr_   rt   ÚgetattrÚ_update_loose)ru   Ú
other_dictr#   r"   r   r   r   r   r   @  s    


zValues.updatec             C   s   | j | jdS )z Return a shallow copy of `self`.)Údefaults)Ú	__class__rv   )ru   r   r   r   rw   L  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)ry   r   )ru   ÚnameÚdefaultr   r   r   Ú
setdefaultP  s    zValues.setdefaultN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rs   r   rw   r€   r   r   r   r   rp   2  s
   rp   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)rr   r…   ÚprocessÚdestr†   ry   Ú	ExceptionÚOptionValueErrorr   r   r‡   )	ru   r   r   r   r   Úresultr"   Ú	new_valuer   r   r   r   rˆ   \  s    
"zOption.processN)r   r‚   rƒ   rr   r…   ÚATTRSrˆ   r   r   r   r   r…   X  s   r…   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 5rQ   rd   r   rT   é   )ÚinfoÚwarningr   ZsevereÚnoneTF)	Ú1ÚonÚyesÚtrueÚ0ÚoffÚnoÚfalseÚ r,   NrR   rS   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-generatorÚstore_falseÚ	generator)rž   r‰   z2Include the date at the end of the document (UTC).z--datez-dÚ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)Úsource_linkÚ
source_url)rž   r¤   Úcallback_argsz4Link from section headers to TOC entries.  (default)z--toc-entry-backlinksZtoc_backlinksÚentry)r‰   rž   r¢   r   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ž   r   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‰   r   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-commentsÚ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-classrU   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>)Úchoicesr   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‰   r   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Ú	tracebackziSpecify the encoding and optionally the error handler of input text.  Default: <locale-dependent>: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)r   r†   z^Specify the text encoding and optionally the error handler for output.  Default: UTF-8:strict.z--output-encodingz-ozutf-8)r£   r   r†   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_codeÚenz<name>)r‰   r   r£   z)Write output file dependencies to <file>.z--record-dependencies)r£   r†   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ú%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)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)Úoption_classÚadd_help_optionÚ	formatterr¶   )rx   Úconfig_filesrr   r   rs   r…   ÚTitledHelpFormatterr³   Úversion_templater<   Úrelative_path_settingsrj   Ú
componentsÚpopulate_from_componentsÚset_defaults_from_dictr|   Úget_standard_config_settingsr   r   r	   rv   )ru   rÄ   r|   Zread_config_filesr   r   Úconfig_settingsr   r   r   r   rs   O  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ž   rU   T)rk   rÃ   r>   ri   rW   rr   ÚOptionGroupÚadd_option_groupÚ
add_optionÚgetrx   r‰   Úsettings_defaultsr|   r   Zsettings_default_overrides)ru   rÄ   Ú	componentrk   rB   ÚtitleÚdescriptionZoption_specÚgroupÚ	help_textÚoption_stringsr   r   r   r   r   rÅ   o  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>Ÿ  ó    z8OptionParser.get_standard_config_files.<locals>.<lambda>c                s   g | ]}|  ¡ rˆ |ƒ‘qS r   )r2   )rA   Úf)Úexpandr   r   rC      s    z:OptionParser.get_standard_config_files.<locals>.<listcomp>)
ra   Úenvironr*   Úpathsepr4   Ústandard_config_filesr]   Ú
expanduserÚpwdÚImportError)ru   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)rp   rà   r   r   )ru   rm   Úfilenamer   r   r   rÇ   ¢  s    z)OptionParser.get_standard_config_settingsc             C   sª   t ƒ }| || ¡ | j |j¡ tj |¡}tƒ }t	ƒ }xZ| j
D ]P}|sJq@xDt|jpVdƒ|jf D ]*}||krpqb| |¡ | | |¡| ¡ qbW q@W t|j| j|ƒ |jS )zAReturns a dictionary containing appropriate config file settings.r   )ÚConfigParserÚreadrÀ   r>   Ú_filesra   r]   Údirnamer+   rp   rÄ   rj   Zconfig_section_dependenciesr%   Úaddr   Úget_sectionr`   rv   rÃ   )ru   Úconfig_filer   r^   Zappliedrm   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¸   r`   rv   rÃ   rÀ   r¹   )ru   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   re   zMaximum 2 arguments allowed.z_Do not specify the same file for both source and destination.  It will clobber the source file.)r=   r   )ru   r   ÚsourceÚdestinationr   r   r   rê   Ä  s    



zOptionParser.check_argsc             C   s   | j  |¡ d S )N)r|   r   )ru   r|   r   r   r   rÆ   Õ  s    z#OptionParser.set_defaults_from_dictc             C   s   t | jƒ}| j|_|S )z(Needed to get custom `Values` instances.)rp   r|   rÀ   r¹   )ru   r|   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)Úoption_groupsÚoption_listr‰   r4   )ru   r‰   rÑ   r   r   r   r   Úget_option_by_destÞ  s
    

zOptionParser.get_option_by_dest)r   NN)-r   r‚   rƒ   r„   rÜ   r*   Zthreshold_choicesr9   r1   ry   ÚsysÚstderrr   Zdefault_error_encodingZ$default_error_encoding_error_handlerr5   r   rP   r;   r.   r(   rM   r   r   r@   rk   rÍ   rÃ   r%   rI   Ú__version__Z__version_details__r³   ÚplatformrÂ   rs   rÅ   rà   rÇ   r   rë   rê   rÆ   rî   rñ   r   r   r   r   r   s  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 writerÚ
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 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| f|ž|Ž g | _tƒ | _d S )N)r   rs   rä   r
   Ú_stderr)ru   r   r   r   r   r   rs     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 y,tjdk rft 	| ||¡ nt 
| ||¡ 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²   ÚstrÚunicoder   ÚopenrL   rò   Úversion_infor   ÚreadfpÚ	read_fileÚUnicodeDecodeErrorrø   ÚwriteÚnot_utf8_errorÚcloserä   rU   Úhas_sectionÚhandle_old_configÚvalidate_settings)ru   Ú	filenamesr#   rá   Úfpr   r   r   rã     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º   )ÚwarningsÚwarn_explicitÚold_warningÚConfigDeprecationWarningrç   r  Úadd_sectionr   Úold_settingsÚ
has_optionr+   Úremove_section)ru   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)Úsectionsrú   rñ   r4   r†   rÌ   rŠ   r   r   r+   r‡   )	ru   rá   r#   ré   r"   r   r   r   r   r   r   r   r  7  s(    
zConfigParser.validate_settingsc             C   s   |  ¡  dd¡S )zW
        Transform '-' to '_' so the cmdline form of option names can be used.
        re   rf   )r3   rh   )ru   Ú	optionstrr   r   r   ÚoptionxformS  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Ì   )ru   ré   Zsection_dictr   r   r   r   rç   Y  s
    
zConfigParser.get_sectionN)r   r‚   rƒ   r  r  r  rs   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)r   r‚   rƒ   r„   r   r   r   r   r  e  s   r  )NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)N)1r„   Ú__docformat__ra   Úos.pathrò   r
  r   rr   r   rþ   Úconfigparserr   r   râ   r   rI   Zdocutils.utilsZdocutils.nodesZdocutils.utils.error_reportingr   r	   r
   r   rû   rü   r   r   r&   r(   r.   r5   r6   r8   r;   r@   rE   rH   rM   rP   r[   r`   r\   ro   rp   r…   r   ZSettingsSpecÚFutureWarningr  r   r   r   r   Ú<module>   sX   


	







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