ó
¡V]c           @   sÌ  d  Z  d Z d d l Z d d l Z d d l Z d d l Z d d l m Z m	 Z	 m
 Z
 m Z d d l m Z m Z d d l m Z d d l m Z m Z d d l m Z m Z m Z d d	 l m Z m Z d d
 l m Z d d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d e f d „  ƒ  YZ" d e f d „  ƒ  YZ# d e f d „  ƒ  YZ$ d e f d „  ƒ  YZ% d e f d „  ƒ  YZ& d S(    s   Miscellaneous directives.t   reStructuredTextiÿÿÿÿN(   t   iot   nodest   statemachinet   utils(   t
   SafeStringt   ErrorString(   t   locale_encoding(   t	   Directivet   convert_directive_function(   t
   directivest   rolest   states(   t	   CodeBlockt   NumberLines(   t   set_classes(   t   misct   Includec           B   s¸   e  Z d  Z d Z d Z e Z i e j d 6e j	 d 6e j
 d 6e d 6e d 6e d 6e j d	 6e j d
 6e j	 d 6e j d 6e j	 d 6Z e j j e j j e j ƒ d ƒ Z d „  Z RS(   s]  
    Include content read from a separate source file.

    Content may be parsed by the parser, or included as a literal
    block.  The encoding of the included file can be specified.  Only
    a part of the given file argument may be included by specifying
    start and end line or text to match before and/or after the text
    to be used.
    i   i    t   literalt   codet   encodings	   tab-widths
   start-lines   end-lines   start-afters
   end-befores   number-linest   classt   namet   includec      
   C   s   |  j  j j j s+ |  j d |  j ƒ ‚ n  |  j j j |  j	 |  j j
 d ƒ } t j j t j j | ƒ ƒ } t j |  j d ƒ } | j d ƒ rÅ | j d ƒ rÅ t j j |  j | d d !ƒ } n  t j j t j j | | ƒ ƒ } t j d | ƒ } t j | ƒ } |  j j d |  j  j j j ƒ } |  j  j j j } |  j j d |  j  j j j ƒ } y; |  j  j j j  j! | ƒ t" j# d	 | d | d
 | ƒ } Wni t$ k
 rÍ} |  j% d |  j t& | ƒ f ƒ ‚ n5 t' k
 r} |  j% d |  j t( | ƒ f ƒ ‚ n X|  j j d d ƒ }	 |  j j d d ƒ }
 yG |	 sA|
 d k	 rf| j) ƒ  } d j | |	 |
 !ƒ } n | j* ƒ  } Wn5 t+ k
 rª} |  j% d |  j t( | ƒ f ƒ ‚ n X|  j j d d ƒ } | r| j, | ƒ } | d k  rú|  j% d |  j ƒ ‚ n  | | t- | ƒ } n  |  j j d d ƒ } | rm| j, | ƒ } | d k  r`|  j% d |  j ƒ ‚ n  | |  } n  t. j/ | | d t0 ƒ} d |  j k r | d k r²| j1 | ƒ } n | } t j2 | d | d |  j j d g  ƒ ƒ} d | _3 |  j4 | ƒ d |  j k rãy t5 |  j d pd ƒ }	 Wn  t6 k
 rF|  j7 d ƒ ‚ n X|	 t- | ƒ }
 | j d ƒ rs| d  } n  t8 g  | f g |	 |
 ƒ } xh | D]G \ } } | rÆ| t j9 | | d | ƒ7} q•| t j: | | ƒ 7} q•Wn | t j: | | ƒ 7} | g Sd |  j k r‰| |  j d <| d k  r7| j; ƒ  } n  t< |  j |  j j= d ƒ g |  j | |  j	 |  j> |  j? |  j  |  j ƒ	 } | j@ ƒ  S|  j jA | | ƒ g  S(   s8   Include a file as part of the content of this reST file.s   "%s" directive disabled.i   i    t   <t   >iÿÿÿÿR   s	   tab-widtht   source_patht   error_handleruV   Problems with "%s" directive path:
Cannot encode input file path "%s" (wrong locale?).u&   Problems with "%s" directive path:
%s.s
   start-lines   end-linet    u   Problem with "%s" directive:
%ss   start-aftersD   Problem with "start-after" option of "%s" directive:
Text not found.s
   end-beforesC   Problem with "end-before" option of "%s" directive:
Text not found.t   convert_whitespaceR   t   sourcet   classesR   s   number-liness+   :number-lines: with non-integer start values   
R   N(B   t   statet   documentt   settingst   file_insertion_enabledt   warningR   t   state_machinet   input_linesR   t   linenot   input_offsett   ost   patht   dirnamet   abspathR
   t	   argumentst
   startswitht   endswitht   joint   standard_include_patht   normpathR   t   relative_patht   NoneR   t   reprunicodet   optionst   gett   input_encodingt   input_encoding_error_handlert	   tab_widtht   record_dependenciest   addR   t	   FileInputt   UnicodeEncodeErrort   severeR   t   IOErrorR   t	   readlinest   readt   UnicodeErrort   findt   lenR   t   string2linest   Truet
   expandtabst   literal_blockt   linet   add_namet   intt
   ValueErrort   errorR   t   inlinet   Textt
   splitlinesR   t   popt   content_offsett
   block_textt   runt   insert_input(   t   selfR   t
   source_dirR*   R   t	   e_handlerR:   t   include_fileRN   t	   startlinet   endlinet   linest   rawtextt
   after_textt   after_indext   before_textt   before_indext   include_linest   textRI   t   tokensR   t   valuet	   codeblock(    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRU   5   sº    "!										
(   t   __name__t
   __module__t   __doc__t   required_argumentst   optional_argumentsRG   t   final_argument_whitespaceR
   t   flagt	   unchangedR   RL   t   unchanged_requiredt   class_optiont   option_specR)   R*   R0   R+   R   t   __file__R1   RU   (    (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyR      s$   






	t   Rawc           B   sS   e  Z d  Z d Z d Z e Z i e j d 6e j	 d 6e j
 d 6Z e Z d „  Z RS(   sÉ   
    Pass through content unchanged

    Content is included in output based on type argument

    Content may be included inline (content section of directive) or
    imported from a file or url.
    i   i    t   filet   urlR   c      	   C   s½  |  j  j j j sD |  j  j j j r] d |  j k sD d |  j k r] |  j d |  j ƒ ‚ n  i d j |  j	 d j
 ƒ  j ƒ  ƒ d 6} |  j j d |  j  j j j ƒ } |  j  j j j } |  j rd |  j k sà d |  j k rù |  j d |  j ƒ ‚ n  d	 j |  j ƒ } nrd |  j k rnd |  j k rE|  j d
 |  j ƒ ‚ n  t j j t j j |  j  j j ƒ ƒ } t j j t j j | |  j d ƒ ƒ } t j d  | ƒ } y; t j d | d | d | ƒ } |  j  j j j j | ƒ Wn5 t k
 r} |  j d |  j t  | ƒ f ƒ ‚ n Xy | j! ƒ  } Wn5 t" k
 r`} |  j d |  j t  | ƒ f ƒ ‚ n X| | d <nd |  j k rv|  j d }	 d d  l# }
 y |
 j$ |	 ƒ j! ƒ  } WnK |
 j% t t& f k
 rü} |  j d |  j |  j d t  | ƒ f ƒ ‚ n Xt j' d | d |	 d | d | ƒ } y | j! ƒ  } Wn5 t" k
 rh} |  j d |  j t  | ƒ f ƒ ‚ n X|	 | d <n
 |  j( ƒ  t) j* d | |  } |  j+ j, |  j- ƒ \ | _. | _/ | g S(   NRu   Rv   s   "%s" directive disabled.t    i    t   formatR   sF   "%s" directive may not both specify an external file and have content.s   
sX   The "file" and "url" options may not be simultaneously specified for the "%s" directive.R   R   u&   Problems with "%s" directive path:
%s.u   Problem with "%s" directive:
%sR   iÿÿÿÿu*   Problems with "%s" directive URL "%s":
%s.R   (0   R    R!   R"   t   raw_enabledR#   R6   R$   R   R0   R-   t   lowert   splitR7   R8   R9   t   contentRN   R)   R*   R+   R,   t   current_sourceR2   R   R3   R4   R   R=   R;   R<   R@   R?   R   RB   RC   t   urllib2t   urlopent   URLErrort   OSErrort   StringInputt   assert_has_contentR   t   rawR%   t   get_source_and_lineR'   R   RJ   (   RW   t
   attributesR   RY   Rd   RX   R*   t   raw_fileRN   R   R~   t   raw_textt   raw_node(    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRU   ·   sx    )							'		
!(   Rh   Ri   Rj   Rk   Rl   RG   Rm   R
   R*   t   uriR   Rr   t   has_contentRU   (    (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRt   ¤   s   	
t   Replacec           B   s   e  Z e Z d  „  Z RS(   c         C   s  t  |  j t j ƒ s. |  j d |  j ƒ ‚ n  |  j ƒ  d j |  j ƒ } t	 j
 | ƒ } |  j j |  j |  j | ƒ d  } g  } x‚ | D]z } | r° t  | t	 j ƒ r° | } qˆ t  | t	 j ƒ rÜ g  | d <| j | ƒ qˆ |  j j j d |  j d |  j ƒg Sqˆ W| r| | j S| S(   NsV   Invalid context: the "%s" directive can only be used within a substitution definition.s   
t   backrefss=   Error in "%s" directive: may contain a single paragraph only.RJ   (   t
   isinstanceR    R   t   SubstitutionDefRN   R   Rƒ   R0   R|   R   t   Elementt   nested_parseRS   R4   t	   paragrapht   system_messaget   appendR%   t   reporterR'   t   children(   RW   Rd   t   elementt   nodet   messagest   elem(    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRU     s.    
	
(   Rh   Ri   RG   R‹   RU   (    (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRŒ   þ   s   t   Unicodec           B   s\   e  Z d  Z d Z d Z e Z i e j d 6e j d 6e j d 6Z	 e
 j d ƒ Z d „  Z RS(   s{  
    Convert Unicode character codes (numbers) to characters.  Codes may be
    decimal numbers, hexadecimal numbers (prefixed by ``0x``, ``x``, ``\x``,
    ``U+``, ``u``, or ``\u``; e.g. ``U+262E``), or XML-style numeric character
    entities (e.g. ``&#x262E;``).  Text following ".." is a comment and is
    ignored.  Spaces are ignored, and any other text remains as-is.
    i   i    t   trimt   ltrimt   rtrims   ( |\n|^)\.\. c         C   sR  t  |  j t j ƒ s. |  j d |  j ƒ ‚ n  |  j j } d |  j k rf d | j	 d <d | j	 d <n  d |  j k r… d | j	 d <n  d |  j k r¤ d | j	 d <n  |  j
 j |  j d ƒ d j ƒ  } t j ƒ  } xu | D]m } y t j | ƒ } Wn2 t k
 r'} |  j d | t | ƒ f ƒ ‚ n X| t j t j | ƒ | ƒ 7} qÚ W| j S(   NsV   Invalid context: the "%s" directive can only be used within a substitution definition.Rœ   i   R   Rž   i    u   Invalid character code: %s
%s(   RŽ   R    R   R   RN   R   R%   R˜   R6   R†   t   comment_patternR{   R-   R   R   R
   t   unicode_codeRM   R   RP   R   t   unescapeR–   (   RW   t   substitution_definitiont   codesR—   R   t   decodedRN   (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRU   1  s,    #	#(   Rh   Ri   Rj   Rk   Rl   RG   Rm   R
   Rn   Rr   t   ret   compileRŸ   RU   (    (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyR›     s   
t   Classc           B   s/   e  Z d  Z d Z d Z e Z e Z d „  Z RS(   s¿   
    Set a "class" attribute on the directive content or the next element.
    When applied to the next element, a "pending" element is inserted, and a
    transform does the work later.
    i   i    c         C   s  y t  j |  j d ƒ } Wn4 t k
 rP |  j d |  j |  j d f ƒ ‚ n Xg  } |  j r½ t j ƒ  } |  j	 j
 |  j |  j | ƒ x | D] } | d j | ƒ q W| j | j ƒ nL t j t j i | d 6|  j d 6|  j ƒ } |  j j j | ƒ | j | ƒ | S(   Ni    s7   Invalid class attribute value for "%s" directive: "%s".R   R   t	   directive(   R
   Rq   R-   RM   RN   R   R|   R   R   R    R‘   RS   t   extendR–   t   pendingR   t   ClassAttributeRT   R%   R!   t   note_pendingR”   (   RW   t   class_valuet	   node_listt	   containerR˜   Rª   (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRU   W  s*    	(	   Rh   Ri   Rj   Rk   Rl   RG   Rm   R‹   RU   (    (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyR§   J  s   t   Rolec           B   s7   e  Z e Z e j d  e j j f d ƒ Z	 d „  Z
 RS(   s   (%s)\s*(\(\s*(%s)\s*\)\s*)?$i   c         C   s®  |  j  |  j k s |  j r5 |  j d |  j ƒ ‚ n  |  j d } |  j j | ƒ } | sy |  j d |  j | f ƒ ‚ n  | j d ƒ } | j d ƒ } g  } | r!t j	 | |  j
 j |  j |  j j ƒ \ } } | d k r*|  j j j d | t j |  j |  j ƒ d |  j ƒ} | | g Sn	 t j } t | d ƒ sSt d	 |  j | f ƒ ‚ yD t | ƒ } |  j j |  j d |  j  | d
 i  ƒ\ }	 }
 } } Wn^ t j k
 r÷} |  j
 j j d |  j | f t j |  j |  j ƒ d |  j ƒ} | | g SXd |
 k r‚y t j | ƒ |
 d <Wq‚t k
 r~} |  j
 j j d |  j t | ƒ f t j |  j |  j ƒ d |  j ƒ} | | g SXn  t j | | |
 | ƒ } t j | | ƒ | S(   s?   Dynamically create and register a custom interpreted text role.s4   "%s" directive requires arguments on the first line.i    s4   "%s" directive arguments not valid role names: "%s".i   i   s#   Unknown interpreted text role "%s".RJ   R-   s[   Supplemental directive arguments for "%s" directive not supported (specified by "%r" role).t   option_presetss   Error in "%s" directive:
%s.R   u(   Invalid argument for "%s" directive:
%s.N(   RS   R'   R|   RN   R   t   argument_patternt   matcht   groupR   t   roleR%   t   languageR    R•   R4   R   RI   RT   t   generic_custom_rolet   hasattrt   AssertionErrorR	   t   parse_directive_blockR   t   MarkupErrorR
   Rq   RM   R   t
   CustomRolet   register_local_role(   RW   t   argsR³   t   new_role_namet   base_role_nameR™   t	   base_roleRN   t   converted_roleR-   R6   R|   RS   t   detailRµ   (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRU   w  s`    				(   Rh   Ri   RG   R‹   R¥   R¦   R   t   Inlinert
   simplenameR²   RU   (    (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyR°   p  s   	t   DefaultRolec           B   s#   e  Z d  Z d Z e Z d „  Z RS(   s&   Set the default interpreted text role.i   c         C   sÂ   |  j  s) d t j k r% t j d =n  g  S|  j  d } t j | |  j j |  j |  j j ƒ \ } } | d  k r± |  j j j
 d | t j |  j |  j ƒ d |  j ƒ} | | g S| t j d <| S(   NR   i    s#   Unknown interpreted text role "%s".RJ   (   R-   R   t   _rolesRµ   R%   R¶   R'   R    R•   R4   RN   R   RI   RT   (   RW   t	   role_nameRµ   R™   RN   (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRU   ´  s    	(   Rh   Ri   Rj   Rl   t   FalseRm   RU   (    (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRÆ   ­  s   t   Titlec           B   s#   e  Z d  Z d Z e Z d „  Z RS(   i   i    c         C   s   |  j  d |  j j d <g  S(   Ni    t   title(   R-   R%   R!   (   RW   (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRU   Í  s    (   Rh   Ri   Rk   Rl   RG   Rm   RU   (    (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRÊ   Ç  s   t   Datec           B   s   e  Z e Z d  „  Z RS(   c         C   s'  t  |  j t j ƒ s. |  j d |  j ƒ ‚ n  d j |  j ƒ pC d } t j	 d
 k  r˜ y | j
 t pg d ƒ } Wq˜ t k
 r” |  j d t ƒ ‚ q˜ Xn  t j | ƒ } t j	 d k  ry | j t pÈ d ƒ } Wqt k
 r| j t pî d d ƒ } |  j d	 | t f ƒ ‚ qXn  t j | ƒ g S(   NsV   Invalid context: the "%s" directive can only be used within a substitution definition.s   
s   %Y-%m-%di   i    s   utf-8u;   Cannot encode date format string with locale encoding "%s".t   replaceu-   Error decoding "%s"with locale encoding "%s".(   i   i    (   i   i    (   RŽ   R    R   R   RN   R   R0   R|   t   syst   version_infot   encodeR   R>   R$   t   timet   strftimet   decodet   UnicodeDecodeErrorR   RP   (   RW   t
   format_strRd   (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRU   Ö  s(    		(   Rh   Ri   RG   R‹   RU   (    (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRÌ   Ò  s   t   TestDirectivec           B   s9   e  Z d  Z d Z e Z i e j d 6Z e Z	 d „  Z
 RS(   s3   This directive is useful only for testing purposes.i   t   optionc         C   sœ   |  j  ra d j |  j  ƒ } |  j j j d |  j |  j |  j f t j	 | | ƒ d |  j
 ƒ} n4 |  j j j d |  j |  j |  j f d |  j
 ƒ} | g S(   Ns   
sB   Directive processed. Type="%s", arguments=%r, options=%r, content:RJ   sG   Directive processed. Type="%s", arguments=%r, options=%r, content: None(   R|   R0   R%   R•   t   infoR   R-   R6   R   RI   R'   (   RW   Rd   RØ   (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRU   	  s    	!(   Rh   Ri   Rj   Rl   RG   Rm   R
   Rp   Rr   R‹   RU   (    (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyRÖ      s   ('   Rj   t   __docformat__RÎ   t   os.pathR)   R¥   RÑ   t   docutilsR   R   R   R   t   docutils.utils.error_reportingR   R   R   t   docutils.parsers.rstR   R	   R
   R   R   t$   docutils.parsers.rst.directives.bodyR   R   t   docutils.parsers.rst.rolesR   t   docutils.transformsR   R   Rt   RŒ   R›   R§   R°   RÆ   RÊ   RÌ   RÖ   (    (    (    sC   lib/python2.7/site-packages/docutils/parsers/rst/directives/misc.pyt   <module>   s.   "ŽZ ,&=.