o
    N=&bg+                     @   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.
Z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   s  t | js	td| jd }t|tjrd|d vrtdd }|D ]r}|d   dkr|d  }zt|}| j	| }W nR t
y   |}d }| jjjd| |d	}| j|}tj||pad
|d}| j|}	||	 t |d r|g|d d d d < n|d  tdd|7  < Y nw  nq"|d u rtd|dkrt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 t |dkrt|d tjstd|jdd n9|dkr=ztdtt| jd d }W n ty)   d}Y nw |r<|tddtjd||d7 }nq|d }|dkr\|D ]}t|tjrY|t| qIq|dkrw|D ]}t|tjrt|t|| qcq|dv rg }td}t !d| D ]}t|}|"tj||| jj#j$| j%|  d |"| q|d d |d d < q|dkrt&'|| j( |r| }tjd||dg|d d < q|d kr| }| jj#j$| j%d!  }tjd||dg|d d < q|d"kr	t |r	t&'|| 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_typeZuri rN   <usr/lib/python3.10/site-packages/docutils/transforms/peps.pyapply(   s   



$









zHeaders.applyN)__name__
__module____qualname____doc__default_priorityr?   r%   r:   compile
IGNORECASEr@   rP   rN   rN   rN   rO   r
      s    r
   c                   @      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|s1|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   rY   r-   r.   )rA   languagerG   r   r]   r+   rN   rN   rO   rP      s   

zContents.applyNrQ   rR   rS   rT   rU   rP   rN   rN   rN   rO   rY      s    rY   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rDt|| tjrD|| d    }d|v r.|| }nd|v r4|}|d8 }|dkrDt|| tjs|set }|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   
Referencescallback)details)r   r   r    r   sectionr"   r#   r;   r   r)   r-   r<   r+   r   r`   r.   r	   ZCallBackcleanup_callback)rA   dociZrefsectra   Ztitle_wordsr+   rN   rN   rO   rP      s6   



zTargetNotes.applyc                 C   s&   t |jdkr|jj|j dS dS )z
        Remove an empty "References" section.

        Called after the `references.TargetNotes` transform is complete.
        r   N)r   parentremove)rA   r+   rN   rN   rO   rf      s   zTargetNotes.cleanup_callbackN)rQ   rR   rS   rT   rU   rP   rf   rN   rN   rN   rO   r`      s
    r`   c                   @   rX   )r,   z'
    Special processing for PEP 0.
    i  c                 C   s*   t | j}| j| | jj| j d S N)PEPZeroSpecialr   walkZ	startnoderi   rj   )rA   visitorrN   rN   rO   rP      s   
zPEPZero.applyNr_   rN   rN   rN   rO   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   rN   rA   rK   rN   rN   rO   unknown_visit   s   zPEPZeroSpecial.unknown_visitc                 C   s   | t| d S rk   )r7   r8   ro   rN   rN   rO   visit_reference   s   zPEPZeroSpecial.visit_referencec                 C   s   d|d v r	t jd S )Nr   r   )r   ZSkipNodero   rN   rN   rO   visit_field_list   s   zPEPZeroSpecial.visit_field_listc                 C   s   |d dk| _ d| _d S )Ncols   r   )	pep_tableentryro   rN   rN   rO   visit_tgroup   s   
zPEPZeroSpecial.visit_tgroupc                 C   s8   |  j d7  _ | jr| j dkr|d d d S d S d S )Nr   r   r   num)rv   ru   r<   ro   rN   rN   rO   visit_colspec   s   zPEPZeroSpecial.visit_colspecc                 C   s
   d| _ d S )Nr   )rv   ro   rN   rN   rO   	visit_row  s   
zPEPZeroSpecial.visit_rowc                 C   s   |  j d7  _ | jrV| j dkrXt|dkrZ|d d |d }t|tjr\t|dkr^| }zt|}| j	j
j| j|  }tj|||d|d< W d S  tyU   Y d S w d S d S d S d S d S )Nr   r   r   rx   r   r   )rv   ru   r   r<   r    r   r*   r"   r$   r   r=   r>   r?   r6   r&   )rA   rK   ptextr   refrN   rN   rO   visit_entry  s"   zPEPZeroSpecial.visit_entryN)rQ   rR   rS   rT   r
   r?   rp   rq   rr   rw   ry   rz   r~   rN   rN   rN   rO   rl      s    	rl   )zpeps@python.orgzpython-list@python.orgzpython-dev@python.orgc                 C   s   |  drD| d drD| d dd tv r| d }n|  dd}tjd|d	d
}|du r1|S | d  d| 7  < |g| dd< | S | 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}   rM   replacementZreplacement_textrN   rN   rO   r8     s   
r8   rk   )rT   Z__docformat__r3   r:   r0   docutilsr   r   r   r   Zdocutils.transformsr   r   r   r	   r
   rY   r`   r,   ZSparseNodeVisitorrl   r   r8   rN   rN   rN   rO   <module>   s    	r23