3 E\@sXdZdZddlmZddlmZmZGdddeZGdddeZGd d d eZ d S) z Miscellaneous transforms. ZreStructuredText)nodes) TransformTransformErrorc@seZdZdZdZddZdS)CallBacka Inserts a callback into a document. The callback is called when the transform is applied, which is determined by its priority. For use with `nodes.pending` elements. Requires a ``details['callback']`` entry, a bound method or function which takes one parameter: the pending node. Other data can be stored in the ``details`` attribute or in the object hosting the callback method. icCs$|j}|jd||jj|dS)Ncallback) startnodedetailsparentremove)selfpendingr r/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/docutils/docutils/transforms/misc.pyapplyszCallBack.applyN)__name__ __module__ __qualname____doc__default_priorityrr r r rrs rc@seZdZdZdZddZdS)ClassAttributez| Move the "class" attribute specified in the "pending" node into the immediately following non-comment element. cCs|j}|j}|}xz|rxpt|j|dt|D]J}||}t|tjs0t|tjrVq0|d|j d7<|jj |dSW|}|j}qW|j j j d|j dtj|j|j|jd}|j|dS)Nclassesclassz,No suitable element following "%s" directive directive)line)rr rangeindexlen isinstancerZ InvisibleZsystem_messagerr documentreportererrorZ literal_blockZ rawsourcerZ replace_self)r r r childrelementr"r r rr,s(      zClassAttribute.applyN)rrrrrrr r r rr#src@s$eZdZdZdZddZddZdS) Transitionsa Move transitions at the end of sections up the tree. Complain on transitions after a title, at the beginning or end of the document, and after another transition. For example, transform this::
...
... into this::
...
... i>cCs&x |jjtjD]}|j|qWdS)N)r Ztraverser transitionvisit_transition)r noder r rr`szTransitions.applycCs|jj|}d}|dksLt|jdtjr|dksLt|jdtjr|dkrt|jtjslt|jtjslt|jj j d|j |j d}n.t|j|dtj r|jj j d|j |j d}|r|jj|||d7}|t|jkst|t|jdkrdS|}xh|t|jdkrb|j}|jdkrT|jj j d|j d}|jj|jj|d|dS|jj|}qW|jj||jj|d|dS) Nrrz4Document or section may not begin with a transition.)sourcerzZAt least one body element must separate transitions; adjacent transitions are not allowed.z'Document may not end with a transition.)r)r rrrtitleZsubtitler sectionAssertionErrorr!r"r*rr&insertrr )r r(rr"Zsiblingr r rr'dsD    zTransitions.visit_transitionN)rrrrrrr'r r r rr%Fsr%N) rZ __docformat__ZdocutilsrZdocutils.transformsrrrrr%r r r rs  #