U
    [Shg+                     @   s   d Z d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	 ddl
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.
reStructuredText    N)nodesutils	languages)	DataError)	Transform)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   s6  t | jstd| jd }t|tjr4d|d kr<tdd }|D ]}|d   dkrD|d  }zt|}| j	| }W n t
k
r(   |}d }| jjjd| |d	}| j|}tj||pd
|d}| j|}	||	 t |d r
|g|d d d d < n|d  tdd|7  < Y nX  q2qD|d krDtd|dkrrtt}
| jd|
 | j|
 t |dk s|d d   dkrtd|D ]}|d   }|d }t |dkrtd|jdd nt |dkrt|d tjstd|jdd nv|dkrz&tdtt| jd d }W n tk
rh   d}Y nX |r|tddtjd||d7 }nq|d }|dkr|D ]"}t|tjr|t| qq|dkr
|D ]$}t|tjr|t|| qq|dkrg }td}t !d| D ]>}t|}|"tj||| jj#j$| j%|  d |"| q2|d d |d d < n|dkrt&'|| 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rt |rt&'|| j( qd 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   unknownrefuriauthorzdiscussions-to)Zreplaceszreplaced-byrequires z,?\s+zcontent-type   version))lendocumentr   
isinstancer   
field_listastextlowerintpep_cvs_url
ValueErrorreporterwarningset_idZproblematicZadd_backref	paragraphpendingPEPZeroinsertnote_pendingpformattimestrftime	localtimeosstatOSError	referencereplace_self
mask_emailTextresplitappendsettingspep_base_urlpep_urlr   Zclean_rcs_keywordsrcs_keyword_substitutions)selfheaderr   fieldvalueZcvs_urlmsgmsgidZprbZprbidr,   namebodydateparanodeZnewbodyspaceZrefpeppepnoZpep_typeuri rP   K/root/rtd-docs/venv/lib/python3.8/site-packages/docutils/transforms/peps.pyapply(   s    



 


(




  



 

zHeaders.applyN)__name__
__module____qualname____doc__default_priorityr@   r&   r;   compile
IGNORECASErA   rR   rP   rP   rP   rQ   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    r>   Zlanguage_coder(   labelsr   r   topicZfully_normalize_nameZhas_namer=   Znote_implicit_targetr,   r   rZ   r.   r/   )rB   languagerH   r   r^   r,   rP   rP   rQ   rR      s    

zContents.applyNrS   rT   rU   rV   rW   rR   rP   rP   rP   rQ   rZ      s   rZ   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  }}|dkrtt|| tjrt|| d    }d|kr^|| }qtnd|krj|}|d8 }q|st }|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)details)r    r   r!   r   sectionr#   r$   r<   r   r*   r.   r=   r,   r	   ra   r/   r
   ZCallBackcleanup_callback)rB   dociZrefsectrb   Ztitle_wordsr,   rP   rP   rQ   rR      s4    




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)rB   r,   rP   rP   rQ   rf      s    zTargetNotes.cleanup_callbackN)rS   rT   rU   rV   rW   rR   rf   rP   rP   rP   rQ   ra      s   ra   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	startnoderi   rj   )rB   visitorrP   rP   rQ   rR      s    
zPEPZero.applyNr`   rP   rP   rP   rQ   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 )rl   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 rk   rP   rB   rL   rP   rP   rQ   unknown_visit   s    zPEPZeroSpecial.unknown_visitc                 C   s   | t| d S rk   )r8   r9   ro   rP   rP   rQ   visit_reference   s    zPEPZeroSpecial.visit_referencec                 C   s   d|d krt jd S )Nr   r   )r   ZSkipNodero   rP   rP   rQ   visit_field_list   s    zPEPZeroSpecial.visit_field_listc                 C   s   |d dk| _ d| _d S )Ncols   r   )	pep_tableentryro   rP   rP   rQ   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)rv   ru   r=   ro   rP   rP   rQ   visit_colspec   s    zPEPZeroSpecial.visit_colspecc                 C   s
   d| _ d S )Nr   )rv   ro   rP   rP   rQ   	visit_row  s    zPEPZeroSpecial.visit_rowc                 C   s   |  j d7  _ | jr| j dkrt|dkr|d d |d }t|tjrt|dkr| }z4t|}| j	j
j| j|  }tj|||d|d< W n tk
r   Y nX d S )Nr   r   r   rx   r   r   )rv   ru   r   r=   r!   r   r+   r#   r%   r    r>   r?   r@   r7   r'   )rB   rL   ptextr   refrP   rP   rQ   visit_entry  s    zPEPZeroSpecial.visit_entryN)rS   rT   rU   rV   r   r@   rp   rq   rr   rw   ry   rz   r~   rP   rP   rP   rQ   rl      s   	rl   )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   html)formatz?subject=PEP%%20%s)hasattr
startswithnon_masked_addressesr#   replacer   raw)r}   rN   replacementZreplacement_textrP   rP   rQ   r9     s    
r9   )N)rV   __docformat__r4   r;   r1   Zdocutilsr   r   r   r   Zdocutils.transformsr   r   r	   r
   r   rZ   ra   r-   ZSparseNodeVisitorrl   r   r9   rP   rP   rP   rQ   <module>   s   	r23