o f'ha@sdZdZddlZddlZddlZddlZddlZddlZddlmZej dkr4ddl m Z ddlm Z n ddl m Z ddlmZ ddlZddlZddlZdd lmZmZmZmZej dkr_eZd d Zd d Z d8ddZ d8ddZ d8ddZ d8ddZ d8ddZ d8ddZ d8ddZ! d8ddZ" d8ddZ# d8d d!Z$ d8d"d#Z% d8d$d%Z& d8d&d'Z'd9d(d)Z(d*d+Z)d,d-Z*Gd.d/d/ej+Z+Gd0d1d1ej,Z,Gd2d3d3ej-ej.Z-Gd4d5d5e Z Gd6d7d7e/Z0dS):au 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`. reStructuredTextN) SUPPRESS_HELPr)RawConfigParser)getcwd)getcwdu)locale_encoding SafeString ErrorOutput ErrorStringcOs<|D] }t|j|dq|D] \}}t|j||qdS)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)setattrvaluesitems)optionoptvalueparserargskwargs attributekeyr3/usr/lib/python3/dist-packages/docutils/frontend.pystore_multiple8s rc CsPz||}Wnty}z ||WYd}~nd}~ww|j||dS)zQ Read a configuration file during option processing. (Option callback.) N)get_config_file_settings ValueErrorerrorrupdate)rrrr new_settingsrrrrread_config_fileDsr cCs0zt|W|Stytd||fw)Nz$setting "%s": unknown encoding: "%s")codecslookup LookupErrorsettingr option_parser config_parserconfig_sectionrrrvalidate_encodingNs  r)cCs,zt|W|Stytd|w)Nzunknown encoding error handler: "%s" (choices: "strict", "ignore", "replace", "backslashreplace", "xmlcharrefreplace", and possibly others; see documentation for the Python ``codecs`` module))r! lookup_errorr#r$rrrvalidate_encoding_error_handlerWs  r+cCsnd|vr+|d\}}t|d|||||r!|||d|n t|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. :_error_handler)splitr+setr rr))r%rr&r'r(encodinghandlerrrr#validate_encoding_and_error_handlercs   r2cCs>t|tr|Sz |j|WStytd|w)z|Check/normalize boolean settings: True: '1', 'on', 'yes', 'true' False: '0', 'off', 'no','false', '' zunknown boolean value: "%s") isinstanceboolbooleansstriplowerKeyErrorr#r$rrrvalidate_booleanys   r9cCsBt|ts |dur |Sz |j|WSty |YSw)zCheck/normalize three-value settings: True: '1', 'on', 'yes', 'true' False: '0', 'off', 'no','false', '' any other value: returned as-is. N)r3r4r5r6r7r8r$rrrvalidate_ternarys r:cCst|}|dkr td|S)Nrz(negative value; must be positive or zero)intrr$rrrvalidate_nonnegative_intsr<c CsNzt|WSty&z |j|WYSttfy%td|ww)Nzunknown threshold: %r.)r;r thresholdsr7r8AttributeErrorr#r$rrrvalidate_thresholds   r?cCs4t|ts |d}|S|}||d|S)Nr,)r3listr.popextend)r%rr&r'r(lastrrr$validate_colon_separated_string_lists  rDcCs:t|ts|g}|}dd|dD}|||S)zHCheck/normalize list arguments (split at "," and strip whitespace). cSs g|] }|dr|dqS)z r6).0irrr s z1validate_comma_separated_list..,)r3r@rAr.rB)r%rr&r'r(rCrrrrvalidate_comma_separated_lists  rJcCs|sdS|dr |S|dS)Nz.//)endswithr$rrrvalidate_url_trailing_slashs  rMcCs.ztj|WStytjdYSwN)docutilsutilsDependencyListIOErrorr$rrrvalidate_dependency_files  rScCsBt|||||}|D]}tj|}||krtd||fq |S)Nz$Invalid class value %r (perhaps %r?))rJrOnodesmake_idr)r%rr&r'r(cls normalizedrrrvalidate_strip_classs rXc Cst|||||}g}|D]T}z |dd\}}Wnty&||Yq ty6td|ddw|}|d} t| dkrI| }nt|dkrYtd|dd|||fq |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 ":".asciibackslashreplacez[Invalid value "%s". Please specify 4 quotes (primary open/close; secondary open/close).)rJr.r>appendrencoder6len) r%rr&r'r( lc_quotesitemlangquotesmultichar_quotesrrrvalidate_smartquotes_localess2        recs`durt|D]$}||vr-||}t|tr"fdd|D}n|r)t|}|||<q dS)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`. Ncsg|]}t|qSr)make_one_path_absolute)rFpath base_pathrrrH sz'make_paths_absolute..)rr3r@rf)pathdictkeysrirrrrhrmake_paths_absolutes   rlcCstjtj||SrN)osrgabspathjoin)rirgrrrrfsrfcOst|}tdt|dD]4}g}||D]%}dd|dDd}||vr&q||vr4|||q||qt|||<q t|S)aReturn 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.) rcSs*g|]}|dr|ddddqS)z--rpN-_) startswithreplace)rF opt_stringrrrrH$sz(filter_settings_spec..rYr)r@ranger_rkr]tuple) settings_specexcludertsettingsrGnewoptsopt_specopt_namerrrfilter_settings_specs     r~c@s0eZdZdZddZddZddZdd Zd S) Valuesz Updates list attributes by extension rather than by replacement. Works in conjunction with the `OptionParser.lists` instance attribute. cOsBtjj|g|Ri|t|dr|jdurtj|_dSdS)Nrecord_dependencies)optparser__init__hasattrrrOrPrQselfrrrrrr9s   zValues.__init__cCsht|tr|j}|}|jD]}t||r,||vr,t||}|r,|||7}||=q||dSrN) r3r__dict__copylistsrkrgetattr _update_loose)r other_dictr&r%rrrrr@s   z Values.updatecCs|j|jdS)z Return a shallow copy of `self`.)defaults) __class__r)rrrrrLsz Values.copycCs&t||ddurt|||t||S)zUV.setdefault(n[,d]) -> getattr(V,n,d), also set D.n=d if n not in D or None. N)rr )rnamedefaultrrr setdefaultPs  zValues.setdefaultN)__name__ __module__ __qualname____doc__rrrrrrrrr2s  rc@s$eZdZejjddgZddZdS)Option validator overridesc Cstj|||||}|j}|rH|jr>t||}z ||||}Wnty7}z td|t|fd}~wwt ||||j rHt ||j d|S)z Call the validator function on applicable settings and evaluate the 'overrides' option. Extends `optparse.Option.process`. zError in option "%s": %sN) rrprocessdestrr ExceptionOptionValueErrorr r r) rrrrrresultr% new_valuerrrrr\s&   zOption.processN)rrrrrATTRSrrrrrrXs rc @seZdZdZgdZ dZ dddddd Z d d d d d d d d d d Z e e j d dp0e p0dZ dZddgddgifdddgdedfddgdddfddd gd!d"d#d$fd%d&d'gd!d(d#d$fd)d*gd!dd#d$fd+d,d-gdedfd.d/gd0d1ifd2d3gd4ed5d6fd7d8gd9d!d:d:d;fdd?fd@dAgd9ddBfdCdDgddedEfdFdGgdHddBfdIdJgddKdedLfdMdNgddKdfdOdPgdedfdQdRgddSdfdTdUgdVdWdXedYfdZd[gdVd\dXedYfd]d^d_gedd`daedbfdcdddegd!dd`d$fdfdgdhgd!dd`d$fdidjgedkddaedlfdmdngd!ddkd$fdodpgedqddaedlfdrdsgdedfdtdugddvdfdwdxgdydzd{fd|d}gddedEfd~dgdddBfdddgdedfddgdedfdddgddedfddgdedfdeddgde edfdedgeedfdddgddddfddgdzeddfddgdzdd4edfdddgddifdddgddifedgddifedgddifedgddifedgddifedgddifedgddifedgdVdedfedgddifRfZ dddddZ dZdZdejejr;dejp for a source link; implies --source-link.z --source-urlmetavarzz-Do not include a "View document source" link.z--no-source-linkcallback) source_link source_url)rr callback_argsz4Link from section headers to TOC entries. (default)z--toc-entry-backlinks toc_backlinksentry)rrrrz0Link from section headers to the top of the TOC.z--toc-top-backlinkstop)rrrz+Disable backlinks to the table of contents.z--no-toc-backlinks)rrz6Link from footnotes/citations to references. (default)z--footnote-backlinks)rrrz/Disable backlinks from footnotes and citations.z--no-footnote-backlinksfootnote_backlinksz0Enable section numbering by Docutils. (default)z--section-numbering sectnum_xform)rrrrz&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-commentsstrip_commentszRemove all elements with classes="" from the document tree. Warning: potentially dangerous; use with caution. (Multiple-use option.)z--strip-elements-with-classr]strip_elements_with_classesz)rrrrzRemove all classes="" attributes from elements in the document tree. Warning: potentially dangerous; use with caution. (Multiple-use option.)z --strip-class strip_classeszReport system messages at or higher than : "info" or "1", "warning"/"2" (default), "error"/"3", "severe"/"4", "none"/"5"z--reportz-r report_levelz)choicesrrrrz4Report 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 . Levels as in --report. Default: 4 (severe).z--halt halt_level)rrrrrz6Halt at the slightest problem. Same as "--halt=info".z--strictzjEnable a non-zero exit status for non-halting system messages at or above . Default: 5 (disabled).z --exit-statusexit_status_levelz3Enable debug-level system messages and diagnostics.z--debugz Disable debug output. (default)z --no-debugdebugz-Send the output of system messages to .z --warningswarning_streamz)rrz1Enable 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: :strict.z--input-encodingz-iz)rrzlSpecify the error handler for undecodable characters. Choices: "strict" (default), "ignore", and "replace".z--input-encoding-error-handlerstrict)rrz^Specify the text encoding and optionally the error handler for output. Default: UTF-8:strict.z--output-encodingz-outf-8)rrrzSpecify error handler for unencodable output characters; "strict" (default), "ignore", "replace", "xmlcharrefreplace", "backslashreplace".z--output-encoding-error-handlerz}Specify text encoding and error handler for error output. Default text encoding: system encoding. Default error handler: %s.z--error-encodingz-ezSSpecify the error handler for unencodable characters in error output. Default: %s.z--error-encoding-error-handlerz)rrrz)Write output file dependencies to .z--record-dependencies)rrrz6Read configuration settings from , if it exists.z--configstring)rtyperrz,Show this program's version number and exit.z --versionz-Vrversionz Show this help message and exit.z--helpz-hhelpz --id-prefixrrz--auto-id-prefixidz--dump-settingsz--dump-internalsz--dump-transformsz--dump-pseudo-xmlz--expose-internal-attributeexpose_internals)rrrz--strict-visitor)_disable_config_source _destination _config_files)rgeneralz(%%prog (Docutils %s%s, Python %s, on %s)z [%s]rrc Osi|_ g|_ tjj|g|Rtdtjddd||js$|j|_t |j |_ |ft ||_ | |j ||p=i|rn|jdspz|}Wntye}z |t|WYd}~nd}~ww||jdSdSdS)z `components` is a list of Docutils components each containing a ``.settings_spec`` attribute. `defaults` is a mapping of setting default overrides. NN)width) option_classadd_help_option formatterr)r config_filesrrrrTitledHelpFormatterrversion_templater@relative_path_settingsrw componentspopulate_from_componentsset_defaults_from_dictrget_standard_config_settingsrrr r)rrrread_config_filesrrconfig_settingsrrrrrOs:    zOptionParser.__init__c Cs|D]a}|dur q|j}|j|jtdt|dD]G}|||d\}}}|r7t|||}||n|}|D]\} } } |j| d| i| } | ddkrWd|j | j <q;|j rb|j |j qq|D]}|rt|jrt|j |jqfdS)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. Nrrrrr]T)rxrrBrvr_r OptionGroupadd_option_group add_optiongetrrsettings_defaultsrrsettings_default_overrides) rr componentrxrGtitle description option_specgroup help_textoption_stringsrrrrrros:    z%OptionParser.populate_from_componentscs|z tjdtj}Wn ty|j}Ynwtjjdtjvr5zddl}Wn t y4ddYnwfdd|DS) z:Return list of config files, from environment or standard.DOCUTILSCONFIGHOMErNcSs|SrNr)xrrrsz8OptionParser.get_standard_config_files..csg|] }|r|qSrrE)rFfexpandrrrHsz:OptionParser.get_standard_config_files..) rmenvironr.pathsepr8standard_config_filesrg expanduserpwd ImportError)rrrrrrget_standard_config_filess      z&OptionParser.get_standard_config_filescCs*t}|D] }||||q|SrN)rrrr)rrzfilenamerrrrs z)OptionParser.get_standard_config_settingscCst}||||j|jtj|}i}t}|j D]%}|s#qt |j p(d|j fD]}||vr5q.d||<| |||q.qt|j|j||jS)zAReturns a dictionary containing appropriate config file settings.rrY) ConfigParserreadrrB_filesrmrgdirnamerrrwconfig_section_dependenciesr(r get_sectionrlrr)r config_filerriappliedrzrsectionrrrrs*     z%OptionParser.get_config_file_settingscCs,||\|_|_t|j|j|j|_|S)z/Store positional arguments as runtime settings.) check_argsrrrlrrrr)rrrrrr check_valuesszOptionParser.check_valuescCshd}}|r|d}|dkrd}|r|d}|dkrd}|r%|d|r0||kr0|d||fS)NrrqzMaximum 2 arguments allowed.z_Do not specify the same file for both source and destination. It will clobber the source file.)rAr)rrsource destinationrrrr s     zOptionParser.check_argscCs|j|dSrN)rrrrrrrrsz#OptionParser.set_defaults_from_dictcCst|j}|j|_|S)z(Needed to get custom `Values` instances.)rrrrrrrrget_default_valuess zOptionParser.get_default_valuescCs@|j|gD]}|jD] }|j|kr|Sq qtd|)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. zNo option with dest == %r.) option_groups option_listrr8)rrrrrrrget_option_by_dests    zOptionParser.get_option_by_dest)rNN)-rrrrrr.threshold_choicesr=r5rsysstderrr default_error_encoding$default_error_encoding_error_handlerr9rrXr?r2r+rSr rrDrxrrr(rO __version____version_details__rplatformrrrrrrr r rrrrrrrrss       !$(+/258>D I L OTW] _ a cf hmqv{    !&   rc@sReZdZddddZ dZdZddZd d Zd d Zd dZ ddZ ddZ dS)r)pep_html writer stylesheet)rstylesheet_path)rtemplate)pep_stylesheetpep_stylesheet_path 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 , section "Old-Format Configuration Files". zhUnable to read configuration file "%s": content not encoded as UTF-8. Skipping "%s" configuration file. cOs,tj|g|Ri|g|_ t|_dSrN)rrrr _stderrrrrrrs zConfigParser.__init__c Cst|ttfvr |g}|D]^}z t|dd}Wn ty!Yq wztjdkr0t |||nt |||Wnt yP|j |j||f|Yq w||j||dre|||||q dS)Nrrroptions)rstrunicoder!openrRr version_inforreadfp read_fileUnicodeDecodeErrorr$writenot_utf8_errorcloserr] has_sectionhandle_old_configvalidate_settings)r filenamesr&rfprrrr s0      zConfigParser.readcCst|jt|d|d}|ds|d|D],\}}||jvr7|j|\}}||s6||nd}|}| ||sH| |||q| ddS)Nrr&r) warnings warn_explicit old_warningConfigDeprecationWarningrr1 add_sectionr old_settings has_optionr/remove_section)rrr&rrr r%rrrr2%s$        zConfigParser.handle_old_configc Cs|D]\}||D]T}z||}Wn tyYq w|jrT|||}z |j|||||d}WntyL}z td||t|||fd}~ww| ||||j r_| ||j dq qdS)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&rr8rrrrr r/r) rrr&r r%rrrrrrrr37s<     zConfigParser.validate_settingscCs|ddS)zW Transform '-' to '_' so the cmdline form of option names can be used. rqrr)r7rt)r optionstrrrr optionxformSszConfigParser.optionxformcCs2i}||r||D] }|||||<q |S)zf Return a given section as a dictionary (empty if the section doesn't exist). )r1r&r)rr  section_dictrrrrrYs  zConfigParser.get_sectionN) rrrr;r8r/rrr2r3r@rrrrrrs  rc@seZdZdZdS)r9z3Warning for deprecated configuration file features.N)rrrrrrrrr9esr9)NNrN)1r __docformat__rmos.pathrr6r!rrr* configparserrrrrrOdocutils.utilsdocutils.nodesdocutils.utils.error_reportingr r r r r'r(rr r)r+r2r9r:r<r?rDrJrMrSrXrerlrfr~rrr SettingsSpecDeprecationWarningr9rrrrst                    #&~v