o
    iP,                     @  s   d Z ddlm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.
    )annotationsreStructuredTextN)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|f 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extendsettingspep_base_urlpep_urlr   clean_rcs_keywordsrcs_keyword_substitutions)selfheaderr   fieldvaluecvs_urlmsgmsgidprbprbidr2   namebodydateparanodenewbodyspacerefpeppepnopep_typeuri r]   ^/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/docutils/transforms/peps.pyapply,   s   



$










zHeaders.applyN)__name__
__module____qualname____doc__default_priorityrF   r*   rA   compile
IGNORECASErH   r_   r]   r]   r]   r^   r      s    r   c                   @     e Zd ZdZdZd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|  returnNonec                 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$   rD   language_coder,   labelsr   r   topicfully_normalize_namehas_nameappendnote_implicit_targetr2   r	   rh   r4   r5   )rI   languagerR   r   rp   r2   r]   r]   r^   r_      s   

zContents.applyNri   rj   r`   ra   rb   rc   rd   r_   r]   r]   r]   r^   rh      s    rh   c                   @  s(   e Zd ZdZdZd
ddZd
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  ri   rj   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(   rB   r   r.   r4   rs   r2   r
   rx   r5   r   CallBackcleanup_callback)rI   docirefsect
copyright_title_wordsr2   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)rI   r2   r]   r]   r^   r      s   zTargetNotes.cleanup_callbackNrv   )r`   ra   rb   rc   rd   r_   r   r]   r]   r]   r^   rx      s
    
rx   c                   @  rg   )	r3   z'
    Special processing for PEP 0.
    i  ri   rj   c                 C  s*   t | j}| j| | jj| j d S N)PEPZeroSpecialr$   walk	startnoder   r   )rI   visitorr]   r]   r^   r_      s   
zPEPZero.applyNrv   rw   r]   r]   r]   r^   r3      s    r3   c                   @  sZ   e Zd ZdZejZdddZdddZdd	 Zdd
dZ	dddZ
dddZd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.
    ri   rj   c                 C  s   d S r   r]   rI   rV   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   rs   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#   rs   r%   r   r1   r'   r)   r$   rD   rE   rF   r=   r+   )rI   rV   ptextr   refr]   r]   r^   visit_entry  s"   zPEPZeroSpecial.visit_entryNrv   )r`   ra   rb   rc   r   rF   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   rZ   replacementreplacement_textr]   r]   r^   r?   #  s   
r?   r   )rc   
__future__r   __docformat__r:   rA   r7   docutilsr   r   r   r   docutils.transformsr   r	   r
   r   r   rh   rx   r3   SparseNodeVisitorr   r   r?   r]   r]   r]   r^   <module>   s"   	w23