ó
…¥¡Lc           @   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	 d d l m
 Z
 m Z d d l m Z m Z d d l m Z m Z m Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d Z d d „ Z d S(   sø   
Transforms for PEP processing.

- `Headers`: Used to transform a PEP's initial RFC-2822 header.  It remains a
  field list, but some entries get processed.
- `Contents`: Auto-inserts a table of contents.
- `PEPZero`: Special processing for PEP 0.
t   reStructuredTextiÿÿÿÿN(   t   nodest   utilst	   languages(   t   ApplicationErrort	   DataError(   t	   Transformt   TransformError(   t   partst
   referencest   misct   Headersc           B   sY   e  Z d  Z d Z d Z d Z e j d e j ƒ d f e j d ƒ d f f Z	 d „  Z
 RS(   s<   
    Process fields in a PEP's initial RFC-2822 header.
    ih  s   pep-%04ds=   http://svn.python.org/view/*checkout*/peps/trunk/pep-%04d.txts   \$RCSfile: (.+),v \$$s   \1s   \$[a-zA-Z]+: (.+) \$$c      
   C   sb  t  |  j ƒ s t d ƒ ‚ n  |  j d } t | t j ƒ sN d | d k r] t d ƒ ‚ n  d  } x-| D]%} | d j ƒ  j ƒ  d k rj | d j ƒ  } y t	 | ƒ } |  j
 | } WnÏ t k
 rŠ| } d  } |  j j j d | d	 | ƒ} |  j j | ƒ } t j | | pd
 d | ƒ} |  j j | ƒ }	 | j |	 ƒ t  | d ƒ rh| g | d d (q‹| d c t j d d | ƒ 7<n XPqj qj W| d  k r®t d ƒ ‚ n  | d k rït j t ƒ }
 |  j j d |
 ƒ |  j j |
 ƒ n  t  | ƒ d k  s!| d d j ƒ  j ƒ  d k r0t d ƒ ‚ n  x+| D]#} | d j ƒ  j ƒ  } | d } t  | ƒ d k rŽt d | j d d ƒ ƒ ‚ n¿ t  | ƒ d k rØt | d t j ƒ sMt d | j d d ƒ ƒ ‚ qMnu | d k r7t j d t j t j |  j d ƒ d ƒ ƒ } | rM| t j d d t j d | d | ƒƒ 7} qMn q7| d } | d k rŸxô| D]. } t | t j ƒ rj| j t | ƒ ƒ qjqjWq7| d k rêx¬| D]1 } t | t j ƒ r²| j t | | ƒ ƒ q²q²Wq7| d$ k rˆg  } t j d ƒ } xl t  j! d | j ƒ  ƒ D]R } t	 | ƒ } | j" t j | | d |  j j# j$ |  j% | ƒƒ | j" | ƒ q$W| d   | (q7| d k rÛt& j' | |  j( ƒ | rZ| j ƒ  } t j d | d | ƒg | (qZq7| d! k r,| j ƒ  } |  j j# j$ |  j% d" } t j d | d | ƒg | (q7| d# k r7t  | ƒ r7t& j' | |  j( ƒ q7q7Wd  S(%   Ns   Document tree is empty.i    t   rfc2822t   classessA   Document does not begin with an RFC-2822 header; it is not a PEP.t   pepi   s?   "PEP" header must contain an integer; "%s" is an invalid value.t	   base_nodes   (none)t   refidt    s3   Document does not contain an RFC-2822 "PEP" header.i   t   titles	   No title!s4   PEP header field body contains multiple elements:
