B
    ƒ@LX0+  ã               @   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 G dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dejƒZdZddd„ZdS )zø
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.
ZreStructuredTexté    N)ÚnodesÚutilsÚ	languages)ÚApplicationErrorÚ	DataError)Ú	TransformÚTransformError)ÚpartsÚ
referencesÚmiscc               @   sD   e Zd ZdZdZdZdZe dej	¡dfe d¡dffZ
dd	„ Zd
S )ÚHeadersz<
    Process fields in a PEP's initial RFC-2822 header.
    ih  zpep-%04dz3http://hg.python.org/peps/file/default/pep-%04d.txtz\$RCSfile: (.+),v \$$z\1z\$[a-zA-Z]+: (.+) \$$c             C   s(  t | jƒstdƒ‚| jd }t|tjƒr4d|d kr<tdƒ‚d }xð|D ]è}|d  ¡  ¡ dkrF|d  ¡ }yt|ƒ}| j	| }W nª t
k
r*   |}d }| jjjd| |d	}| j |¡}tj||pÈd
|d}| j |¡}	| |	¡ t |d ƒr|g|d d d d …< n|d  t dd|¡7  < Y nX P qFW |d krDtdƒ‚|dkrrt t¡}
| j d|
¡ | j |
¡ t |ƒdk sš|d d  ¡  ¡ dkr¢tdƒ‚x~|D ]t}|d  ¡  ¡ }|d }t |ƒdkrìtd|jdd ƒ‚nŒt |ƒdkr"t|d tjƒsxtd|jdd ƒ‚nV|dkrªt dt t | jd ¡d ¡¡}|rx|t ddtjd||d¡7 }nqª|d }|dkrºx*|D ]"}t|tjƒr| t|ƒ¡ qW qª|dkröx,|D ]$}t|tjƒrÊ| t||ƒ¡ qÊW qª|dkrxg }t d¡}xRt  d| ¡ ¡D ]>}t|ƒ}| !tj||| jj"j#| j$|  d¡ | !|¡ q W |d d… |d d …< n¦|dkrºt% &|| j'¡ |r| ¡ }tjd||dg|d d …< nd|dkrü| ¡ }| jj"j#| j$d   }tjd||dg|d d …< n"|d!krªt |ƒrªt% &|| j'¡ qªW d S )"NzDocument tree is empty.r   Úrfc2822ÚclasseszADocument does not begin with an RFC-2822 header; it is not a PEP.Úpepé   z?"PEP" header must contain an integer; "%s" is an invalid value.)Z	base_nodez(none))ZrefidÚ z3Document does not contain an RFC-2822 "PEP" header.é   Útitlez	No title!z4PEP header field body contains multiple elements:
%s)Úlevelz=PEP header field body may only contain a single paragraph:
%szlast-modifiedz%d-%b-%YÚsourceé   )ÚrefuriZauthorzdiscussions-to)Zreplaceszreplaced-byZrequiresú z,?\s+éÿÿÿÿzcontent-typeé   Úversion)(ÚlenÚdocumentr   Ú
isinstancer   Z
field_listÚastextÚlowerÚintÚpep_cvs_urlÚ
ValueErrorÚreporterZwarningÚset_idZproblematicZadd_backrefÚ	paragraphÚpendingÚPEPZeroÚinsertÚnote_pendingZpformatÚtimeZstrftimeZ	localtimeÚosÚstatÚ	referenceÚreplace_selfÚ
mask_emailZTextÚreÚsplitÚappendÚsettingsÚpep_base_urlÚpep_urlr   Zclean_rcs_keywordsÚrcs_keyword_substitutions)ÚselfÚheaderr   ZfieldÚvalueZcvs_urlÚmsgZmsgidZprbZprbidr'   ÚnameZbodyZdateZparaÚnodeZnewbodyZspaceZrefpepÚpepnoZpep_typeZuri© r?   ú7lib/python3.7/site-packages/docutils/transforms/peps.pyÚapply)   sª    



 


(








zHeaders.applyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údefault_priorityr6   r"   r1   ÚcompileÚ
IGNORECASEr7   rA   r?   r?   r?   r@   r      s   r   c               @   s   e Zd ZdZdZdd„ ZdS )ÚContentsz~
    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d }t d|¡}tj	d|dgd}t 
|¡}| j |¡sb|d  |¡ | j |¡ t tj¡}||7 }| j d|¡ | j |¡ d S )NÚcontentsr   )r   Únamesr   )r   Zget_languager   r4   Zlanguage_coder$   Úlabelsr   r   ÚtopicZfully_normalize_nameZhas_namer3   Znote_implicit_targetr'   r	   rI   r)   r*   )r8   Zlanguager<   r   rM   r'   r?   r?   r@   rA   ’   s    


