B \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@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 Cs(t|jstd|jd}t|tjr4d|dkr}t|}|!tj|||jj"j#|j$|d|!|q W|dd|dd<n| dkrt%&||j'|r|} tjd | |dg|dd<nd| dkr|}|jj"j#|j$d }tjd ||dg|dd<n"| d!krt| rt%&||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-to)Zreplacesz replaced-byrequires z,?\s+z content-type version)(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_typeurirLlanguagerDrrZr*rLrLrMrNs        zContents.applyN)rOrPrQrRrSrNrLrLrLrMrVsrVc@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||d}d|kr`||}Pn d|krl|}|d8}qW|st}|tdd7}| ||r| ||n | |t t j}| ||j|dtj tjd|jid}| ||j|ddS) Nrrr copyrightrZ Referencescallback)details)rrr rsectionr!r"r8rr(r,r9r*r r\r-r ZCallBackcleanup_callback)r>dociZrefsectr]Z title_wordsr*rLrLrMrNs2       zTargetNotes.applycCs"t|jdkr|jj|jdS)z Remove an empty "References" section. Called after the `references.TargetNotes` transform is complete. rN)rparentremove)r>r*rLrLrMraszTargetNotes.cleanup_callbackN)rOrPrQrRrSrNrarLrLrLrMr\sr\c@seZdZdZdZddZdS)r+z' Special processing for PEP 0. icCs*t|j}|j||jj|jdS)N)PEPZeroSpecialrwalkZ startnoderdre)r>ZvisitorrLrLrMrNs  z PEPZero.applyN)rOrPrQrRrSrNrLrLrLrMr+sr+c@sNeZdZdZejZddZddZddZdd Z d d Z d d Z ddZ dS)rfz 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)NrL)r>rHrLrLrM unknown_visitszPEPZeroSpecial.unknown_visitcCs|t|dS)N)r5r6)r>rHrLrLrMvisit_referenceszPEPZeroSpecial.visit_referencecCsd|dkrtjdS)Nr r)rZSkipNode)r>rHrLrLrMvisit_field_lists zPEPZeroSpecial.visit_field_listcCs|ddk|_d|_dS)Ncolsr) pep_tableentry)r>rHrLrLrM visit_tgroupszPEPZeroSpecial.visit_tgroupcCs0|jd7_|jr,|jdkr,|dddS)Nrrrnum)rnrmr9)r>rHrLrLrM visit_colspecszPEPZeroSpecial.visit_colspeccCs d|_dS)Nr)rn)r>rHrLrLrM visit_rowszPEPZeroSpecial.visit_rowcCs|jd7_|jr|jdkrt|dkr|dd|d}t|tjrt|dkr|}y4t|}|j j j |j |}tj |||d|d<Wntk rYnXdS)Nrrrrpr)r)rnrmrr9r rr)r!r#rr:r;r<r4r%)r>rHptextrrefrLrLrM visit_entrys zPEPZeroSpecial.visit_entryN) rOrPrQrRr r<rhrirjrorqrrrvrLrLrLrMrfs rf)zpeps@python.orgzpython-list@python.orgzpython-dev@python.orgcCs|dr|ddr|dddtkr6|d}n |dd}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)rurJ replacementZreplacement_textrLrLrMr6s  r6)N)rRZ __docformat__sysr2r7r/ZdocutilsrrrrrZdocutils.transformsrrr r r r rVr\r+ZSparseNodeVisitorrfr|r6rLrLrLrM s o23