%st   levels=   PEP header field body may only contain a single paragraph:
%ss   last-modifieds   %d-%b-%Yt   sourcei   t   refurit   authors   discussions-tot   replacess   replaced-byt   requirest    s   ,?\s+iÿÿÿÿs   content-typei   t   version(   R   s   replaced-byR   ()   t   lent   documentR   t
   isinstanceR   t
   field_listt   Nonet   astextt   lowert   intt   pep_cvs_urlt
   ValueErrort   reportert   warningt   set_idt   problematict   add_backreft	   paragrapht   pendingt   PEPZerot   insertt   note_pendingt   pformatt   timet   strftimet	   localtimet   ost   statt	   referencet   replace_selft
   mask_emailt   Textt   ret   splitt   appendt   settingst   pep_base_urlt   pep_urlR   t   clean_rcs_keywordst   rcs_keyword_substitutions(   t   selft   headerR   t   fieldt   valuet   cvs_urlt   msgt   msgidt   prbt   prbidR+   t   namet   bodyt   datet   parat   nodet   newbodyt   spacet   refpept   pepnot   pep_typet   uri(    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyt   apply)   sª    	#2
&	(
 	"(   t   __name__t
   __module__t   __doc__t   default_priorityR>   R#   R9   t   compilet
   IGNORECASER@   RU   (    (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyR      s   t   Contentsc           B   s   e  Z d  Z d Z d „  Z RS(   s~   
    Insert an empty table of contents topic and a transform placeholder into
    the document after the RFC 2822 header.
    i|  c         C   sã   t  j |  j j j |  j j ƒ } | j d } t j d | ƒ } t j	 d | d d g ƒ} t j
 | ƒ } |  j j | ƒ s | d j | ƒ n  |  j j | ƒ t j t j ƒ } | | 7} |  j j d | ƒ |  j j | ƒ d  S(   Nt   contentsR   R   t   namesi   (   R   t   get_languageR   R<   t   language_codeR%   t   labelsR   R   t   topict   fully_normalize_namet   has_nameR;   t   note_implicit_targetR+   R   R\   R-   R.   (   RA   t   languageRJ   R   Rb   R+   (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyRU   ’   s    
(   RV   RW   RX   RY   RU   (    (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyR\   ‰   s   t   TargetNotesc           B   s&   e  Z d  Z d Z d „  Z d „  Z RS(   s¶   
    Locate the "References" section, insert a placeholder for an external
    target footnote insertion transform at the end, and schedule the
    transform to run immediately.
    i  c         C   s{  |  j  } t | ƒ d } d  } } x | d k r¤ t | | t j ƒ r¤ | | d j ƒ  j ƒ  j ƒ  } d | k r‚ | | } Pn d | k r— | } n  | d 8} q& W| st j ƒ  } | t j	 d d ƒ 7} | j
 | ƒ | ró | j | | ƒ q| j | ƒ n  t j t j ƒ } | j | ƒ |  j  j | d ƒ t j t j d i |  j d 6ƒ} | j | ƒ |  j  j | d ƒ d  S(	   Ni   i    R	   t	   copyrightR   t
   Referencest   detailst   callback(   R   R   R   R   R   t   sectionR    R!   R:   R   R'   R-   R;   R+   R	   Rg   R.   R
   t   CallBackt   cleanup_callback(   RA   t   doct   it   refsectRh   t   title_wordsR+   (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyRU   ¬   s2    	
% 
	c         C   s2   t  | j ƒ d k r. | j j j | j ƒ n  d S(   s   
        Remove an empty "References" section.

        Called after the `references.TargetNotes` transform is complete.
        i   N(   R   t   parentt   remove(   RA   R+   (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyRn   Ê   s    (   RV   RW   RX   RY   RU   Rn   (    (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyRg   ¢   s   	R,   c           B   s   e  Z d  Z d Z d „  Z RS(   s'   
    Special processing for PEP 0.
    iø  c         C   s9   t  |  j ƒ } |  j j | ƒ |  j j j |  j ƒ d  S(   N(   t   PEPZeroSpecialR   t   walkt	   startnodeRs   Rt   (   RA   t   visitor(    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyRU   Ü   s    (   RV   RW   RX   RY   RU   (    (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyR,   Ô   s   Ru   c           B   sV   e  Z d  Z e j Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(   s´   
    Perform the special processing needed by PEP 0:

    - Mask email addresses.

    - Link PEP numbers in the second column of 4-column tables to the PEPs
      themselves.
    c         C   s   d  S(   N(    (   RA   RN   (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyt   unknown_visitï   s    c         C   s   | j  t | ƒ ƒ d  S(   N(   R6   R7   (   RA   RN   (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyt   visit_referenceò   s    c         C   s    d | d k r t  j ‚ n  d  S(   NR   R   (   R   t   SkipNode(   RA   RN   (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyt   visit_field_listõ   s    c         C   s    | d d k |  _  d |  _ d  S(   Nt   colsi   i    (   t	   pep_tablet   entry(   RA   RN   (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyt   visit_tgroupù   s    c         C   s?   |  j  d 7_  |  j r; |  j  d k r; | d j d ƒ n  d  S(   Ni   i   R   t   num(   R   R~   R;   (   RA   RN   (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyt   visit_colspecý   s    c         C   s   d |  _  d  S(   Ni    (   R   (   RA   RN   (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyt	   visit_row  s    c         C   sè   |  j  d 7_  |  j rä |  j  d k rä t | ƒ d k rä | d j d ƒ | d } t | t j ƒ rä t | ƒ d k rä | j ƒ  } yF t | ƒ } |  j	 j
 j |  j | } t j | | d | ƒ| d <Wqá t k
 rÝ qá Xqä n  d  S(   Ni   i   R   R   i    R   (   R   R~   R   R;   R   R   R*   R    R"   R   R<   R=   R>   R5   R$   (   RA   RN   t   pt   textR   t   ref(    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyt   visit_entry  s    *
$ (   RV   RW   RX   R   R>   Ry   Rz   R|   R€   R‚   Rƒ   R‡   (    (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyRu   â   s   								s   peps@python.orgs   python-list@python.orgs   python-dev@python.orgc         C   s°   |  j  d ƒ r¨ |  d j d ƒ r¨ |  d d t k rC |  d } n0 |  j ƒ  j d d ƒ } t j d | d d	 ƒ} | d k rƒ | S|  d c d
 | 7<| g |  (|  Sn |  Sd S(   s¨  
    Mask the email address in `ref` and return a replacement node.

    `ref` is returned unchanged if it contains no email address.

    For email addresses such as "user@host", mask the address as "user at
    host" (text) to thwart simple email address harvesters (except for those
    listed in `non_masked_addresses`).  If a PEP number (`pepno`) is given,
    return a reference including a default email subject.
    R   s   mailto:i   i    t   @s   &#32;&#97;t&#32;R   t   formatt   htmls   ?subject=PEP%%20%sN(   t   hasattrt
   startswitht   non_masked_addressesR    t   replaceR   t   rawR   (   R†   RR   t   replacementt   replacement_text(    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyR7     s    "
(   s   peps@python.orgs   python-list@python.orgs   python-dev@python.org(   RX   t   __docformat__t   sysR3   R9   R0   t   docutilsR   R   R   R   R   t   docutils.transformsR   R   R   R	   R
   R   R\   Rg   R,   t   SparseNodeVisitorRu   R   R   R7   (    (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/peps.pyt   <module>   s$   o23  