B “äî\ˆsã@sTdZdZddlZddlZddlmZmZmZddlmZm Z m Z m Z m Z ddl mZddlmZddlmZmZddlZGd d „d ƒZd Zd Zdd ddddddddddeefdd„Zd"dd„Zd#dd„Zde jddd dddddddddfdd„Zde jdd dddddddf dd„Zd$dd„Zdd ddddddddddeede jfdd„Z d d!„Z!dS)%a‚ 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 ZreStructuredTextéN)Ú __version__Ú__version_details__Ú SettingsSpec)ÚfrontendÚioÚutilsÚreadersÚwriters)Ú OptionParser)Ú Transformer)Ú ErrorOutputÚ ErrorStringc@s¼eZdZdZddddejdejdfdd„Zdd„Zdd„Z d d „Z d&d d „Z d'd d„Z dd„Z d(dd„Zd)dd„Zd*dd„Zd+dd„Zdd„Zd,dd„Zdd„Zd d!„Zd"d#„Zd$d%„ZdS)-Ú PublisherzK A facade encapsulating the high-level logic of a Docutils system. Nc Csxd|_||_||_||_x4dD],} tt|| ƒtƒrtdt|| ƒ| | fƒ‚qW||_||_ ||_ ||_ ||_ t ƒ|_dS)zâ 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). N)ÚreaderÚparserÚwriterz’passed string "%s" as "%s" parameter; pass an instance, or use the "%s_name" parameter instead (in docutils.core.publish_* convenience functions).)ÚdocumentrrrÚ isinstanceÚgetattrÚstrÚAssertionErrorÚsourceÚ source_classÚ destinationÚdestination_classÚsettingsr Ú_stderr) ÚselfrrrrrrrrÚ component©rú1/tmp/pip-build-uw_ogi45/docutils/docutils/core.pyÚ__init__ s  zPublisher.__init__cCs$t |¡}|||ƒ|_|jj|_dS)zSet `self.reader` by name.N)rZget_reader_classrr)rÚ reader_namerÚ parser_nameZ reader_classrrr Ú set_readerPs  zPublisher.set_readercCst |¡}|ƒ|_dS)zSet `self.writer` by name.N)r Zget_writer_classr)rÚ writer_nameZ writer_classrrr Ú set_writerVs zPublisher.set_writercCs^|jdkr| ||j|¡|jdkrF|jjdkr<|j |¡|jj|_|jdkrZ| |¡dS)N)rr$rÚ set_parserrr&)rr"r#r%rrr Úset_components[s      zPublisher.set_componentscKs`|r<|stƒ}||_| ¡}t|ƒdkr<|ddkr sz2Publisher.process_command_line..)r5ÚsysÚargvÚ version_inforZlocale_encodingÚ parse_argsr)rrEr-r.r2r/r,r4r)rBr Úprocess_command_lines   zPublisher.process_command_linecCs0|jdkr|j|d|jdkr,|j|ddS)N)Ú source_path)Údestination_path)rÚ set_sourcerÚset_destination)rrIrJrrr Úset_io£s   zPublisher.set_iocCsd|dkr|jj}n||j_y|j|||jjd|_Wn*tk r^|j|||jjd|_YnXdS)N)rrIÚencoding)rZ_sourcerZinput_encodingrÚ TypeError)rrrIrrr rK©s zPublisher.set_sourcecCs:|dkr|jj}n||j_|j|||jj|jjd|_dS)N)rrJrNZ error_handler)rZ _destinationrÚoutput_encodingÚoutput_encoding_error_handlerr)rrrJrrr rL¹s zPublisher.set_destinationcCs4|jj |j|j|jj|j|jf¡|jj ¡dS)N) rÚ transformerZpopulate_from_componentsrrrrrÚapply_transforms)rrrr rSÃs zPublisher.apply_transformsFc Cs>d}yl|jdkr*|j|||||f|p&iŽ| ¡|j |j|j|j¡|_| ¡|j   |j|j ¡} |j   ¡Wnxt k rœ} zd}| j} Wdd} ~ XYnNtk rè} z0|js´‚|jjrÆ| ¡‚| | ¡d}d} Wdd} ~ XYnX| ¡|r*|jr*|jjj|jjkr*t |jjjd¡n|r:t | ¡| S)z¼ Process command line options and arguments (if `self.settings` not already set), run `self.reader` and then `self.writer`. Return `self.writer`'s output. Nr)Té )rrHrMrÚreadrrrrSrÚwriterZassemble_partsÚ SystemExitÚcodeÚ Exceptionr8Údebugging_dumpsÚreport_ExceptionZreporterZ max_levelZexit_status_levelrDÚexit) rrEr-r.r2r;r/Úenable_exit_statusr\ÚoutputÚerrorÚ exit_statusrrr ÚpublishÉs@       zPublisher.publishcCsâ|js dS|jjr8td|jdtt |jj¡|jd|jjrftd|jdtt |jj¡|jd|jj r®td|jdtd|jdtt dd„|jj j Dƒ¡|jd|jj rÞtd|jdt|j ¡  d ¡|jddS) Nz ::: Runtime settings:)Úfilez ::: Document internals:z ::: Transforms applied:z@ (priority, transform class, pending node details, keyword args)cSs2g|]*\}}}}|d|j|jf|o(|j|f‘qS)z%s.%s)Ú __module__Ú__name__Údetails)r@ÚpriorityZxclassÚpendingÚkwargsrrr rCsz-Publisher.debugging_dumps..z ::: Pseudo-XML:Zraw_unicode_escape)rrZ dump_settingsÚprintrÚpprintÚpformatÚ__dict__Zdump_internalsZdump_transformsrRZappliedZdump_pseudo_xmlÚencode)rrrr rZòs&  zPublisher.debugging_dumpscCs¾t|tjƒr| |¡n¢t|tƒr.| |¡nŒt|tjƒrP|j  dt |ƒ¡njt|tj ƒrr|j  dt |ƒ¡nHt dt |ƒ|jdt dt tjrždtjp dtj ¡df|jddS) Nz-Unable to open source file for reading: %s z2Unable to open destination file for writing: %s z%s)rbzëExiting 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.z [%s]Úr)rrZ SystemMessageÚreport_SystemMessageÚUnicodeEncodeErrorÚreport_UnicodeErrorrZ InputErrorrrVr Z OutputErrorrirÚdocutilsrrDÚversionr0)rr_rrr r[ s"       zPublisher.report_ExceptioncCs&td|jtjj|jf|jddS)Nz,Exiting due to level-%s (%s) system message.)rb)riÚlevelrZReporterZlevelsr)rr_rrr ro!szPublisher.report_SystemMessagec CsZ|j|j|j…}|j dt|ƒ|jj| dd¡| dd¡|jj t t j   ¡df¡dS)Na¬%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. r>ÚxmlcharrefreplaceÚbackslashreplacer)ÚobjectÚstartÚendrrVr rrPrmrQrrDrsr0)rr_Údatarrr rq&s  zPublisher.report_UnicodeError)NNNN)NNNN)NNNNN)NN)NN)NN)NNNNNNF)rdrcÚ __qualname__Ú__doc__rÚ FileInputÚ FileOutputr!r$r&r(r5r7r<rHrMrKrLrSrarZr[rorqrrrr rs4 -         'rz*%prog [options] [ []]z£Reads from (default is stdin) and writes to (default is stdout). See for the full reference.Ú standaloneÚrestructuredtextÚ pseudoxmlTc Cs:t||||d}| |||¡|j| | | ||| | d}|S)a% 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). )r)r/r])rr(ra)rr"rr#rr%rr2r;r/r]rEr-r.Úpubr^rrr Úpublish_cmdlineJs   rƒFcCs6ttj||tj|||||||| | | | | |d\}}|S)z© Set up & run a `Publisher` for programmatic use with file-like I/O. Return the encoded string output also. Parameters: see `publish_programmatically`. )rrrIrrrJrr"rr#rr%rr2r;r/r])Úpublish_programmaticallyrr}r~)rrIrrJrr"rr#rr%rr2r;r/r]r^r‚rrr Ú publish_filees  r…cCs6ttj||tjd|||||||| | | | | d\}}|S)aB 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`. N)rrrIrrrJrr"rr#rr%rr2r;r/r])r„rÚ StringInputÚ StringOutput)rrIrJrr"rr#rr%rr2r;r/r]r^r‚rrr Úpublish_strings rˆcCs8t|||tjd||||||| | | | | |d\}}|jjS)a 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`. N)rrIrrrrJrr"rr#rr%rr2r;r/r])r„rr‡rr3)rrIrrJrr"rr#rr%rr2r;r/r]r^r‚rrr Ú publish_parts£s r‰c Cs\t||d||tjd} |  ||d¡|  || | ¡|  ||¡|  dd¡| j| d} | jS)a  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`. N)rrrrrrÚnull)r]) rrZ NullOutputr(r<rKrLrar)rrIrrr"rr#rr2r;r/r]r‚r^rrr Úpublish_doctreeÅs     r‹c Csdtjjjdd} t| d|t |¡tj|d} |s>|r>|  |¡|   |||¡|   d|¡| j |dS)aJ 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Š)r#N)rrr)r]) rrrZdoctreeÚReaderrrZ DocTreeInputr‡r&r<rLra) rrJrr%rr2r;r/r]rr‚rrr Úpublish_from_doctreeäs    rc Cs<t|||||d}| |||¡|j| | | ||| | d}|S)a“ 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). )rr)r/r])rr(ra)rr"rr#rr%rr2r;r/r]rEr-r.rrr‚r^rrr Úpublish_cmdline_to_binary s   rŽcCs\t||| | ||d}| || | ¡| | ||¡| ||¡| ||¡|j|d}||fS)a7 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? )rrr)r])rr(r<rKrLra)rrrIrrrJrr"rr#rr%rr2r;r/r]r‚r^rrr r„,sd     r„)NNNNNrNr€NrNNNNF) NNNrNr€NrNNNNF)NNrNNNNF)"r|Z __docformat__rDrjrrrrrrrrrr Zdocutils.frontendr Zdocutils.transformsr Zdocutils.utils.error_reportingr r Zdocutils.readers.doctreerZ default_usageZdefault_descriptionrƒr…rˆr†r‰r‹rZBinaryFileOutputrŽr„rrrr Ú s€  ,     #