o
    Nig+                     @   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   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.)	base_nodez(none))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)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_idproblematic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   clean_rcs_keywordsrcs_keyword_substitutions)selfheaderr   fieldvaluecvs_urlmsgmsgidprbprbidr1   namebodydateparanodenewbodyspacerefpeppepnopep_typeuri r\   L/home/ubuntu/.local/lib/python3.10/site-packages/docutils/transforms/peps.pyapply(   s   



$









zHeaders.applyN)__name__
__module____qualname____doc__default_priorityrE   r)   r@   compile
IGNORECASErG   r^   r\   r\   r\   r]   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   get_languager#   rC   language_coder+   labelsr   r   topicfully_normalize_namehas_namerB   note_implicit_targetr1   r   rg   r3   r4   )rH   languagerQ   r   rm   r1   r\   r\   r]   r^      s   

zContents.applyNr_   r`   ra   rb   rc   r^   r\   r\   r\   r]   rg      s    rg   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'   rA   r   r-   r3   rB   r1   r	   rs   r4   r
   CallBackcleanup_callback)rH   docirefsectrt   title_wordsr1   r\   r\   r]   r^      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)rH   r1   r\   r\   r]   rz      s   zTargetNotes.cleanup_callbackN)r_   r`   ra   rb   rc   r^   rz   r\   r\   r\   r]   rs      s
    rs   c                   @   rf   )r2   z'
    Special processing for PEP 0.
    i  c                 C   s*   t | j}| j| | jj| j d S N)PEPZeroSpecialr#   walk	startnoder   r   )rH   visitorr\   r\   r]   r^      s   
zPEPZero.applyNrr   r\   r\   r\   r]   r2      s    r2   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 )r   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 r   r\   rH   rU   r\   r\   r]   unknown_visit   s   zPEPZeroSpecial.unknown_visitc                 C   s   | t| d S r   )r=   r>   r   r\   r\   r]   visit_reference   s   zPEPZeroSpecial.visit_referencec                 C   s   d|d v r	t jd S )Nr   r   )r   SkipNoder   r\   r\   r]   visit_field_list   s   zPEPZeroSpecial.visit_field_listc                 C   s   |d dk| _ d| _d S )Ncols   r   )	pep_tableentryr   r\   r\   r]   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)r   r   rB   r   r\   r\   r]   visit_colspec   s   zPEPZeroSpecial.visit_colspecc                 C   s
   d| _ d S )Nr   )r   r   r\   r\   r]   	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   r   r   r   )r   r   r"   rB   r$   r   r0   r&   r(   r#   rC   rD   rE   r<   r*   )rH   rU   ptextr   refr\   r\   r]   visit_entry  s"   zPEPZeroSpecial.visit_entryN)r_   r`   ra   rb   r   rE   r   r   r   r   r   r   r   r\   r\   r\   r]   r      s    	r   )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   rY   replacementreplacement_textr\   r\   r]   r>     s   
r>   r   )rb   __docformat__r9   r@   r6   docutilsr   r   r   r   docutils.transformsr   r   r	   r
   r   rg   rs   r2   SparseNodeVisitorr   r   r>   r\   r\   r\   r]   <module>   s    	r23