3 E\@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 ErrorStringcOsHx|D]}t|j|dqWx&t|jD]\}}t|j||q*WdS)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 attributekeyrk/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/docutils/docutils/frontend.pystore_multiple/s rcCsNy|j|}Wn,tk r:}z|j|WYdd}~XnX|jj||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 rc Cs8ytj|Wn$tk r2td||fYnX|S)Nz$setting "%s": unknown encoding: "%s")codecslookup LookupError)settingr option_parser config_parserconfig_sectionrrrvalidate_encodingEs r"c Cs4ytj|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_errorr)rr rr r!rrrvalidate_encoding_error_handlerNsr$cCsnd|krV|jd\}}t|d|||||rB|j||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 rr r!encodinghandlerrrr#validate_encoding_and_error_handlerZs  r*c CsFt|tr|Sy|j|jjStk r@td|YnXdS)z|Check/normalize boolean settings: True: '1', 'on', 'yes', 'true' False: '0', 'off', 'no','false', '' zunknown boolean value: "%s"N) isinstanceboolbooleansstriplowerKeyErrorr)rr rr r!rrrvalidate_booleanps  r1c CsBt|ts|dkr|Sy|j|jjStk r<|SXdS)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.r/r0)rr rr r!rrrvalidate_ternary}s r2cCst|}|dkrtd|S)Nrz(negative value; must be positive or zero)intr)rr rr r!rrrvalidate_nonnegative_intsr4cCsVyt|Stk rPy|j|jSttfk rJtd|YnXYnXdS)Nzunknown threshold: %r.)r3r thresholdsr/r0AttributeErrorr)rr rr r!rrrvalidate_thresholdsr7cCs2t|ts|jd}n|j}|j|jd|S)Nr%)r+r r&popextend)rr rr r!lastrrr$validate_colon_separated_string_lists   r;cCs:t|ts|g}|j}dd|jdD}|j||S)zHCheck/normalize list arguments (split at "," and strip whitespace). cSs g|]}|jdr|jdqS)z )r.).0irrr sz1validate_comma_separated_list..,)r+r r8r&r9)rr rr r!r:r rrrvalidate_comma_separated_lists   r@cCs"|sdS|jdr|S|dSdS)Nz.//)endswith)rr rr r!rrrvalidate_url_trailing_slashs  rCc Cs.y tjj|Stk r(tjjdSXdS)N)docutilsutilsDependencyListIOError)rr rr r!rrrvalidate_dependency_files rHcCsFt|||||}x0|D](}tjj|}||krtd||fqW|S)Nz$Invalid class value %r (perhaps %r?))r@rDZnodesZmake_idr)rr rr r!cls normalizedrrrvalidate_strip_classs  rKc Cst|||||}g}x|D]}y|jdd\}}WnFtk rR|j|wYn(tk rxtd|jddYnX|j}|jd} t| dkr| }n t|dkrtd|jdd|j||fqW|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).)r@r&r6appendrencoder.len) rr rr r!Z lc_quotesitemlangquotesZmultichar_quotesrrrvalidate_smartquotes_localess*     rVcsfdkrtjxP|D]H}||kr||}t|trHfdd|D}n|rVt|}|||<qWdS)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 rW)ZpathdictkeysrYrr r)rYrmake_paths_absolutes     r]cCstjjtjj||S)N)rZrXabspathjoin)rYrXrrrrWsrWcOst|}xtdt|dD]p}g}xZ||D]N}dd|dDd}||krPq,|t|jkrp|j||q,|j|q,Wt|||<qWt|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|]"}|jdr|ddjddqS)z--r`N-_) startswithreplace)r<Z opt_stringrrrr>sz(filter_settings_spec..rLr)r rangerRr\rPtuple) settings_specexcluderesettingsr=ZnewoptsZopt_specopt_namerrrfilter_settings_spec s  rlc@s(eZdZdZddZddZddZdS) Valuesz Updates list attributes by extension rather than by replacement. Works in conjunction with the `OptionParser.lists` instance attribute. cOs:tjj|f||t|d s*|jdkr6tjj|_dS)Nrecord_dependencies)optparserm__init__hasattrrnrDrErF)selfrrrrrrp0s  zValues.__init__cCspt|tr|j}|j}xHt|jjD]6}t||r(||kr(t||}|r(|||7}||=q(W|j |dS)N) r+rm__dict__copyr listsr\rqgetattr _update_loose)rr other_dictrrr rrrr7s    z Values.updatecCs|j|jdS)z Return a shallow copy of `self`.)defaults) __class__rs)rrrrrrtCsz Values.copyN)__name__ __module__ __qualname____doc__rprrtrrrrrm)s rmc@s$eZdZejjddgZddZdS)Option validator overridesc Cstjj|||||}|j}|r|jrt||}y|j|||}Wn8tk rx}ztjd|t|fWYdd}~XnXt ||||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) rorprocessdestrrv ExceptionOptionValueErrorrrr) rrr r rrresultr new_valuerrrrrLs " zOption.processN)r{r|r}rorATTRSrrrrrrHsrc8@s~eZdZdZdddgZdjZdddd 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/gdedfd0d1gd2d3ifd4d5gd6edd9fd:d;gdfd?d@gd 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-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-classrPZstrip_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-ozutf-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_filesgeneralz(%%prog (Docutils %s%s, Python %s, on %s)z [%s]rcOsi|_g|_tjj|f|tdtjddd||jsB|j|_t |j |_ |ft ||_ |j |j |j|pti|r|jd ry |j}Wn0tk r}z|jt|WYdd}~XnX|j|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)ru config_filesrorrprTitledHelpFormatterrversion_templater relative_path_settingsrg componentspopulate_from_componentsset_defaults_from_dictryget_standard_config_settingsrrrrs)rrrryZread_config_filesrrconfig_settingsrrrrrp?s"    zOptionParser.__init__c Csx|D]}|dkrq|j}|jj|jxtdt|dD]}|||d\}}}|rrtj|||}|j|n|}x@|D]8\} } } |j| d| i| } | j ddkr|d|j | j <q|W|j r:|j j|j q:WqWx$|D]}|r|jr|j j|jqWdS)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. NrrarrrPrL)rhrr9rfrRro OptionGroupadd_option_group add_optiongetrursettings_defaultsryrZsettings_default_overrides) rrr componentrhr=title descriptionZ option_specgroup help_textoption_stringsrr rrrr_s,     z%OptionParser.populate_from_componentscsytjdjtj}Wntk r0|j}YnXtjjdtjkrny ddl}Wnt k rlddYnXfdd|DS) z:Return list of config files, from environment or standard.ZDOCUTILSCONFIGHOMErNcSs|S)Nr)xrrrsz8OptionParser.get_standard_config_files..csg|]}|jr|qSr)r.)r<f)expandrrr>sz:OptionParser.get_standard_config_files..) rZenvironr&pathsepr0standard_config_filesrX expanduserpwd ImportError)rrrrr)rrget_standard_config_files~s   z&OptionParser.get_standard_config_filescCs.t}x"|jD]}|j|j||qW|S)N)rmrrr)rrrjfilenamerrrrsz)OptionParser.get_standard_config_settingscCst}|j|||jj|jtjj|}i}t}xX|j D]N}|sHq>xBt |j pTf|j fD](}||krnq`d||<|j |j||q`Wq>Wt|j|j||jS)zAReturns a dictionary containing appropriate config file settings.rL) ConfigParserreadrr9_filesrZrXdirnamermrrgZconfig_section_dependenciesr!r get_sectionr]rsr)rr config_filerrYZappliedrjrsectionrrrrs$   z%OptionParser.get_config_file_settingscCs,|j|\|_|_t|j|j|j|_|S)z/Store positional arguments as runtime settings.) check_argsrrr]rsrrr)rrrrrrr check_valuesszOptionParser.check_valuescCshd}}|r"|jd}|dkr"d}|r<|jd}|dkr, 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|_dS)N)CPRawConfigParserrprr_stderr)rrrrrrrrpszConfigParser.__init__cCst|ttfkr|g}x|D]}ytj|dd}Wntk rHwYnXy0tjdkrhtjj |||ntjj |||Wn4t k r|j j |j||f|jwYnX|j|jj||jdr|j||j||qWdS)Nrzutf-8rar`options)rar`)rstrropenrGr version_inforrreadfp read_fileUnicodeDecodeErrorrwritenot_utf8_errorcloserrP has_sectionhandle_old_configvalidate_settings)rr filenamesrrfprrrrs(     zConfigParser.readcCstj|jt|d|jd}|jds0|jdxht|jD]X\}}||j krt|j |\}}|j|s||j|nd}|}|j ||s>|j |||q>W|j ddS)Nrrr) warnings warn_explicit old_warningConfigDeprecationWarningrr add_sectionr r old_settings has_optionr'remove_section)rrrrrr rrrrrrs        zConfigParser.handle_old_configc Csx|jD]}x|j|D]}y|j|}Wntk rBwYnX|jr|j||}y|j|||||d}Wn<tk r}z td||t|||fWYdd}~XnX|j ||||j r|j ||j dqWq WdS)zi Call the validator function and implement overrides on all applicable settings. )r r!zAError in config file "%s", section "[%s]": %s %s = %sN) sectionsrrr0rrrrrr'r) rrrrrrr r rrrrrr's(  zConfigParser.validate_settingscCs|jjddS)zW Transform '-' to '_' so the cmdline form of option names can be used. rbrc)r/re)rr optionstrrrr optionxformCszConfigParser.optionxformcCs6i}|j|r2x"|j|D]}|j||||<qW|S)zf Return a given section as a dictionary (empty if the section doesn't exist). )rrr)rrrZ section_dictr rrrrIs  zConfigParser.get_sectionN)rr)rr)rr) r{r|r}r rrrprrrrrrrrrrs  rc@seZdZdZdS)rz3Warning for deprecated configuration file features.N)r{r|r}r~rrrrrUsr)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)N)-r~Z __docformat__rZos.pathrr configparserrrrorrDZdocutils.utilsZdocutils.nodesZdocutils.utils.error_reportingrrrrrrr"r$r*r1r2r4r7r;r@rCrHrKrVr]rWrlrmrrZ SettingsSpecrrDeprecationWarningrrrrrsL        " ~v