zContents.applyN)rB   rC   rD   rE   rF   rA   r?   r?   r?   r@   rI   ‰   s   rI   c               @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚTargetNotesz¶
    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rvt|| tjƒrv|| d  ¡  ¡  ¡ }d|kr`|| }P nd|krl|}|d8 }qW |sºt ¡ }|t dd¡7 }| 	|¡ |r°| 
||¡ n
| |¡ t tj¡}| |¡ | j  |d¡ tjtjd| jid}| |¡ | j  |d¡ d S )	Nr   r   r
   Ú	copyrightr   Z
ReferencesÚcallback)Zdetails)r   r   r   r   Zsectionr   r    r2   r   r%   r)   r3   r'   r
   rN   r*   r   ZCallBackÚcleanup_callback)r8   ÚdocÚiZrefsectrO   Ztitle_wordsr'   r?   r?   r@   rA   ¬   s2    



zTargetNotes.applyc             C   s"   t |jƒdkr|jj |j¡ dS )z
        Remove an empty "References" section.

        Called after the `references.TargetNotes` transform is complete.
        r   N)r   ÚparentÚremove)r8   r'   r?   r?   r@   rQ   Ê   s    zTargetNotes.cleanup_callbackN)rB   rC   rD   rE   rF   rA   rQ   r?   r?   r?   r@   rN   ¢   s   rN   c               @   s   e Zd ZdZdZdd„ ZdS )r(   z'
    Special processing for PEP 0.
    iø  c             C   s*   t | jƒ}| j |¡ | jj | j¡ d S )N)ÚPEPZeroSpecialr   ÚwalkZ	startnoderT   rU   )r8   Zvisitorr?   r?   r@   rA   Ü   s    
zPEPZero.applyN)rB   rC   rD   rE   rF   rA   r?   r?   r?   r@   r(   Ô   s   r(   c               @   sN   e Zd ZdZejZdd„ Zdd„ Zdd„ Zdd	„ Z	d
d„ Z
dd„ Zdd„ ZdS )rV   z´
    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 )Nr?   )r8   r=   r?   r?   r@   Úunknown_visitï   s    zPEPZeroSpecial.unknown_visitc             C   s   |  t|ƒ¡ d S )N)r/   r0   )r8   r=   r?   r?   r@   Úvisit_referenceò   s    zPEPZeroSpecial.visit_referencec             C   s   d|d krt j‚d S )Nr   r   )r   ZSkipNode)r8   r=   r?   r?   r@   Úvisit_field_listõ   s    zPEPZeroSpecial.visit_field_listc             C   s   |d dk| _ d| _d S )NZcolsé   r   )Ú	pep_tableÚentry)r8   r=   r?   r?   r@   Úvisit_tgroupù   s    zPEPZeroSpecial.visit_tgroupc             C   s0   |  j d7  _ | jr,| j dkr,|d  d¡ d S )Nr   r   r   Únum)r]   r\   r3   )r8   r=   r?   r?   r@   Úvisit_colspecý   s    zPEPZeroSpecial.visit_colspecc             C   s
   d| _ d S )Nr   )r]   )r8   r=   r?   r?   r@   Ú	visit_row  s    zPEPZeroSpecial.visit_rowc             C   s®   |  j d7  _ | jrª| j dkrªt|ƒdkrª|d  d¡ |d }t|tjƒrªt|ƒdkrª| ¡ }y4t|ƒ}| j	j
j| j|  }tj|||d|d< W n tk
r¨   Y nX d S )Nr   r   r   r_   r   )r   )r]   r\   r   r3   r   r   r&   r   r!   r   r4   r5   r6   r.   r#   )r8   r=   ÚpÚtextr   Úrefr?   r?   r@   Úvisit_entry  s    zPEPZeroSpecial.visit_entryN)rB   rC   rD   rE   r   r6   rX   rY   rZ   r^   r`   ra   re   r?   r?   r?   r@   rV   â   s   	rV   )zpeps@python.orgzpython-list@python.orgzpython-dev@python.orgc             C   s’   |   d¡rŠ| d  d¡rŠ| d dd… tkr6| d }n |  ¡  dd¡}tjd|d	d
}|dkrb|S | d  d| 7  < |g| dd…< | S n| S dS )a¨  
    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   zmailto:r   Nr   ú@z&#32;&#97;t&#32;r   Zhtml)Úformatz?subject=PEP%%20%s)ÚhasattrÚ
startswithÚnon_masked_addressesr   Úreplacer   Úraw)rd   r>   ZreplacementZreplacement_textr?   r?   r@   r0     s    
r0   )N)rE   Z__docformat__Úsysr,   r1   r+   Zdocutilsr   r   r   r   r   Zdocutils.transformsr   r   r	   r
   r   r   rI   rN   r(   ZSparseNodeVisitorrV   rj   r0   r?   r?   r?   r@   Ú<module>   s    o23