
4Qc           @   s  d  Z  d Z d d l Z d d l Z d d l Z d d l m Z d d l m Z	 e j
 d k  rr d d l m Z n  i+ d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d d" 6d d$ 6d d& 6d d( 6d d* 6d d, 6d d. 6d d0 6d d2 6d d4 6d d6 6d d9 6d d; 6d d= 6d d@ 6d dB 6d dE 6d dG 6d dI 6d dK 6d dN 6d dQ 6d dT 6d dV 6d dX 6d dZ 6d d\ 6d d^ 6d d` 6d db 6d dd 6d df 6Z i  Z dg   Z dh   Z di   Z dj   Z dk   Z dl   Z dm   Z dn   Z do   Z dp dq dr ds dt du dv dw g Z dx   Z dy   Z dz d{  Z d|   Z e j d} e j  Z d~   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d S(   s9   
This package contains directive implementation modules.
t   reStructuredTextiN(   t   nodes(   t   eni   i   (   t
   __import__t   admonitionst	   Attentiont	   attentiont   Cautiont   cautiont   bodyt	   CodeBlockt   codet   Dangert   dangert   Errort   errort	   Importantt	   importantt   Notet   notet   Tipt   tipt   Hintt   hintt   Warningt   warningt
   Admonitiont
   admonitiont   Sidebart   sidebart   Topict   topict	   LineBlocks
   line-blockt   ParsedLiterals   parsed-literalt	   MathBlockt   matht   Rubrict   rubrict   Epigrapht   epigrapht
   Highlightst
   highlightst	   PullQuotes
   pull-quotet   Compoundt   compoundt	   Containert	   containert   tablest   RSTTablet   tablet   CSVTables	   csv-tablet	   ListTables
   list-tablet   imagest   Imaget   imaget   Figuret   figuret   partst   Contentst   contentst   Sectnumt   sectnumt   Headert   headert   Footert   footert
   referencest   TargetNotess   target-notest   htmlt   Metat   metat   misct   Rawt   rawt   Includet   includet   Replacet   replacet   Unicodet   unicodet   Classt   classt   Rolet   rolet   DefaultRoles   default-rolet   Titlet   titlet   Datet   datet   TestDirectives   restructuredtext-test-directivec         C   s>  |  j    } g  } g  } | t k r2 t | | f Sd } y | j | } WnT t k
 ru } | j d | | f  n+ t k
 r | j d |  | j f  n X| s y" t j | } | j d |   Wq t k
 r | j d |   | } q Xn  | r0| j	 j
 d j |  d | j } | j |  n  y t | \ }	 }
 Wn t k
 r^d | f SXy" t |	 t   t   d d } WnI t k
 r} | j | j	 j d	 |	 |  | f d | j  d | f SXy t | |
  } | t | <WnG t k
 r3| j | j	 j d
 |
 |	 |  f d | j  d | f SX| | f S(   s   
    Locate and return a directive function from its language-dependent name.
    If not found in the current language, check English.  Return None if the
    named directive cannot be found.
    s?   Problem retrieving directive entry from language module %r: %s.s+   No directive entry for "%s" in module "%s".s*   Using English fallback for directive "%s".s(   Trying "%s" as canonical directive name.s   
t   linet   leveli   s:   Error importing directive module "%s" (directive "%s"):
%ss8   No directive class "%s" in module "%s" (directive "%s").N(   t   lowert   _directivest   Nonet
   directivest   AttributeErrort   appendt   KeyErrort   __name__t   _fallback_language_modulet   reportert   infot   joint   current_linet   _directive_registryR   t   globalst   localst   ImportErrorR   t   getattr(   t   directive_namet   language_modulet   documentt   normnamet   messagest   msg_textt   canonicalnameR   t   messaget
   modulenamet	   classnamet   modulet   detailt	   directive(    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyRz   L   sb    					"c         C   s   | t  |  <d S(   s   
    Register a nonstandard application-defined directive function.
    Language lookups are not needed for such functions.
    N(   R]   (   t   nameRz   (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   register_directive   s    c         C   s-   |  r% |  j    r% t d |    n d Sd S(   s   
    Check for a valid flag option (no argument) and return ``None``.
    (Directive option conversion function.)

    Raise ``ValueError`` if an argument is found.
    s%   no argument is allowed; "%s" suppliedN(   t   stript
   ValueErrorR^   (   t   argument(    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   flag   s    c         C   s#   |  d k r t d   n |  Sd S(   s   
    Return the argument text, unchanged.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    s#   argument required but none suppliedN(   R^   R~   (   R   (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   unchanged_required   s    c         C   s   |  d k r d S|  Sd S(   s   
    Return the argument text, unchanged.
    (Directive option conversion function.)

    No argument implies empty string ("").
    u    N(   R^   (   R   (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt	   unchanged   s    c         C   sQ   |  d k r t d   n2 d j g  |  j   D] } | j   ^ q.  } | Sd S(   s   
    Return the path argument unwrapped (with newlines removed).
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    s#   argument required but none suppliedt    N(   R^   R~   Rg   t
   splitlinesR}   (   R   t   st   path(    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyR      s    .c         C   s8   |  d k r t d   n d j |  j    } | Sd S(   s   
    Return the URI argument with whitespace removed.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    s#   argument required but none suppliedR   N(   R^   R~   Rg   t   split(   R   t   uri(    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyR      s    c         C   s+   t  |   } | d k  r' t d   n  | S(   s|   
    Check for a nonnegative integer argument; raise ``ValueError`` if not.
    (Directive option conversion function.)
    i    s(   negative value; must be positive or zero(   t   intR~   (   R   t   value(    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   nonnegative_int   s    c         C   s1   y |  j  d  }  Wn t k
 r& n Xt |   S(   sK   
    Check for an integer percentage value with optional percent sign.
    s    %(   t   rstripR`   R   (   R   (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt
   percentage   s
    t   emt   ext   pxt   int   cmt   mmt   ptt   pcc         C   s   t  j d d j |  |   } y t | j d   WnG t t f k
 r t d d j g  | D] } d | ^ q_    n X| j d  | j d  S(   s   
    Check for a positive argument of one of the units and return a
    normalized string of the form "<value><unit>" (without space in
    between).

    To be called from directive option conversion functions.
    s   ^([0-9.]+) *(%s)$t   |i   s8   not a positive measure of one of the following units:
%st    s   "%s"i   (   t   ret   matchRg   t   floatt   groupR`   R~   (   R   t   unitsR   t   i(    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   get_measure   s    .c         C   s   t  |  t d g  S(   NR   (   R   t   length_units(   R   (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   length_or_unitless   s    R   c         C   sm   y t  |  t d g  SWnN t k
 rh y t  |  d g  | SWqi t k
 rd t  |  t d g  SXn Xd S(   s  
    Return normalized string of a length or percentage unit.

    Add <default> if there is no unit. Raise ValueError if the argument is not
    a positive measure of one of the valid CSS units (or without unit).

    >>> length_or_percentage_or_unitless('3 pt')
    '3pt'
    >>> length_or_percentage_or_unitless('3%', 'em')
    '3%'
    >>> length_or_percentage_or_unitless('3')
    '3'
    >>> length_or_percentage_or_unitless('3', 'px')
    '3px'
    t   %R   N(   R   R   R~   (   R   t   default(    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt    length_or_percentage_or_unitless   s    c         C   sw   |  d k r t d   n  |  j   } g  } xC | D]; } t j |  } | sb t d |   n  | j |  q4 W| S(   s   
    Convert the argument into a list of ID-compatible strings and return it.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    s#   argument required but none supplieds"   cannot make "%s" into a class nameN(   R^   R~   R   R   t   make_idRa   (   R   t   namest   class_namesR{   t
   class_name(    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   class_option  s    s2   (?:0x|x|\\x|U\+?|\\u)([0-9a-f]+)$|&#x([0-9a-f]+);$c         C   s   yj |  j    r t t |    St j |   } | re | j d  pO | j d  } t t | d   S|  SWn# t k
 r } t d |   n Xd S(   s  
    Convert a Unicode character code to a Unicode character.
    (Directive option conversion function.)

    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;``).  Other text remains as-is.

    Raise ValueError for illegal Unicode code values.
    i   i   i   s   code too large (%s)N(   t   isdigitt   unichrR   t   unicode_patternR   R   t   OverflowErrorR~   (   R   R   R   Ry   (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   unicode_code#  s    c         C   s5   t  |   } t |  d k r1 t d |   n  | S(   s   
    A single character is returned as-is.  Unicode characters codes are
    converted as in `unicode_code`.  (Directive option conversion function.)
    i   s8   %r invalid; must be a single character or a Unicode code(   R   t   lenR~   (   R   t   char(    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   single_char_or_unicode;  s
    c         C   s:   |  d k r d } n! |  d k r* d } n t  |   } | S(   s   
    As with `single_char_or_unicode`, but "tab" and "space" are also supported.
    (Directive option conversion function.)
    t   tabs   	t   spaceR   (   R   (   R   R   (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt$   single_char_or_whitespace_or_unicodeF  s    		c         C   s+   t  |   } | d k  r' t d   n  | S(   s   
    Converts the argument into an integer.  Raises ValueError for negative,
    zero, or non-integer values.  (Directive option conversion function.)
    i   s(   negative or zero value; must be positive(   R   R~   (   R   R   (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   positive_intS  s    c         C   sG   d |  k r |  j  d  } n |  j    } g  | D] } t |  ^ q1 S(   s   
    Converts a space- or comma-separated list of values into a Python list
    of integers.
    (Directive option conversion function.)

    Raises ValueError for non-positive-integer values.
    t   ,(   R   R   (   R   t   entriest   entry(    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   positive_int_list]  s    c         C   s9   y t  j |   Wn! t k
 r4 t d |    n X|  S(   s   
    Verfies the encoding argument by lookup.
    (Directive option conversion function.)

    Raises ValueError for unknown encodings.
    s   unknown encoding: "%s"(   t   codecst   lookupt   LookupErrorR~   (   R   (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   encodingk  s
    c         C   sp   y |  j    j   } Wn' t k
 r? t d t |    n X| | k rP | St d |  t |  f   d S(   s  
    Directive option utility function, supplied to enable options whose
    argument must be a member of a finite set of possible values (must be
    lower case).  A custom conversion function must be written to use it.  For
    example::

        from docutils.parsers.rst import directives

        def yesno(argument):
            return directives.choice(argument, ('yes', 'no'))

    Raise ``ValueError`` if no argument is found or if the argument's value is
    not valid (not an entry in the supplied list).
    s'   must supply an argument; choose from %ss   "%s" unknown; choose from %sN(   R\   R}   R`   R~   t   format_values(   R   t   valuesR   (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   choicex  s    c         C   s6   d d j  g  |  d  D] } d | ^ q  |  d f S(   Ns   %s, or "%s"s   , is   "%s"(   Rg   (   R   R   (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyR     s    *(   i   i   (   R   R   (   R   R   (   R	   R
   (   R   R   (   R   s   Error(   R   R   (   R   R   (   R   R   (   R   R   (   R   s   Warning(   R   R   (   R	   R   (   R	   R   (   R	   R    (   R	   R!   (   R	   R"   (   R	   R$   (   R	   R&   (   R	   R(   (   R	   R*   (   R	   R+   (   R	   s	   Container(   R/   R0   (   R/   R2   (   R/   R3   (   R4   R5   (   R4   R7   (   s   partsR:   (   s   partsR<   (   s   partsR>   (   s   partsR@   (   RB   RC   (   RD   RE   (   RG   RH   (   RG   s   Include(   RG   RL   (   RG   RN   (   RG   RP   (   RG   RR   (   RG   RT   (   RG   RU   (   RG   RW   (   RG   RY   ((   t   __doc__t   __docformat__R   R   t   syst   docutilsR   t   docutils.parsers.rst.languagesR   Rd   t   version_infot   docutils._compatR   Ri   R]   Rz   R|   R   R   R   R   R   R   R   R   R   R   R   R   t   compilet
   IGNORECASER   R   R   R   R   R   R   R   R   (    (    (    sL   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/directives/__init__.pyt   <module>   s   
	:							
	
							
			