B Ðñ¢dÞã@sÈdZdZddlZddlZddlZddlZddlZddlZddlmZej dkrhddl m Z ddlm Z nddl m Z ddlmZ ddlZddlZddlZdd lmZmZmZmZej dkr¾eZd d „Zd d „Zd8dd„Zd9dd„Zd:dd„Zd;dd„Zddd„Z!d?dd„Z"d@dd„Z#dAd d!„Z$dBd"d#„Z%dCd$d%„Z&dDd&d'„Z'dEd(d)„Z(d*d+„Z)d,d-„Z*Gd.d/„d/ej+ƒZ+Gd0d1„d1ej,ƒZ,Gd2d3„d3ej-ej.ƒZ-Gd4d5„d5e ƒZ Gd6d7„d7e/ƒZ0dS)Faƒ 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`. ÚreStructuredTextéN)Ú SUPPRESS_HELP)ér)ÚRawConfigParser)Úgetcwd)Úgetcwdu)Úlocale_encodingÚ SafeStringÚ ErrorOutputÚ ErrorStringcOsDx|D]}t|j|dƒqWx"| ¡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Úitems)ÚoptionÚoptÚvalueÚparserÚargsÚkwargsÚ attributeÚkey©rú8/tmp/pip-target-jj3kjtpb/lib/python/docutils/frontend.pyÚstore_multiple8s 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)rrrrZ new_settingsrrrrÚread_config_fileDs rcCs8yt |¡Wn$tk r2td||fƒ‚YnX|S)Nz$setting "%s": unknown encoding: "%s")ÚcodecsÚlookupÚ LookupError)ÚsettingrÚ option_parserÚ config_parserÚconfig_sectionrrrÚvalidate_encodingNs 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!)r"rr#r$r%rrrÚvalidate_encoding_error_handlerWsr(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(Úsetr r r&)r"rr#r$r%ÚencodingÚhandlerrrrÚ#validate_encoding_and_error_handlercs  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!)r"rr#r$r%rrrÚvalidate_booleanys  r5cCsBt|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/r0r1r2r3r4)r"rr#r$r%rrrÚvalidate_ternary†s r6cCst|ƒ}|dkrtdƒ‚|S)Nrz(negative value; must be positive or zero)Úintr)r"rr#r$r%rrrÚvalidate_nonnegative_int”sr8c CsVyt|ƒStk rPy|j| ¡Sttfk rJtd|ƒ‚YnXYnXdS)Nzunknown threshold: %r.)r7rÚ thresholdsr3r4ÚAttributeErrorr!)r"rr#r$r%rrrÚvalidate_threshold›sr;cCs2t|tƒs| d¡}n| ¡}| | d¡¡|S)Nr))r/Úlistr*ÚpopÚextend)r"rr#r$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 )r2)Ú.0Úirrrú ¹sz1validate_comma_separated_list..ú,)r/r<r=r*r>)r"rr#r$r%r?rrrrÚvalidate_comma_separated_list®s   rEcCs"|sdS| d¡r|S|dSdS)Nz./ú/)Úendswith)r"rr#r$r%rrrÚvalidate_url_trailing_slash½s  rHcCs.y tj |¡Stk r(tj d¡SXdS)N)ÚdocutilsÚutilsÚDependencyListÚIOError)r"rr#r$r%rrrÚvalidate_dependency_fileÆs rMcCsFt|||||ƒ}x0|D](}tj |¡}||krtd||fƒ‚qW|S)Nz$Invalid class value %r (perhaps %r?))rErIZnodesZmake_idr)r"rr#r$r%ÚclsÚ normalizedrrrÚvalidate_strip_classÍs  rPc 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).)rEr*r:ÚappendrÚencoder2Úlen) r"rr#r$r%Z lc_quotesÚitemÚlangÚquotesZmultichar_quotesrrrÚvalidate_smartquotes_localesÚs*     r[csdˆdkrtƒ‰xP|D]H}||kr||}t|tƒrF‡fdd„|Dƒ}n|rTtˆ|ƒ}|||<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)rAÚpath)Ú base_pathrrrC sz'make_paths_absolute..)rr/r<r\)ZpathdictÚkeysr^rrr)r^rÚmake_paths_absoluteýs     r`cCstj tj ||¡¡S)N)Úosr]ÚabspathÚjoin)r^r]rrrr\sr\cOs’t|ƒ}x€tdt|ƒdƒD]l}g}xV||D]J}dd„|dDƒd}||krPq,|| ¡krl| ||¡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.) ércSs*g|]"}| d¡r|dd… dd¡‘qS)z--rdNú-Ú_)Ú startswithÚreplace)rAZ opt_stringrrrrC$sz(filter_settings_spec..rQr)r<ÚrangerWr_rUÚtuple)Ú settings_specÚexcluderhÚsettingsrBZnewoptsZopt_specÚopt_namerrrÚfilter_settings_specs   roc@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)ÚoptparserpÚ__init__ÚhasattrrqrIrJrK)Úselfrrrrrrs9s  zValues.__init__cCslt|tƒr|j}| ¡}xD|j ¡D]6}t||ƒr$||kr$t||ƒ}|r$|||7}||=q$W| |¡dS)N) r/rpÚ__dict__ÚcopyÚlistsr_rtÚgetattrÚ _update_loose)ruÚ other_dictr#r"rrrrr@s    z Values.updatecCs|j|jdS)z Return a shallow copy of `self`.)Údefaults)Ú __class__rv)rurrrrwLsz Values.copyN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rsrrwrrrrrp2s rpc@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) rrr‚ÚprocessÚdestrƒryÚ ExceptionÚOptionValueErrorr r r„) rurrr rÚresultr"Ú new_valuerrrrr…Us " zOption.processN)r~rr€rrr‚ÚATTRSr…rrrrr‚Qsr‚c8@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 5rQrdrrTé)ÚinfoÚwarningrZsevereÚnoneTF) Ú1ÚonÚyesÚtrueÚ0ÚoffÚnoÚfalseÚr,NrRrSzGeneral 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)Ú 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ŸÚ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-classrUZstrip_elements_with_classesz)r›r†r rƒ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†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 . 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 . 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†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: :strict.z--input-encodingz-iz)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-ozutf-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)r†r¦r z)Write output file dependencies to .z--record-dependencies)r rƒ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´)rxÚ config_filesrrrŒrsr‚ÚTitledHelpFormatterr±Úversion_templater<Úrelative_path_settingsrjÚ componentsÚpopulate_from_componentsÚset_defaults_from_dictr|Úget_standard_config_settingsrrr rv)rurÂr|Zread_config_filesrrÚconfig_settingsrrrrrsHs"    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. Nrrr²r›rUrQ)rkrÁr>rirWrrÚ OptionGroupÚadd_option_groupÚ add_optionÚgetrxr†Úsettings_defaultsr|rZsettings_default_overrides) rurÂÚ componentrkrBÚtitleÚ descriptionZ option_specÚgroupÚ help_textÚoption_stringsrrrrrrÃhs,     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)r2)rAÚf)ÚexpandrrrC™sz:OptionParser.get_standard_config_files..) raÚenvironr*Úpathsepr4Ústandard_config_filesr]Ú expanduserÚpwdÚ ImportError)rur¾rÜr)r×rÚget_standard_config_files‡s   z&OptionParser.get_standard_config_filescCs.tƒ}x"| ¡D]}| | |¡|¡qW|S)N)rprÞrr)rurmÚ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.rrQ)Ú ConfigParserÚreadr¾r>Ú_filesrar]ÚdirnamerprÂrjZconfig_section_dependenciesr%rÚ get_sectionr`rvrÁ)ruÚ config_filerr^ZappliedrmrÌÚsectionrrrr¡s$   z%OptionParser.get_config_file_settingscCs,| |¡\|_|_t|j|jƒ|j|_|S)z/Store positional arguments as runtime settings.)Ú check_argsrµr¶r`rvrÁr¾r·)rur rrrrÚ 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$tj|f|ž|Žg|_tƒ|_dS)N)rrsrâr Ú_stderr)rurrrrrrsýszConfigParser.__init__c Csèt|ƒttfkr|g}xÌ|D]Ä}yt |dd¡}Wntk rHwYnXy,tjdkrft  |||¡nt  |||¡Wn4t k rª|j   |j||f¡| ¡wYnX| ¡|j |¡| d¡rÔ| |¡| ||¡qWdS)NÚrzutf-8)rrÚoptions)r°ÚstrÚunicoderÚopenrLrïÚ version_inforÚreadfpÚ read_fileÚUnicodeDecodeErrorrõÚwriteÚnot_utf8_errorÚcloserârUÚ has_sectionÚhandle_old_configÚvalidate_settings)ruÚ filenamesr#rßÚfprrrrás(     zConfigParser.readcCs¤t |jt|d¡| d¡}| d¡s0| d¡xd| ¡D]X\}}||jkrp|j|\}}| |¡sx| |¡nd}|}|  ||¡s:|  |||¡q:W|  d¡dS)Nrr÷r¸) ÚwarningsÚ warn_explicitÚ old_warningÚConfigDeprecationWarningrärÚ add_sectionrÚ old_settingsÚ has_optionr+Úremove_section)rurßr÷rrrær"rrrrs        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îr4rƒrÊr‡rr r+r„) rurßr#rær"rrrŠrrrrr0s(  zConfigParser.validate_settingscCs| ¡ dd¡S)zW Transform '-' to '_' so the cmdline form of option names can be used. rerf)r3rh)ruÚ optionstrrrrÚ optionxformLszConfigParser.optionxformcCs6i}| |¡r2x"| |¡D]}| ||¡||<qW|S)zf Return a given section as a dictionary (empty if the section doesn't exist). )rr÷rÊ)ruræZ section_dictrrrrräRs  zConfigParser.get_sectionN) r~rr€r r rrsrárrrrärrrrràès  ràc@seZdZdZdS)r z3Warning for deprecated configuration file features.N)r~rr€rrrrrr ^sr )NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)NN)N)1rÚ __docformat__raÚos.pathrïrrrrrrûÚ configparserrrràrrIZdocutils.utilsZdocutils.nodesZdocutils.utils.error_reportingrr r r rørùrrr&r(r.r5r6r8r;r@rErHrMrPr[r`r\rorpr‚rŒZ SettingsSpecÚDeprecationWarningr rrrrÚsX             " ~v