3 E\0+@sdZdZddlZddlZddlZddlZddlmZmZm Z ddlm Z m Z ddl m Z mZddl mZmZmZGdd d e ZGd d d e ZGd d d e ZGddde ZGdddejZdZdddZdS)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. ZreStructuredTextN)nodesutils languages)ApplicationError DataError) TransformTransformError)parts referencesmiscc@sDeZdZdZdZdZdZejdej dfejddffZ dd Z d S) Headersz< Process fields in a PEP's initial RFC-2822 header. ihzpep-%04dz3http://hg.python.org/peps/file/default/pep-%04d.txtz\$RCSfile: (.+),v \$$z\1z\$[a-zA-Z]+: (.+) \$$cCs*t|jstd|jd}t|tj s6d|dkr>tdd}x|D]}|djjdkrH|dj}yt|}|j |}Wnt k r,|}d}|jj j d||d }|jj |}tj||pd |d }|jj |} |j| t|dr|g|dddd<n|dtjd d |7<YnXPqHW|dkrFtd |dkrttjt} |jjd| |jj| t|dks|ddjjdkrtdx~|D]t}|djj} |d} t| dkrtd|jddnt| dkr$t| dtjsztd|jddnV| dkrtjdtjtj|jdd} |rz| tjd d tjd | |d7} nq| d}| dkrx*|D]"}t|tjr|jt|qWq| dkrx,|D]$}t|tjr|jt||qWq| d#krzg}tjd}xRtj d| jD]>}t|}|j!tj|||jj"j#|j$|d|j!|q"W|dd$|dd<n| dkrt%j&||j'|r |j} tjd | |dg|dd<nd| d kr|j}|jj"j#|j$d!}tjd ||dg|dd<n"| d"krt| rt%j&||j'qWdS)%NzDocument tree is empty.rrfc2822classeszADocument does not begin with an RFC-2822 header; it is not a PEP.pepz?"PEP" header must contain an integer; "%s" is an invalid value.)Z base_nodez(none))Zrefidz3Document 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-%Ysource)refuriauthorzdiscussions-toreplaces replaced-byrequires z,?\s+z content-type version)rrr)(lendocumentr isinstancerZ field_listastextlowerint pep_cvs_url ValueErrorreporterwarningset_idZ problematicZ add_backref paragraphpendingPEPZeroinsert note_pendingpformattimestrftime localtimeosstat reference replace_self mask_emailZTextresplitappendsettings pep_base_urlpep_urlrZclean_rcs_keywordsrcs_keyword_substitutions)selfheaderrfieldvalueZcvs_urlmsgmsgidZprbZprbidr,namebodydateparanodeZnewbodyspaceZrefpeppepnoZpep_typeurirNr/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/docutils/docutils/transforms/peps.pyapply)s               (         z Headers.applyN) __name__ __module__ __qualname____doc__default_priorityr>r&r9compile IGNORECASEr?rPrNrNrNrOr sr c@seZdZdZdZddZdS)Contentsz~ Insert an empty table of contents topic and a transform placeholder into the document after the RFC 2822 header. i|cCstj|jjj|jj}|jd}tjd|}tj d|dgd}tj |}|jj |sb|dj ||jj |tjtj}||7}|jjd||jj|dS)Ncontentsr)rnamesr)rZ get_languager!r<Z language_coder(labelsrrtopicZfully_normalize_nameZhas_namer;Znote_implicit_targetr,r rXr.r/)r@languagerFrr\r,rNrNrOrPs        zContents.applyN)rQrRrSrTrUrPrNrNrNrOrXsrXc@s$eZdZdZdZddZddZdS) 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. icCs|j}t|d}d}}x\|dkrvt||tjrv||djjj}d|kr`||}Pn d|krl|}|d8}qW|stj}|tjdd7}|j ||r|j ||n |j |tj t j}|j ||jj|dtj tjd|jid}|j ||jj|ddS) Nrrr copyrightrZ Referencescallback)details)r!r r"rsectionr#r$r:rr*r.r;r,r r^r/r ZCallBackcleanup_callback)r@dociZrefsectr_Z title_wordsr,rNrNrOrPs2       zTargetNotes.applycCs"t|jdkr|jjj|jdS)z Remove an empty "References" section. Called after the `references.TargetNotes` transform is complete. rN)r parentremove)r@r,rNrNrOrcszTargetNotes.cleanup_callbackN)rQrRrSrTrUrPrcrNrNrNrOr^sr^c@seZdZdZdZddZdS)r-z' Special processing for PEP 0. icCs*t|j}|jj||jjj|jdS)N)PEPZeroSpecialr!walkZ startnoderfrg)r@visitorrNrNrOrPs  z PEPZero.applyN)rQrRrSrTrUrPrNrNrNrOr-sr-c@sNeZdZdZejZddZddZddZdd Z d d Z d d Z ddZ dS)rhz 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. cCsdS)NrN)r@rJrNrNrO unknown_visitszPEPZeroSpecial.unknown_visitcCs|jt|dS)N)r7r8)r@rJrNrNrOvisit_referenceszPEPZeroSpecial.visit_referencecCsd|dkrtjdS)Nr r)rZSkipNode)r@rJrNrNrOvisit_field_lists zPEPZeroSpecial.visit_field_listcCs|ddk|_d|_dS)Ncolsr) pep_tableentry)r@rJrNrNrO visit_tgroupszPEPZeroSpecial.visit_tgroupcCs0|jd7_|jr,|jdkr,|djddS)Nrrrnum)rqrpr;)r@rJrNrNrO visit_colspecszPEPZeroSpecial.visit_colspeccCs d|_dS)Nr)rq)r@rJrNrNrO visit_rowszPEPZeroSpecial.visit_rowc Cs|jd7_|jr|jdkrt|dkr|djd|d}t|tjrt|dkr|j}y4t|}|j j j |j |}tj |||d|d<Wntk rYnXdS)Nrrrrsr)r)rqrpr r;r"rr+r#r%r!r<r=r>r6r')r@rJptextrrefrNrNrO visit_entrys zPEPZeroSpecial.visit_entryN) rQrRrSrTr r>rkrlrmrrrtruryrNrNrNrOrhs rhpeps@python.orgpython-list@python.orgpython-dev@python.orgcCs|jdr|djdr|dddtkr6|d}n |jjdd}tjd|d d }|dkrb|S|dd |7<|g|dd<|Sn|SdS) 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. rzmailto:rNr@z at rhtml)formatz?subject=PEP%%20%s)hasattr startswithnon_masked_addressesr#replacerraw)rxrL replacementZreplacement_textrNrNrOr8s  r8)rzr{r|)N)rTZ __docformat__sysr4r9r1ZdocutilsrrrrrZdocutils.transformsrrr r r r rXr^r-ZSparseNodeVisitorrhrr8rNrNrNrO s$o23