
3|Oc           @   s/  d  Z  d Z d d l Z d d l Z d d l m Z m Z m Z d d l m Z m	 Z	 m
 Z
 m Z m Z d d l m Z d d l m Z d d l m Z m Z d d l Z d	 f  d
     YZ d Z d Z e d e d e d e e e e e e e e d  Z e e e e e d e d e d e e e e e d  Z e e e d e d e d e e e e e d  Z e e	 j e e d e d e d e e e e e d  Z e e	 j e d e d e e e e e d  Z  e e d e e e e e d  Z! e d e d e d e e e e e e e e e e	 j" d  Z# d   Z$ d S(   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
t   reStructuredTextiN(   t   __version__t   __version_details__t   SettingsSpec(   t   frontendt   iot   utilst   readerst   writers(   t   OptionParser(   t   Transformer(   t   ErrorOutputt   ErrorStringt	   Publisherc        	   B   s  e  Z d  Z d d d d e j d e j d d  Z d   Z d   Z	 d   Z
 d d d d d  Z d d d d d  Z d   Z d d d d d d  Z d d d	  Z d d d
  Z d d d  Z d   Z d d d d d d e d  Z d   Z d   Z d   Z d   Z RS(   sK   
    A facade encapsulating the high-level logic of a Docutils system.
    c	   
      C   s   d |  _ | |  _ | |  _ | |  _ xI d D]A }	 t t |  |	  t  s+ t d t |  |	  |	 |	 f   q+ W| |  _	 | |  _
 | |  _ | |  _ | |  _ t   |  _ d S(   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).
        t   readert   parsert   writers   passed string "%s" as "%s" parameter; pass an instance, or use the "%s_name" parameter instead (in docutils.core.publish_* convenience functions).N(   s   readers   parsers   writer(   t   Nonet   documentR   R   R   t
   isinstancet   getattrt   strt   AssertionErrort   sourcet   source_classt   destinationt   destination_classt   settingsR   t   _stderr(
   t   selfR   R   R   R   R   R   R   R   t	   component(    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   __init__    s    
				 					c         C   s4   t  j |  } | | |  |  _ |  j j |  _ d S(   s   Set `self.reader` by name.N(   R   t   get_reader_classR   R   (   R   t   reader_nameR   t   parser_namet   reader_class(    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt
   set_readerP   s    c         C   s   t  j |  } |   |  _ d S(   s   Set `self.writer` by name.N(   R   t   get_writer_classR   (   R   t   writer_namet   writer_class(    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt
   set_writerV   s    c         C   s   |  j  d  k r( |  j | |  j |  n  |  j d  k rn |  j  j d  k r\ |  j  j |  n  |  j  j |  _ n  |  j d  k r |  j |  n  d  S(   N(   R   R   R$   R   t
   set_parserR   R(   (   R   R!   R"   R&   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   set_components[   s    c         K   s   | ra | s t    } n  | | _ | j   } t |  d k ra | d d k ra d g | _ qa n  t d |  j |  j |  j | f d | d t	 d | d	 |  } | S(
   Ni   it   applicationt   applicationst
   componentst   defaultst   read_config_filest   usaget   description(
   R   t   config_sectiont   splitt   lent   config_section_dependenciesR	   R   R   R   t   True(   R   R0   R1   t   settings_specR2   R.   t   partst   option_parser(    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   setup_option_parsere   s    	"c         K   s1   |  j  | | | | |  } | j   |  _ |  j S(   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:   t   get_default_valuesR   (   R   R0   R1   R7   R2   R.   R9   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   get_settingsv   s    	c         C   sQ   |  j  d  k rM | p i  j   } | j d t  |  j d | d | |  n  d  S(   Nt	   tracebackR7   R2   (   R   R   t   copyt
   setdefaultR6   R<   (   R   R7   t   settings_overridesR2   R.   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   process_programmatic_settings   s    c   
      K   s   |  j  | | | | |  } | d k rz t j d } t j d k  rz t j pO d } g  | D] }	 |	 j |  ^ qY } qz n  | j |  |  _	 d S(   s   
        Pass an empty list to `argv` to avoid reading `sys.argv` (the
        default).

        Set components first (`self.set_reader` & `self.set_writer`).
        i   i   i    t   asciiN(   i   i    (
   R:   R   t   syst   argvt   version_infoR   t   locale_encodingt   decodet
   parse_argsR   (
   R   RD   R0   R1   R7   R2   R.   R9   t   argv_encodingt   a(    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   process_command_line   s    	(c         C   sH   |  j  d  k r" |  j d |  n  |  j d  k rD |  j d |  n  d  S(   Nt   source_patht   destination_path(   R   R   t
   set_sourceR   t   set_destination(   R   RL   RM   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   set_io   s    c         C   s   | d  k r |  j j } n | |  j _ y+ |  j d | d | d |  j j  |  _ Wn8 t k
 r |  j d | d | d |  j j  |  _ n Xd  S(   NR   RL   t   encoding(   R   R   t   _sourceR   t   input_encodingR   t	   TypeError(   R   R   RL   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyRN      s    		c      	   C   s^   | d  k r |  j j } n | |  j _ |  j d | d | d |  j j d |  j j  |  _ d  S(   NR   RM   RQ   t   error_handler(   R   R   t   _destinationR   t   output_encodingt   output_encoding_error_handlerR   (   R   R   RM   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyRO      s    	c         C   sH   |  j  j j |  j |  j |  j j |  j |  j f  |  j  j j   d  S(   N(	   R   t   transformert   populate_from_componentsR   R   R   R   R   t   apply_transforms(   R   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyR[      s    c         C   s  d } y |  j d k r= |  j | | | | | | p6 i   n  |  j   |  j j |  j |  j |  j  |  _ |  j	   |  j
 j |  j |  j  }	 |  j
 j   Wnx t k
 r }
 d } |
 j } nW t k
 r}
 |  j s   n  |  j j r |  j     n  |  j |
  t } d } n X|  j   | rj|  j rj|  j j j |  j j k rjt j |  j j j d  n | rt j |  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.
        i   i
   N(   R   R   RK   RP   R   t   readR   R   R   R[   R   t   writeR   t   assemble_partst
   SystemExitt   codet	   ExceptionR=   t   debugging_dumpst   report_ExceptionR6   t   reportert	   max_levelt   exit_status_levelRC   t   exit(   R   RD   R0   R1   R7   R@   R2   t   enable_exit_statusRg   t   outputt   errort   exit_status(    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   publish   s@    

	


c      	   C   sH  |  j  s d  S|  j j rE |  j d IJ|  j t j |  j j  IJn  |  j j r} |  j d IJ|  j t j |  j  j  IJn  |  j j r	|  j d IJ|  j d IJ|  j t j g  |  j  j	 j
 D]= \ } } } } | d | j | j f | o | j | f ^ q  IJn  |  j j rD|  j d IJ|  j |  j  j   j d  IJn  d  S(   Ns   
::: Runtime settings:s   
::: Document internals:s   
::: Transforms applied:s@    (priority, transform class, pending node details, keyword args)s   %s.%ss   
::: Pseudo-XML:t   raw_unicode_escape(   R   R   t   dump_settingsR   t   pprintt   pformatt   __dict__t   dump_internalst   dump_transformsRY   t   appliedt
   __module__t   __name__t   detailst   dump_pseudo_xmlt   encode(   R   t   priorityt   xclasst   pendingt   kwargs(    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyRb      s$    	Vc         C   s   t  | t j  r" |  j |  n t  | t  rA |  j |  n t  | t j  rp |  j j	 d t
 |   nm t  | t j  r |  j j	 d t
 |   n> |  j d t
 |  IJ|  j d t t t j j   d f IJd  S(   Nu-   Unable to open source file for reading:
  %s
u2   Unable to open destination file for writing:
  %s
u   %ss   Exiting due to error.  Use "--traceback" to diagnose.
Please report errors to <docutils-users@lists.sf.net>.
Include "--traceback" output, Docutils version (%s [%s]),
Python version (%s), your OS type & version, and the
command line used.i    (   R   R   t   SystemMessaget   report_SystemMessaget   UnicodeEncodeErrort   report_UnicodeErrorR   t
   InputErrorR   R]   R   t   OutputErrorR   R   RC   t   versionR3   (   R   Rj   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyRc   	  s    		c         C   s+   |  j  d | j t j j | j f IJd  S(   Ns,   Exiting due to level-%s (%s) system message.(   R   t   levelR   t   Reportert   levels(   R   Rj   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyR     s    
c      
   C   sz   | j  | j | j !} |  j j d t |  |  j j | j d d  | j d d  |  j j	 t
 t j j   d f  d  S(   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 <docutils-users@lists.sf.net>.
Include "--traceback" output, Docutils version (%s),
Python version (%s), your OS type & version, and the
command line used.
RB   t   xmlcharrefreplacet   backslashreplacei    (   t   objectt   startt   endR   R]   R   R   RW   Ry   RX   R   RC   R   R3   (   R   Rj   t   data(    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyR   $  s    				N(   Rv   Ru   t   __doc__R   R   t	   FileInputt
   FileOutputR   R$   R(   R*   R:   R<   RA   RK   RP   RN   RO   R[   t   FalseRl   Rb   Rc   R   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyR      s4   			-			
		
		'			s*   %prog [options] [<source> [<destination>]]s   Reads from <source> (default is stdin) and writes to <destination> (default is stdout).  See <http://docutils.sf.net/docs/user/config.html> for the full reference.t
   standalonet   restructuredtextt	   pseudoxmlc      
   C   sV   t  |  | | 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).
    R   R2   Rh   (   R   R*   Rl   (   R   R!   R   R"   R   R&   R   R7   R@   R2   Rh   RD   R0   R1   t   pubRi   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   publish_cmdlineH  s    c      #   C   s   t  d t j d |  d | d t j d | 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`.
    R   R   RL   R   R   RM   R   R!   R   R"   R   R&   R   R7   R@   R2   Rh   (   t   publish_programmaticallyR   R   R   (   R   RL   R   RM   R   R!   R   R"   R   R&   R   R7   R@   R2   Rh   Ri   R   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   publish_filec  s    	c      #   C   s   t  d t j d |  d | d t j d d d | 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`.
    R   R   RL   R   R   RM   R   R!   R   R"   R   R&   R   R7   R@   R2   Rh   N(   R   R   t   StringInputt   StringOutputR   (   R   RL   RM   R   R!   R   R"   R   R&   R   R7   R@   R2   Rh   Ri   R   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   publish_string}  s    	c      #   C   s   t  d |  d | d | d t j d d d | d | d | d	 | d
 | d | d |	 d |
 d | d | d | d |  \ } } | j j S(   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`.
    R   RL   R   R   R   RM   R   R!   R   R"   R   R&   R   R7   R@   R2   Rh   N(   R   R   R   R   R   R8   (   R   RL   R   RM   R   R!   R   R"   R   R&   R   R7   R@   R2   Rh   Ri   R   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   publish_parts  s    	c         C   s   t  d | d | d d	 d | d | d t j  } | j | | d  | j | |	 |
  | j |  |  | j d	 d	  | j d |  } | 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`.
    R   R   R   R   R   R   t   nullRh   N(
   R   R   R   t
   NullOutputR*   RA   RN   RO   Rl   R   (   R   RL   R   R   R!   R   R"   R   R7   R@   R2   Rh   R   Ri   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   publish_doctree  s    c	      
   C   s   t  j j j d d  }	 t |	 d | d t j |   d t j d | }
 | 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"   R   R   R   R   Rh   N(   t   docutilsR   t   doctreet   ReaderR   R   R   t   DocTreeInputR   R(   RA   RO   Rl   (   R   RM   R   R&   R   R7   R@   R2   Rh   R   R   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   publish_from_doctree  s    c      
   C   s\   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).
    R   R   R2   Rh   (   R   R*   Rl   (   R   R!   R   R"   R   R&   R   R7   R@   R2   Rh   RD   R0   R1   R   R   R   Ri   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   publish_cmdline_to_binary	  s    	c      
   C   s   t  | | |
 d | d |  d | } | j | |	 |  | j | | |  | j | |  | j | |  | j d |  } | | f S(   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
    <http://docutils.sf.net/docs/user/mailing-lists.html#docutils-develop>.

    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?
    R   R   R   Rh   (   R   R*   RA   RN   RO   Rl   (   R   R   RL   R   R   RM   R   R!   R   R"   R   R&   R   R7   R@   R2   Rh   R   Ri   (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyR   *  s    d	(%   R   t   __docformat__RC   Ro   R   R   R   R   R   R   R   R   R   t   docutils.frontendR	   t   docutils.transformsR
   t   docutils.utils.error_reportingR   R   t   docutils.readers.doctreeR   t   default_usaget   default_descriptionR   R6   R   R   R   R   R   R   R   R   t   BinaryFileOutputR   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/docutils/core.pyt   <module>   s~   ( )		#