B “äî\ã@sˆdZdZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl Z ddl Z ddl Z ddlmZmZmZmZdd„Zdd „Zd4d d „Zd5d d „Zd6dd„Zd7dd„Zd8dd„Zd9dd„Zd:dd„Zd;dd„Zddd„Zd?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'Gd0d1„d1ej)ƒZ*Gd2d3„d3e+ƒ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`. ZreStructuredTextéN)Ú SUPPRESS_HELP)Úlocale_encodingÚ SafeStringÚ ErrorOutputÚ ErrorStringcOsHx|D]}t|j|dƒqWx&t| ¡ƒD]\}}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)ÚsetattrÚvaluesÚlistÚitems)ÚoptionÚoptÚvalueÚparserÚargsÚkwargsÚ attributeÚkey©rú5/tmp/pip-build-uw_ogi45/docutils/docutils/frontend.pyÚstore_multiple/s rc CsNy| |¡}Wn,tk r:}z| |¡Wdd}~XYnX|j ||¡dS)zQ Read a configuration file during option processing. (Option callback.) N)Úget_config_file_settingsÚ ValueErrorÚerrorrÚupdate)r r r rZ new_settingsrrrrÚread_config_file;s rcCs8yt |¡Wn$tk r2td||fƒ‚YnX|S)Nz$setting "%s": unknown encoding: "%s")ÚcodecsÚlookupÚ LookupError)Úsettingr Ú option_parserÚ config_parserÚconfig_sectionrrrÚvalidate_encodingEs r"cCs4yt |¡Wn tk r.td|ƒ‚YnX|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)rr rr r!rrrÚvalidate_encoding_error_handlerNsr$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 rr r!ÚencodingÚhandlerrrrÚ#validate_encoding_and_error_handlerZs  r*cCsFt|tƒr|Sy|j| ¡ ¡Stk r@td|ƒ‚YnXdS)z|Check/normalize boolean settings: True: '1', 'on', 'yes', 'true' False: '0', 'off', 'no','false', '' zunknown boolean value: "%s"N)Ú isinstanceÚboolÚbooleansÚstripÚlowerÚKeyErrorr)rr rr r!rrrÚvalidate_booleanps  r1cCsBt|tƒs|dkr|Sy|j| ¡ ¡Stk r<|SXdS)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/r0)rr rr r!rrrÚvalidate_ternary}s r2cCst|ƒ}|dkrtdƒ‚|S)Nrz(negative value; must be positive or zero)Úintr)rr rr r!rrrÚvalidate_nonnegative_int‹sr4c CsVyt|ƒStk rPy|j| ¡Sttfk rJtd|ƒ‚YnXYnXdS)Nzunknown threshold: %r.)r3rÚ thresholdsr/r0ÚAttributeErrorr)rr rr r!rrrÚvalidate_threshold’sr7cCs2t|tƒs| d¡}n| ¡}| | d¡¡|S)Nr%)r+r r&ÚpopÚextend)rr rr r!ÚlastrrrÚ$validate_colon_separated_string_listœs   r;cCs:t|tƒs|g}| ¡}dd„| d¡Dƒ}| |¡|S)zHCheck/normalize list arguments (split at "," and strip whitespace). cSs g|]}| d¡r| d¡‘qS)z )r.)Ú.0Úirrrú °sz1validate_comma_separated_list..ú,)r+r r8r&r9)rr rr r!r:r rrrÚvalidate_comma_separated_list¥s   r@cCs"|sdS| d¡r|S|dSdS)Nz./ú/)Úendswith)rr rr r!rrrÚvalidate_url_trailing_slash´s  rCcCs.y tj |¡Stk r(tj d¡SXdS)N)ÚdocutilsÚutilsÚDependencyListÚIOError)rr rr r!rrrÚvalidate_dependency_file½s rHcCsFt|||||ƒ}x0|D](}tj |¡}||krtd||fƒ‚qW|S)Nz$Invalid class value %r (perhaps %r?))r@rDZnodesZmake_idr)rr rr r!ÚclsÚ normalizedrrrÚvalidate_strip_classÄs  rKc CsÔt|||||ƒ}g}xº|D]²}y| dd¡\}}WnFtk rR| |¡wYn(tk rxtd| dd¡ƒ‚YnX| ¡}| d¡} t| ƒdkrž| }n t|ƒdkr¾td| dd¡ƒ‚| ||f¡qW|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 ":".ÚasciiÚbackslashreplaceéz[Invalid value "%s". Please specify 4 quotes (primary open/close; secondary open/close).)r@r&r6ÚappendrÚencoder.Úlen) rr rr r!Z lc_quotesÚitemÚlangÚquotesZmultichar_quotesrrrÚvalidate_smartquotes_localesÑs*     rVcsfˆdkrt ¡‰xP|D]H}||kr||}t|tƒrH‡fdd„|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..)ÚosÚgetcwdr+r rW)ZpathdictÚkeysrYrr r)rYrÚmake_paths_absoluteôs     r]cCstj tj ||¡¡S)N)rZrXÚabspathÚjoin)rYrXrrrrWsrWcOs–t|ƒ}x„tdt|ƒdƒD]p}g}xZ||D]N}dd„|dDƒd}||krPq,|t| ¡ƒkrp| ||¡q,| |¡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|]"}| d¡r|dd… dd¡‘qS)z--r`Nú-Ú_)Ú startswithÚreplace)r<Z opt_stringrrrr>sz(filter_settings_spec..rLr)r ÚrangerRr\rPÚtuple)Ú settings_specÚexcludereÚsettingsr=ZnewoptsZopt_specÚopt_namerrrÚfilter_settings_spec s  rlc@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚValuesz• Updates list attributes by extension rather than by replacement. Works in conjunction with the `OptionParser.lists` instance attribute. cOs8tjj|f|ž|Žt|dƒr(|jdkr4tj ¡|_dS)NÚrecord_dependencies)ÚoptparsermÚ__init__ÚhasattrrnrDrErF)Úselfrrrrrrp0s  zValues.__init__cCspt|tƒr|j}| ¡}xHt|j ¡ƒD]6}t||ƒr(||kr(t||ƒ}|r(|||7}||=q(W|  |¡dS)N) r+rmÚ__dict__Úcopyr Úlistsr\rqÚgetattrÚ _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$eZdZejjddgZdd„ZdS)ÚOptionÚ validatorÚ overridesc Csžtj |||||¡}|j}|rš|jr†t||ƒ}y| |||¡}Wn8tk rx}zt d|t|ƒf¡‚Wdd}~XYnXt |||ƒ|j ršt ||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) rorÚprocessÚdestr€rvÚ ExceptionÚOptionValueErrorrrr) rrr r rrÚresultrÚ new_valuerrrrr‚Ls " zOption.processN)r{r|r}rorÚATTRSr‚rrrrrHsrc8@sxeZdZdZdddgZd ¡Zdddd d d œZd d d d d d d d d dœ Ze e j ddƒpZe pZdZ dZddddgifdddgdedœfddgdddœfd d!d"gd#d$d%d&œfd'd(d)gd#d*d%d&œfd+d,gd#dd%d&œfd-d.d/gdedœfd0d1gd2d3ifd4d5gd6ed7d8œfd9d:gd;d#dd?gd;d#d@dAœfdBdCgd;ddDœfdEdFgddedGœfdHdIgdJddDœfdKdLgddMdedNœfdOdPgddMdœfdQdRgdedœfdSdTgddUdœfdVdWgdXdYdZed[œfd\d]gdXd^dZed[œfd_d`dageddbdceddœfdedfdggd#ddbd&œfdhdidjgd#d dbd&œfdkdlgedmd dcednœfdodpgd#ddmd&œfdqdrgedsd dcednœfdtdugdedœfdvdwgddxdœfdydzgd{d|d}œfd~dgddedGœfd€dgd‚ddDœfdƒd„d…gd†ed‡œfdˆd‰gdŠed‹œfdŒddŽgd†dedœfd‘d’gdŠed‹œfd“e efd”d•gd†e edœfd–ed—geed‹œfd˜d™dšgd›dœddžœfdŸd gd|edd¡œfd¢d£gd|d¤d6ed¥œfd¦d§d¨gd©dªifd«d¬d­gd©d®ifed¯gd°d±ifed²gd°d³ifed´gd©difedµgd©difed¶gd©difed·gd©difed¸gdXd¹edºœfed»gd©diff2fZddddd¼œZd½Zd¾Zd¿ejejr dÀejp d±e j  ¡dÁe j!fZ"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,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 5rLr`rarOé)ÚinfoÚwarningrZsevereÚnoneTF) Ú1ÚonÚyesÚtrueÚ0ÚoffÚnoÚfalseÚr(NrMrNzGeneral 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ƒzInclude 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-urlÚmetavarzz-Do not include a "View document source" link.z--no-source-linkÚcallback)Z source_linkZ source_url)r˜ržÚ callback_argsz4Link from section headers to TOC entries. (default)z--toc-entry-backlinksZ toc_backlinksÚentry)rƒr˜rœÚdefaultz0Link 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-backlinksZfootnote_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="" from the document tree. Warning: potentially dangerous; use with caution. (Multiple-use option.)z--strip-elements-with-classrPZstrip_elements_with_classesz)r˜rƒrr€z”Remove 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)Úchoicesr¡rƒrr€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 . Levels as in --report. Default: 4 (severe).z--haltZ halt_level)r¤rƒr¡rr€z6Halt 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-debugÚdebugz-Send the output of system messages to .z --warningsÚwarning_streamz)rƒrz1Enable 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)rr€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-ozutf-8)rr¡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)rƒr¡rz)Write output file dependencies to .z--record-dependencies)rr€r¡z6Read configuration settings from , 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-attributeZexpose_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]rrc OsÔi|_g|_tjj|f|žtdtjdddœ|—Ž|jsB|j|_t |j ƒ|_ |ft |ƒ|_ |  |j ¡| |pti¡|rÐ|jdsÐy | ¡}Wn0tk rÂ}z| t|ƒ¡Wdd}~XYnX| |j¡dS)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¯)ruÚ config_filesror‰rprÚTitledHelpFormatterr¬Úversion_templater Úrelative_path_settingsrgÚ componentsÚpopulate_from_componentsÚset_defaults_from_dictryÚget_standard_config_settingsrrrrs)rrr½ryZread_config_filesrrZconfig_settingsrrrrrp?s"    zOptionParser.__init__c CsþxÒ|D]Ê}|dkrq|j}|j |j¡x¦tdt|ƒdƒD]’}|||d…\}}}|rrt |||¡}| |¡n|}x@|D]8\} } } |j| d| i| —Ž} |   d¡dkr|d|j | j <q|W|j r:|j  |j ¡q:WqWx$|D]}|rÚ|jrÚ|j  |j¡qÚWdS)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. Nrrar­r˜rPrL)rhr¼r9rfrRroÚ OptionGroupÚadd_option_groupÚ add_optionÚgetrurƒÚsettings_defaultsryrZsettings_default_overrides) rrr½Ú componentrhr=ÚtitleÚ descriptionZ option_specÚgroupÚ help_textÚoption_stringsrr rrrr¾_s,     z%OptionParser.populate_from_componentscs€ytjd tj¡}Wntk r0|j}YnXtjj‰dtjkrny ddl}Wnt k rldd„‰YnX‡fdd„|DƒS) z:Return list of config files, from environment or standard.ZDOCUTILSCONFIGÚHOMErNcSs|S)Nr)ÚxrrrÚóz8OptionParser.get_standard_config_files..csg|]}| ¡rˆ|ƒ‘qSr)r.)r<Úf)Úexpandrrr>sz:OptionParser.get_standard_config_files..) rZÚenvironr&Úpathsepr0Ústandard_config_filesrXÚ expanduserÚpwdÚ ImportError)rrr¹rÖr)rÑrÚget_standard_config_files~s   z&OptionParser.get_standard_config_filescCs.tƒ}x"| ¡D]}| | |¡|¡qW|S)N)rmrØrr)rrrjÚfilenamerrrrÀ’sz)OptionParser.get_standard_config_settingscCs¦tƒ}| ||¡|j |j¡tj |¡}i}tƒ}xX|j D]N}|sHq>xBt |j pTdƒ|j fD](}||krnq`d||<|  | |¡|¡q`Wq>Wt|j|j|ƒ|jS)zAReturns a dictionary containing appropriate config file settings.rrL)Ú ConfigParserÚreadr¹r9Ú_filesrZrXÚdirnamermr½rgZconfig_section_dependenciesr!rÚ get_sectionr]rsr¼)rrÚ config_filerrYZappliedrjrÆÚsectionrrrr˜s$   z%OptionParser.get_config_file_settingscCs,| |¡\|_|_t|j|jƒ|j|_|S)z/Store positional arguments as runtime settings.)Ú check_argsr°r±r]rsr¼r¹r²)rrrrrrrÚ check_values­szOptionParser.check_valuescCshd}}|r"| d¡}|dkr"d}|r<| d¡}|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)ÚCPÚRawConfigParserrprÜrÚ_stderr)rrrrrrrrpôszConfigParser.__init__c Csìt|ƒttfkr|g}xÐ|D]È}yt |dd¡}Wntk rHwYnXy0tjdkrhtj  |||¡ntj  |||¡Wn4t k r®|j   |j||f¡| ¡wYnX| ¡|j |¡| d¡rØ| |¡| ||¡qWdS)NÚrzutf-8)rar`Úoptions)r«ÚstrrÚopenrGrèÚ version_inforírîÚreadfpÚ read_fileÚUnicodeDecodeErrorrïÚwriteÚnot_utf8_errorÚcloserÜrPÚ has_sectionÚhandle_old_configÚvalidate_settings)rrÚ filenamesrrÙÚfprrrrÛýs(     zConfigParser.readcCs¨t |jt|d¡| d¡}| d¡s0| d¡xht| ¡ƒD]X\}}||j krt|j |\}}| |¡s|| |¡nd}|}|  ||¡s>|  |||¡q>W|  d¡dS)Nrrñr³) ÚwarningsÚ warn_explicitÚ old_warningÚConfigDeprecationWarningrÞrûÚ add_sectionr r Ú old_settingsÚ has_optionr'Úremove_section)rrrÙrñrr ràrrrrrüs        zConfigParser.handle_old_configc CsÜxÖ| ¡D]Ê}xÄ| |¡D]¶}y| |¡}Wntk rBwYnX|jrº| ||¡}y|j|||||d}Wn<tk rª}ztd||t|ƒ||fƒ‚Wdd}~XYnX|  |||¡|j r|  ||j d¡qWq 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) Úsectionsrñrçr0r€rÄr„rrr'r) rrrÙrràrr r r‡rrrrrý's(  zConfigParser.validate_settingscCs| ¡ dd¡S)zW Transform '-' to '_' so the cmdline form of option names can be used. rbrc)r/re)rrÚ optionstrrrrÚ optionxformCszConfigParser.optionxformcCs6i}| |¡r2x"| |¡D]}| ||¡||<qW|S)zf Return a given section as a dictionary (empty if the section doesn't exist). )rûrñrÄ)rrràZ section_dictr rrrrÞIs  zConfigParser.get_sectionN) r{r|r}rrrùrprÛrürýr rÞrrrrrÚßs  rÚc@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__rZÚos.pathrèrÚ configparserrírrorrDZdocutils.utilsZdocutils.nodesZdocutils.utils.error_reportingrrrrrrr"r$r*r1r2r4r7r;r@rCrHrKrVr]rWrlrmrr‰Z SettingsSpecrîrÚÚDeprecationWarningrrrrrÚsL        " ~v