U C^@sdZdZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl Z ddl Z ddl Z ddlmZmZmZmZddZdd Zd4d d Zd5d d Zd6ddZd7ddZd8ddZd9ddZd:ddZd;ddZdddZd?d d!Z d@d"d#Z!dAd$d%Z"d&d'Z#d(d)Z$Gd*d+d+e j%Z%Gd,d-d-e j&Z&Gd.d/d/e j'e j(Z'Gd0d1d1ej)Z*Gd2d3d3e+Z,dS)Ba Command-line and common processing for Docutils front-end tools. Exports the following classes: * `OptionParser`: Standard Docutils command-line processing. * `Option`: Customized version of `optparse.Option`; validation support. * `Values`: Runtime settings; objects are simple structs (``object.attribute``). Supports cumulative list settings (attributes). * `ConfigParser`: Standard Docutils config file processing. Also exports the following functions: * Option callbacks: `store_multiple`, `read_config_file`. * Setting validators: `validate_encoding`, `validate_encoding_error_handler`, `validate_encoding_and_error_handler`, `validate_boolean`, `validate_ternary`, `validate_threshold`, `validate_colon_separated_string_list`, `validate_comma_separated_string_list`, `validate_dependency_file`. * `make_paths_absolute`. * SettingSpec manipulation: `filter_settings_spec`. ZreStructuredTextN) SUPPRESS_HELP)locale_encoding SafeString ErrorOutput ErrorStringcOs@|D]}t|j|dqt|D]\}}t|j||q$dS)z Store multiple values in `parser.values`. (Option callback.) Store `None` for each attribute named in `args`, and store the value for each key (attribute name) in `kwargs`. N)setattrvalueslistitems)optionoptvalueparserargskwargs attributekeyr7/tmp/pip-install-6_kvzl1k/docutils/docutils/frontend.pystore_multiple/src CsNz||}Wn,tk r:}z||W5d}~XYnX|j||dS)zQ Read a configuration file during option processing. (Option callback.) N)get_config_file_settings ValueErrorerrorrupdate)r r r rZ new_settingsrrrrread_config_file;s rcCs8zt|Wn$tk r2td||fYnX|S)Nz$setting "%s": unknown encoding: "%s")codecslookup LookupErrorsettingr option_parser config_parserconfig_sectionrrrvalidate_encodingEs r#cCs4zt|Wn tk r.td|YnX|S)Nzunknown encoding error handler: "%s" (choices: "strict", "ignore", "replace", "backslashreplace", "xmlcharrefreplace", and possibly others; see documentation for the Python ``codecs`` module))r lookup_errorrrrrrvalidate_encoding_error_handlerNs r%cCsnd|krV|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%setrrr#)rr r r!r"encodinghandlerrrr#validate_encoding_and_error_handlerZs( r+cCsHt|tr|Sz|j|WStk rBtd|YnXdS)z|Check/normalize boolean settings: True: '1', 'on', 'yes', 'true' False: '0', 'off', 'no','false', '' zunknown boolean value: "%s"N) isinstanceboolbooleansstriplowerKeyErrorrrrrrvalidate_booleanps  r2cCsHt|ts|dkr|Sz|j|WStk rB|YSXdS)zCheck/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/r0r1rrrrvalidate_ternary}s r3cCst|}|dkrtd|S)Nrz(negative value; must be positive or zero)intrrrrrvalidate_nonnegative_intsr5c Cs^z t|WStk rXz|j|WYSttfk rRtd|YnXYnXdS)Nzunknown threshold: %r.)r4r thresholdsr0r1AttributeErrorrrrrrvalidate_thresholds r8cCs2t|ts|d}n|}||d|S)Nr&)r,r r'popextend)rr r r!r"lastrrr$validate_colon_separated_string_lists   r<cCs:t|ts|g}|}dd|dD}|||S)zHCheck/normalize list arguments (split at "," and strip whitespace). cSs g|]}|dr|dqS)z r/).0irrr s z1validate_comma_separated_list..,)r,r r9r'r:)rr r r!r"r;r rrrvalidate_comma_separated_lists   rBcCs"|sdS|dr|S|dSdS)Nz.//)endswithrrrrvalidate_url_trailing_slashs  rEcCs4ztj|WStk r.tjdYSXdSN)docutilsutilsDependencyListIOErrorrrrrvalidate_dependency_filesrKcCsBt|||||}|D](}tj|}||krtd||fq|S)Nz$Invalid class value %r (perhaps %r?))rBrGZnodesZmake_idr)rr r r!r"cls normalizedrrrvalidate_strip_classs rNc Cst|||||}g}|D]}z|dd\}}WnHtk rR||YqYn(tk rxtd|ddYnX|}|d} t| dkr| }n t|dkrtd|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).)rBr'r7appendrencoder/len) rr r r!r"Z lc_quotesitemlangquotesZmultichar_quotesrrrvalidate_smartquotes_localess2      rYcsbdkrt|D]H}||kr||}t|trFfdd|D}n|rTt|}|||<qdS)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)r>path base_pathrrr@sz'make_paths_absolute..)osgetcwdr,r rZ)Zpathdictkeysr]rr rr\rmake_paths_absolutes   racCstjtj||SrF)r^r[abspathjoin)r]r[rrrrZsrZcOst|}tdt|dD]l}g}||D]N}dd|dDd}||krLq(|t|krl|||q(||q(t|||<qt|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.) cSs*g|]"}|dr|ddddqS)z--rdN-_) startswithreplace)r>Z opt_stringrrrr@s z(filter_settings_spec..rOr)r rangerUr`rStuple) settings_specexcluderisettingsr?ZnewoptsZopt_specopt_namerrrfilter_settings_spec s   rpc@s(eZdZdZddZddZddZdS) Valuesz Updates list attributes by extension rather than by replacement. Works in conjunction with the `OptionParser.lists` instance attribute. cOs8tjj|f||t|dr(|jdkr4tj|_dS)Nrecord_dependencies)optparserq__init__hasattrrrrGrHrIselfrrrrrrt0s  zValues.__init__cCslt|tr|j}|}t|jD]6}t||r&||kr&t||}|r&|||7}||=q&| |dSrF) r,rq__dict__copyr listsr`rugetattr _update_loose)rw other_dictr rr rrrr7s   z Values.updatecCs|j|jdS)z Return a shallow copy of `self`.)defaults) __class__rx)rwrrrryCsz Values.copyN)__name__ __module__ __qualname____doc__rtrryrrrrrq)s rqc@s$eZdZejjddgZddZdS)Option validator overridesc Cstj|||||}|j}|r|jrt||}z||||}Wn8tk rx}ztd|t|fW5d}~XYnXt ||||j rt ||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) rsrprocessdestrr{ ExceptionOptionValueErrorrrr) rwr r rrresultr new_valuerrrrrLs"   zOption.processN)rrrrsrATTRSrrrrrrHsrc8@sxeZdZdZdddgZdZdddd d d Zd d d d d d d d d d Ze e j ddpZe pZdZ dZddddgifdddgdedfddgdddfd d!d"gd#d$d%d&fd'd(d)gd#d*d%d&fd+d,gd#dd%d&fd-d.d/gdedfd0d1gd2d3ifd4d5gd6ed7d8fd9d:gd;d#dd?gd;d#d@dAfdBdCgd;ddDfdEdFgddedGfdHdIgdJddDfdKdLgddMdedNfdOdPgddMdfdQdRgdedfdSdTgddUdfdVdWgdXdYdZed[fd\d]gdXd^dZed[fd_d`dageddbdceddfdedfdggd#ddbd&fdhdidjgd#d dbd&fdkdlgedmd dcednfdodpgd#ddmd&fdqdrgedsd dcednfdtdugdedfdvdwgddxdfdydzgd{d|d}fd~dgddedGfddgdddDfdddgdedfddgdedfdddgddedfddgdedfde efddgde edfdedgeedfdddgddddfddgd|eddfddgd|dd6edfdddgddifdddgddifedgddifedgddifedgddifedgddifedgddifedgddifedgdXdedfedgddiff2fZdddddZdZdZdejejr dejp de j de j!fZ"dddĄZ#ddƄZ$ddȄZ%ddʄZ&dd̄Z'dd΄Z(ddЄZ)dd҄Z*ddԄZ+ddքZ,dS) 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 5rOrdrerR)infowarningrZseverenoneTF) 1onyestrue0offnofalser)NrPrQzGeneral Docutils Optionsz'Specify the document title as metadata.z--titlez2Include a "Generated by Docutils" credit and link.z --generatorz-g store_true)actionrz"Do not include a generator credit.z--no-generator store_false generator)rrz2Include the date at the end of the document (UTC).z--datez-d store_constz%Y-%m-%dZ datestamp)rconstrzInclude 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 for a source link; implies --source-link.z --source-urlmetavarzz-Do not include a "View document source" link.z--no-source-linkcallback)Z source_linkZ source_url)rr callback_argsz4Link from section headers to TOC entries. (default)z--toc-entry-backlinksZ toc_backlinksentry)rrrdefaultz0Link 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-backlinksZfootnote_backlinksz0Enable section numbering by Docutils. (default)z--section-numberingZ 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-classrSZstrip_elements_with_classesz)rrrrzRemove all classes="" attributes from elements in the document tree. Warning: potentially dangerous; use with caution. (Multiple-use option.)z --strip-classZ strip_classeszReport system messages at or higher than : "info" or "1", "warning"/"2" (default), "error"/"3", "severe"/"4", "none"/"5"z--reportz-rZ 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--haltZ 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-statusZexit_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-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)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-attributeZexpose_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|f|tdtjddd||jsB|j|_t |j |_ |ft ||_ | |j ||pti|r|jdsz |}Wn0tk r}z|t|W5d}~XYnX||jdS)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)rz config_filesrsrrtrTitledHelpFormatterrversion_templater relative_path_settingsrk componentspopulate_from_componentsset_defaults_from_dictr~get_standard_config_settingsrrrrx)rwrr~Zread_config_filesrrconfig_settingsrrrrrt?s2     zOptionParser.__init__c Cs|D]}|dkrq|j}|j|jtdt|dD]}|||d\}}}|rnt|||}||n|}|D]8\} } } |j| d| i| } | ddkrvd|j | j <qv|j r6|j |j q6q|D]}|r|jr|j |jqdS)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. NrrerrrSrO)rlrr:rjrUrs OptionGroupadd_option_group add_optiongetrzrsettings_defaultsr~rZsettings_default_overrides) rwr componentrlr?title descriptionZ option_specgroup help_textoption_stringsrr rrrr_s0   z%OptionParser.populate_from_componentscsztjdtj}Wntk r0|j}YnXtjjdtjkrnz ddl}Wnt k rlddYnXfdd|DS) z:Return list of config files, from environment or standard.ZDOCUTILSCONFIGHOMErNcSs|SrFr)xrrrz8OptionParser.get_standard_config_files..csg|]}|r|qSrr=)r>fexpandrrr@sz:OptionParser.get_standard_config_files..) r^environr'pathsepr1standard_config_filesr[ expanduserpwd ImportError)rwrrrrrget_standard_config_files~s   z&OptionParser.get_standard_config_filescCs*t}|D]}||||q|SrF)rqrrr)rwrnfilenamerrrrs z)OptionParser.get_standard_config_settingscCst}||||j|jtj|}i}t}|j D]J}|sFq, section "Old-Format Configuration Files". zhUnable to read configuration file "%s": content not encoded as UTF-8. Skipping "%s" configuration file. cOs&tjj|f||g|_t|_dSrF)CPRawConfigParserrtrr_stderrrvrrrrtszConfigParser.__init__c Cst|ttfkr|g}|D]}zt|dd}Wntk rHYqYnXz0tjdkrhtj |||ntj |||Wn6t k r|j |j||f|YqYnX||j||dr|||||qdS)Nrr)rerdoptions)rstrropenrJr version_inforrreadfp read_fileUnicodeDecodeErrorrwritenot_utf8_errorcloserrS has_sectionhandle_old_configvalidate_settings)rw filenamesr rfprrrrs(      zConfigParser.readcCst|jt|d|d}|ds0|dt|D]X\}}||j krr|j |\}}||sz||nd}|}| ||s<| |||q<| ddS)Nrrr) warnings warn_explicit old_warningConfigDeprecationWarningrr add_sectionr r old_settings has_optionr(remove_section)rwrrrr rrrrrrs"        zConfigParser.handle_old_configc Cs|D]}||D]}z||}Wntk r@YqYnX|jr|||}z|j|||||d}Wn<tk r}ztd||t|||fW5d}~XYnX| ||||j r| ||j dqqdS)zi Call the validator function and implement overrides on all applicable settings. )r!r"zAError in config file "%s", section "[%s]": %s %s = %sN) sectionsrrr1rrrrrr(r) rwrr rrr r rrrrrr's8     zConfigParser.validate_settingscCs|ddS)zW Transform '-' to '_' so the cmdline form of option names can be used. rfrg)r0ri)rw optionstrrrr optionxformCszConfigParser.optionxformcCs2i}||r.||D]}|||||<q|S)zf Return a given section as a dictionary (empty if the section doesn't exist). )rrr)rwrZ section_dictr rrrrIs  zConfigParser.get_sectionN) rrrrr rrtrrrrrrrrrrs rc@seZdZdZdS)r z3Warning for deprecated configuration file features.N)rrrrrrrrr Usr )NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)N)-rZ __docformat__r^os.pathrr  configparserrrrsrrGZdocutils.utilsZdocutils.nodesZdocutils.utils.error_reportingrrrrrrr#r%r+r2r3r5r8r<rBrErKrNrYrarZrprqrrZ SettingsSpecrrDeprecationWarningr rrrrs          # ~v