o 1_+@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. reStructuredTextN)nodesutils languages)ApplicationError DataError) TransformTransformError)parts referencesmiscc@sDeZdZdZdZdZdZedej dfeddffZ 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]+: (.+) \$$c Cst|js td|jd}t|tjrd|dvrtdd}|D]r}|ddkr|d}z t|}|j |}WnRt y|}d}|jj j d||d }|j |}tj||pad |d }|j |} || t|dr|g|dddd<n |dtd d |7<Ynwnq"|durtd |dkrtt} |jd| |j| t|dks|dddkrtd|D]=}|d} |d} t| dkrtd|jddt| dkrt| dtjstd|jddn9| dkr=ztdtt|jdd} Wn ty)d} Ynw|r<| td d tjd | |d7} nq| d}| dkr\|D]}t|tjrY|t|qIq| dkrw|D]}t|tjrt|t||qcq| dvrg}td}t !d| D]}t|}|"tj|||jj#j$|j%|d|"|q|dd|dd<q| dkrt&'||j(|r|} tjd | |dg|dd<q| d kr|}|jj#j$|j%d!}tjd ||dg|dd<q| d"kr t| r t&'||j(qdS)#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.) base_nodez(none))refidz3Document 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-%Ysourceunknownrefuriauthorzdiscussions-to)replacesz replaced-byrequires z,?\s+z content-type version))lendocumentr isinstancer field_listastextlowerint pep_cvs_url ValueErrorreporterwarningset_id problematic add_backref paragraphpendingPEPZeroinsert note_pendingpformattimestrftime localtimeosstatOSError reference replace_self mask_emailTextresplitappendsettings pep_base_urlpep_urlrclean_rcs_keywordsrcs_keyword_substitutions)selfheaderrfieldvaluecvs_urlmsgmsgidprbprbidr3namebodydateparanodenewbodyspacerefpeppepnopep_typeurir^:/usr/lib/python3/dist-packages/docutils/transforms/peps.pyapply)s             $           z Headers.applyN) __name__ __module__ __qualname____doc__default_priorityrGr+rBcompile IGNORECASErIr`r^r^r^r_r s  r c@eZdZdZdZddZdS)Contentsz~ Insert an empty table of contents topic and a transform placeholder into the document after the RFC 2822 header. i|cCst|jjj|jj}|jd}td|}tj d|dgd}t |}|j |s1|d ||j |ttj}||7}|jd||j|dS)Ncontentsr)rnamesr)r get_languager%rE language_coder-labelsrrtopicfully_normalize_namehas_namerDnote_implicit_targetr3r rir5r6)rJlanguagerSrror3r^r^r_r`s       zContents.applyNrarbrcrdrer`r^r^r^r_ris ric@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}}|dkrDt||tjrD||d}d|vr.||}nd|vr4|}|d8}|dkrDt||tjs|set}|tdd7}| ||r`| ||n| |t t j}| ||j|dtj tjd|jid}| ||j|ddS) Nrrr copyrightr Referencescallback)details)r%r$r&rsectionr(r)rCrr/r5rDr3r rur6r CallBackcleanup_callback)rJdocirefsectrv title_wordsr3r^r^r_r`s6      zTargetNotes.applycCs&t|jdkr|jj|jdSdS)z Remove an empty "References" section. Called after the `references.TargetNotes` transform is complete. rN)r$parentremove)rJr3r^r^r_r|szTargetNotes.cleanup_callbackN)rarbrcrdrer`r|r^r^r^r_rus  ruc@rh)r4z' Special processing for PEP 0. icCs*t|j}|j||jj|jdSN)PEPZeroSpecialr%walk startnoderr)rJvisitorr^r^r_r`s  z PEPZero.applyNrtr^r^r^r_r4s r4c@sNeZdZdZejZddZddZddZdd Z d d Z d d Z ddZ dS)rz 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. cCsdSrr^rJrWr^r^r_ unknown_visitszPEPZeroSpecial.unknown_visitcCs|t|dSr)r?r@rr^r^r_visit_referenceszPEPZeroSpecial.visit_referencecCsd|dvr tjdS)Nrr)rSkipNoderr^r^r_visit_field_lists zPEPZeroSpecial.visit_field_listcCs|ddk|_d|_dS)Ncolsr) pep_tableentryrr^r^r_ visit_tgroups zPEPZeroSpecial.visit_tgroupcCs8|jd7_|jr|jdkr|dddSdSdS)Nrrrnum)rrrDrr^r^r_ visit_colspecszPEPZeroSpecial.visit_colspeccCs d|_dS)Nr)rrr^r^r_ visit_rows zPEPZeroSpecial.visit_rowcCs|jd7_|jrV|jdkrXt|dkrZ|dd|d}t|tjr\t|dkr^|}zt|}|j j j |j |}tj |||d|d<WdStyUYdSwdSdSdSdSdS)Nrrrrrr)rrr$rDr&rr2r(r*r%rErFrGr>r,)rJrWptextrrefr^r^r_ visit_entrys"  zPEPZeroSpecial.visit_entryN) rarbrcrdr rGrrrrrrrr^r^r^r_rs  r)zpeps@python.orgzpython-list@python.orgzpython-dev@python.orgcCs|drD|ddrD|dddtvr|d}n|dd}tjd|d d }|dur1|S|dd |7<|g|dd<|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. rzmailto:rNr@z at rhtml)formatz?subject=PEP%%20%s)hasattr startswithnon_masked_addressesr(replacerraw)rr[ replacementreplacement_textr^r^r_r@s  r@r)rd __docformat__sysr;rBr8docutilsrrrrrdocutils.transformsrr r r r r rirur4SparseNodeVisitorrrr@r^r^r^r_s" r23