V!\c@s/dZdZddlZddlZddlmZmZmZddlmZm Z m Z m Z m Z ddl mZddlmZddlmZmZddlZd fd YZd Zd Zed ededeeeeeeeedZeeeeed ededeeeeedZeeed ededeeeeed Zee jeed ededeeeeedZee jed edeeeeed Z eedeeeeedZ!ed ededeeeeeeeeee j"dZ#dZ$dS(s Calling the ``publish_*`` convenience functions (or instantiating a `Publisher` object) with component names will result in default behavior. For custom behavior (setting component options), create custom component objects first, and pass *them* to ``publish_*``/`Publisher`. See `The Docutils Publisher`_. .. _The Docutils Publisher: http://docutils.sf.net/docs/api/publisher.html treStructuredTextiN(t __version__t__version_details__t SettingsSpec(tfrontendtiotutilstreaderstwriters(t OptionParser(t Transformer(t ErrorOutputt ErrorStringt Publisherc BseZdZddddejdejddZdZdZ dZ dddddZ dddddZ dZ ddddddZddd Zddd Zddd Zd Zdddddded ZdZdZdZdZRS(sK A facade encapsulating the high-level logic of a Docutils system. c Csd|_||_||_||_xIdD]A} tt|| t s+tdt|| | | fq+W||_ ||_ ||_ ||_ ||_ t|_dS(s Initial setup. If any of `reader`, `parser`, or `writer` are not specified, the corresponding ``set_...`` method should be called with a component name (`set_reader` sets the parser as well). treadertparsertwriterspassed string "%s" as "%s" parameter; pass an instance, or use the "%s_name" parameter instead (in docutils.core.publish_* convenience functions).N(sreadersparserswriter(tNonetdocumentRRRt isinstancetgetattrtstrtAssertionErrortsourcet source_classt destinationtdestination_classtsettingsR t_stderr( tselfRRRRRRRRt component((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyt__init__ s           cCs4tj|}||||_|jj|_dS(sSet `self.reader` by name.N(Rtget_reader_classRR(Rt reader_nameRt parser_namet reader_class((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyt set_readerPscCstj|}||_dS(sSet `self.writer` by name.N(Rtget_writer_classR(Rt writer_namet writer_class((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyt set_writerVscCs|jdkr(|j||j|n|jdkrn|jjdkr\|jj|n|jj|_n|jdkr|j|ndS(N(RRR$Rt set_parserRR((RR!R"R&((s1/tmp/pip-install-usGedi/docutils/docutils/core.pytset_components[sc Ks|ra|st}n||_|j}t|dkra|ddkradg|_qantd|j|j|j|fd|dt d|d |}|S( Niit applicationt applicationst componentstdefaultstread_config_filestusaget description( Rtconfig_sectiontsplittlentconfig_section_dependenciesR RRRtTrue(RR0R1t settings_specR2R.tpartst option_parser((s1/tmp/pip-install-usGedi/docutils/docutils/core.pytsetup_option_parseres   " cKs1|j|||||}|j|_|jS(s  Set and return default settings (overrides in `defaults` dict). Set components first (`self.set_reader` & `self.set_writer`). Explicitly setting `self.settings` disables command line option processing from `self.publish()`. (R:tget_default_valuesR(RR0R1R7R2R.R9((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyt get_settingsvs cCsQ|jdkrM|pij}|jdt|jd|d||ndS(Nt tracebackR7R2(RRtcopyt setdefaultR6R<(RR7tsettings_overridesR2R.((s1/tmp/pip-install-usGedi/docutils/docutils/core.pytprocess_programmatic_settingss c Ks|j|||||}|dkrztjd}tjdkrztjpOd}g|D]} | j|^qY}qzn|j||_ dS(s Pass an empty list to `argv` to avoid reading `sys.argv` (the default). Set components first (`self.set_reader` & `self.set_writer`). iiitasciiN(ii( R:Rtsystargvt version_infoRtlocale_encodingtdecodet parse_argsR( RRDR0R1R7R2R.R9t argv_encodingta((s1/tmp/pip-install-usGedi/docutils/docutils/core.pytprocess_command_lines   (cCsH|jdkr"|jd|n|jdkrD|jd|ndS(Nt source_pathtdestination_path(RRt set_sourceRtset_destination(RRLRM((s1/tmp/pip-install-usGedi/docutils/docutils/core.pytset_ioscCs|dkr|jj}n ||j_y+|jd|d|d|jj|_Wn8tk r|jd|d|d|jj|_nXdS(NRRLtencoding(RRt_sourceRtinput_encodingRt TypeError(RRRL((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyRNs       c Cs^|dkr|jj}n ||j_|jd|d|d|jjd|jj|_dS(NRRMRQt error_handler(RRt _destinationRtoutput_encodingtoutput_encoding_error_handlerR(RRRM((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyROs     cCsH|jjj|j|j|jj|j|jf|jjjdS(N( Rt transformertpopulate_from_componentsRRRRRtapply_transforms(R((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyR[s  c Csd}y|jdkr=|j||||||p6in|j|jj|j|j|j|_|j |j j |j|j } |j j Wnxtk r} d}| j} nWtk r} |jsn|jjr|jn|j| t}d} nX|j|rj|jrj|jjj|jjkrjtj|jjjdn|rtj| n| S(s Process command line options and arguments (if `self.settings` not already set), run `self.reader` and then `self.writer`. Return `self.writer`'s output. ii N(RRRKRPRtreadRRRR[RtwriteRtassemble_partst SystemExittcodet ExceptionR=tdebugging_dumpstreport_ExceptionR6treportert max_leveltexit_status_levelRCtexit( RRDR0R1R7R@R2tenable_exit_statusRgtoutputterrort exit_status((s1/tmp/pip-install-usGedi/docutils/docutils/core.pytpublishs@          c CsH|js dS|jjrE|jdIJ|jtj|jjIJn|jjr}|jdIJ|jtj|jjIJn|jjr |jdIJ|jdIJ|jtjg|jj j D]=\}}}}|d|j |j f|o|j |f^qIJn|jjrD|jdIJ|j|jjjdIJndS(Ns ::: Runtime settings:s ::: Document internals:s ::: Transforms applied:s@ (priority, transform class, pending node details, keyword args)s%s.%ss ::: Pseudo-XML:traw_unicode_escape(RRt dump_settingsRtpprinttpformatt__dict__tdump_internalstdump_transformsRYtappliedt __module__t__name__tdetailstdump_pseudo_xmltencode(Rtprioritytxclasstpendingtkwargs((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyRbs$         V  cCst|tjr"|j|nt|trA|j|nt|tjrp|jj dt |nt|tj r|jj dt |nT|jdt |IJ|jdt t jrdt jpdtjjdfIJdS(Nu-Unable to open source file for reading: %s u2Unable to open destination file for writing: %s u%ssExiting due to error. Use "--traceback" to diagnose. Please report errors to . Include "--traceback" output, Docutils version (%s%s), Python version (%s), your OS type & version, and the command line used.s [%s]ti(RRt SystemMessagetreport_SystemMessagetUnicodeEncodeErrortreport_UnicodeErrorRt InputErrorRR]R t OutputErrorRtdocutilsRRCtversionR3(RRj((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyRc s"   cCs+|jd|jtjj|jfIJdS(Ns,Exiting due to level-%s (%s) system message.(RtlevelRtReportertlevels(RRj((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyR!s c Csz|j|j|j!}|jjdt||jj|jdd|jdd|jj t t j j dfdS(Ns%s The specified output encoding (%s) cannot handle all of the output. Try setting "--output-encoding-error-handler" to * "xmlcharrefreplace" (for HTML & XML output); the output will contain "%s" and should be usable. * "backslashreplace" (for other output formats); look for "%s" in the output. * "replace"; look for "?" in the output. "--output-encoding-error-handler" is currently set to "%s". Exiting due to error. Use "--traceback" to diagnose. If the advice above doesn't eliminate the error, please report it to . Include "--traceback" output, Docutils version (%s), Python version (%s), your OS type & version, and the command line used. RBtxmlcharrefreplacetbackslashreplacei(tobjecttstarttendRR]R RRWRyRXRRCRR3(RRjtdata((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyR&s    N(RvRut__doc__RRt FileInputt FileOutputRR$R(R*R:R<RARKRPRNROR[tFalseRlRbRcRR(((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyR s4    -      '   s*%prog [options] [ []]sReads from (default is stdin) and writes to (default is stdout). See for the full reference.t standalonetrestructuredtextt pseudoxmlc CsVt|||d|}|j||||j| | | ||d| d| }|S(s% Set up & run a `Publisher` for command-line-based file I/O (input and output file paths taken automatically from the command line). Return the encoded string output also. Parameters: see `publish_programmatically` for the remainder. - `argv`: Command-line argument list to use instead of ``sys.argv[1:]``. - `usage`: Usage string, output if there's a problem parsing the command line. - `description`: Program description, output for the "--help" option (along with command-line option descriptions). RR2Rh(R R*Rl(RR!RR"RR&RR7R@R2RhRDR0R1tpubRi((s1/tmp/pip-install-usGedi/docutils/docutils/core.pytpublish_cmdlineJs c#Cstdtjd|d|dtjd|d|d|d|d |d |d |d | d | d| d| d| d|\}}|S(s Set up & run a `Publisher` for programmatic use with file-like I/O. Return the encoded string output also. Parameters: see `publish_programmatically`. RRRLRRRMRR!RR"RR&RR7R@R2Rh(tpublish_programmaticallyRRR(RRLRRMRR!RR"RR&RR7R@R2RhRiR((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyt publish_filees       c#Cstdtjd|d|dtjddd|d|d|d |d |d |d |d | d| d| d| d| \}}|S(sB Set up & run a `Publisher` for programmatic use with string I/O. Return the encoded string or Unicode string output. For encoded string output, be sure to set the 'output_encoding' setting to the desired encoding. Set it to 'unicode' for unencoded Unicode string output. Here's one way:: publish_string(..., settings_overrides={'output_encoding': 'unicode'}) Similarly for Unicode string input (`source`):: publish_string(..., settings_overrides={'input_encoding': 'unicode'}) Parameters: see `publish_programmatically`. RRRLRRRMRR!RR"RR&RR7R@R2RhN(RRt StringInputt StringOutputR(RRLRMRR!RR"RR&RR7R@R2RhRiR((s1/tmp/pip-install-usGedi/docutils/docutils/core.pytpublish_strings      c#Cstd|d|d|dtjddd|d|d|d |d |d |d | d | d| d| d| d|\}}|jjS(s Set up & run a `Publisher`, and return a dictionary of document parts. Dictionary keys are the names of parts, and values are Unicode strings; encoding is up to the client. For programmatic use with string I/O. For encoded string input, be sure to set the 'input_encoding' setting to the desired encoding. Set it to 'unicode' for unencoded Unicode string input. Here's how:: publish_parts(..., settings_overrides={'input_encoding': 'unicode'}) Parameters: see `publish_programmatically`. RRLRRRRMRR!RR"RR&RR7R@R2RhN(RRRRRR8(RRLRRMRR!RR"RR&RR7R@R2RhRiR((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyt publish_partss      c  Cstd|d|dd d|d|dtj} | j||d| j|| | | j||| jd d | jd| } | j S( s Set up & run a `Publisher` for programmatic use with string I/O. Return the document tree. For encoded string input, be sure to set the 'input_encoding' setting to the desired encoding. Set it to 'unicode' for unencoded Unicode string input. Here's one way:: publish_doctree(..., settings_overrides={'input_encoding': 'unicode'}) Parameters: see `publish_programmatically`. RRRRRRtnullRhN( R RRt NullOutputR*RARNRORlR(RRLRRR!RR"RR7R@R2RhRRi((s1/tmp/pip-install-usGedi/docutils/docutils/core.pytpublish_doctrees  c Cstjjjdd} t| d|dtj|dtjd|} | re|re| j |n| j |||| j d|| j d|S(sJ Set up & run a `Publisher` to render from an existing document tree data structure, for programmatic use with string I/O. Return the encoded string output. Note that document.settings is overridden; if you want to use the settings of the original `document`, pass settings=document.settings. Also, new document.transformer and document.reporter objects are generated. For encoded string output, be sure to set the 'output_encoding' setting to the desired encoding. Set it to 'unicode' for unencoded Unicode string output. Here's one way:: publish_from_doctree( ..., settings_overrides={'output_encoding': 'unicode'}) Parameters: `document` is a `docutils.nodes.document` object, an existing document tree. Other parameters: see `publish_programmatically`. R"RRRRRhN( RRtdoctreetReaderR RRt DocTreeInputRR(RARORl( RRMRR&RR7R@R2RhRR((s1/tmp/pip-install-usGedi/docutils/docutils/core.pytpublish_from_doctrees  c Cs\t|||d|d|}|j||||j| | | ||d| d| }|S(s Set up & run a `Publisher` for command-line-based file I/O (input and output file paths taken automatically from the command line). Return the encoded string output also. This is just like publish_cmdline, except that it uses io.BinaryFileOutput instead of io.FileOutput. Parameters: see `publish_programmatically` for the remainder. - `argv`: Command-line argument list to use instead of ``sys.argv[1:]``. - `usage`: Usage string, output if there's a problem parsing the command line. - `description`: Program description, output for the "--help" option (along with command-line option descriptions). RRR2Rh(R R*Rl(RR!RR"RR&RR7R@R2RhRDR0R1RRRRi((s1/tmp/pip-install-usGedi/docutils/docutils/core.pytpublish_cmdline_to_binary s c Cst||| d| d|d|}|j|| | |j| |||j|||j|||jd|}||fS(s7 Set up & run a `Publisher` for custom programmatic use. Return the encoded string output and the Publisher object. Applications should not need to call this function directly. If it does seem to be necessary to call this function directly, please write to the Docutils-develop mailing list . Parameters: * `source_class` **required**: The class for dynamically created source objects. Typically `io.FileInput` or `io.StringInput`. * `source`: Type depends on `source_class`: - If `source_class` is `io.FileInput`: Either a file-like object (must have 'read' and 'close' methods), or ``None`` (`source_path` is opened). If neither `source` nor `source_path` are supplied, `sys.stdin` is used. - If `source_class` is `io.StringInput` **required**: The input string, either an encoded 8-bit string (set the 'input_encoding' setting to the correct encoding) or a Unicode string (set the 'input_encoding' setting to 'unicode'). * `source_path`: Type depends on `source_class`: - `io.FileInput`: Path to the input file, opened if no `source` supplied. - `io.StringInput`: Optional. Path to the file or object that produced `source`. Only used for diagnostic output. * `destination_class` **required**: The class for dynamically created destination objects. Typically `io.FileOutput` or `io.StringOutput`. * `destination`: Type depends on `destination_class`: - `io.FileOutput`: Either a file-like object (must have 'write' and 'close' methods), or ``None`` (`destination_path` is opened). If neither `destination` nor `destination_path` are supplied, `sys.stdout` is used. - `io.StringOutput`: Not used; pass ``None``. * `destination_path`: Type depends on `destination_class`: - `io.FileOutput`: Path to the output file. Opened if no `destination` supplied. - `io.StringOutput`: Path to the file or object which will receive the output; optional. Used for determining relative paths (stylesheets, source links, etc.). * `reader`: A `docutils.readers.Reader` object. * `reader_name`: Name or alias of the Reader class to be instantiated if no `reader` supplied. * `parser`: A `docutils.parsers.Parser` object. * `parser_name`: Name or alias of the Parser class to be instantiated if no `parser` supplied. * `writer`: A `docutils.writers.Writer` object. * `writer_name`: Name or alias of the Writer class to be instantiated if no `writer` supplied. * `settings`: A runtime settings (`docutils.frontend.Values`) object, for dotted-attribute access to runtime settings. It's the end result of the `SettingsSpec`, config file, and option processing. If `settings` is passed, it's assumed to be complete and no further setting/config/option processing is done. * `settings_spec`: A `docutils.SettingsSpec` subclass or object. Provides extra application-specific settings definitions independently of components. In other words, the application becomes a component, and its settings data is processed along with that of the other components. Used only if no `settings` specified. * `settings_overrides`: A dictionary containing application-specific settings defaults that override the defaults of other components. Used only if no `settings` specified. * `config_section`: A string, the name of the configuration file section for this application. Overrides the ``config_section`` attribute defined by `settings_spec`. Used only if no `settings` specified. * `enable_exit_status`: Boolean; enable exit status at end of processing? RRRRh(R R*RARNRORl(RRRLRRRMRR!RR"RR&RR7R@R2RhRRi((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyR,sd  (%Rt __docformat__RCRoRRRRRRRRRtdocutils.frontendR tdocutils.transformsR tdocutils.utils.error_reportingR R tdocutils.readers.doctreeR t default_usagetdefault_descriptionRR6RRRRRRRRtBinaryFileOutputRR(((s1/tmp/pip-install-usGedi/docutils/docutils/core.pyt s~  ( +      #