B 0`1"@s dZdZddlZddlZddlZddlZddlZddlZGdddeZ ej dkrdGddde Z ne Z d d Z dFd d ZGddde e ZGddde ZGdddeZGdddeZGdddZGdddZGdddZGdddZGdddZGd d!d!ZGd"d#d#eZGd$d%d%ZGd&d'd'ZGd(d)d)eZGd*d+d+eZGd,d-d-eZGd.d/d/eZGd0d1d1eZ Gd2d3d3Z!Gd4d5d5Z"Gd6d7d7eZ#Gd8d9d9eZ$Gd:d;d;Z%Gdd?d?eeeZ'Gd@dAdAeeeZ(GdBdCdCeeZ)GdDdEdEeeZ*GdFdGdGeeZ+GdHdIdIeeZ,GdJdKdKeeZ-GdLdMdMeeZ.GdNdOdOeeZ/GdPdQdQeeZ0GdRdSdSeeZ1GdTdUdUeeZ2GdVdWdWeeZ3GdXdYdYeeZ4GdZd[d[eeZ5Gd\d]d]eeZ6Gd^d_d_eeZ7Gd`dadaeeZ8GdbdcdceeZ9GdddedeeeZ:GdfdgdgeeZ;GdhdidieeZGdndodoeeZ?GdpdqdqeeZ@Gdrdsdse!eZAGdtdudueeZBGdvdwdwe!eZCGdxdydye!eZDGdzd{d{e!eZEGd|d}d}e!eZFGd~ddeeZGGddde!eZHGddde!eZIGddde!eZJGddde!eZKGddde!eZLGddde!eZMGdddeeZNGddde!eZOGddde!eZPGddde!eZQGdddeeZRGdddeeZSGdddeeZTGdddeeZUGddde!eZVGdddeeZWGddde!eZXGdddeeZYGdddeeZZGdddeeZ[GdddeeZ\GdddeeZ]GdddeeZ^GdddeeZ_GdddeeZ`GdddeeZaGdddeeZbGdddee eZcGdddee eZdGdddee e"ee$ZeGdddeeee%e$ZfGdddeeee%e$ZgGddde!eZhGddÄdeeZiGddńde!eZjGddDŽde!eZkGddɄdeeZlGdd˄de!eZmGdd̈́de!eZnGddτde!eZoGddфde!eZpGddӄde!eZqGddՄde!eZrGddׄdeeeeZsGddلdee eZtGddۄdee"eeZuGdd݄de"eZvGdd߄de"eZwGddde"eZxGdddee"e#eZyGddde"e#eZzGddde"e#eZ{Gddde"eZ|Gddde"eZ}Gddde"eZ~Gddde"eZGddde"eZGddde"eZGddde"eZGdddee"eZGddde"eZGddde"eZGddde"eZdZGdddZGdddeZGdddeZddZddZd d Zd d ZeeGd ddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZddZedZed Zd!d"d#d$d%d&d'd'd(d"d)d*d%d+d,d&d&d-d.d/d.d%d+d&d0d(d1d.d2d0d3d4d-d5!Zd6d7d8d9d:d;Zd<d=Zd>d?Zd@dAZdBdCZdDdEZdS(Ga Docutils document tree element class library. Classes in CamelCase are abstract base classes or auxiliary classes. The one exception is `Text`, for a text (PCDATA) node; uppercase is used to differentiate from element classes. Classes in lower_case_with_underscores are element classes, matching the XML element generic identifiers in the DTD_. The position of each node (the level at which it can occur) is significant and is represented by abstract base classes (`Root`, `Structural`, `Body`, `Inline`, etc.). Certain transformations will be easier because we can use ``isinstance(node, base_class)`` to determine the position of the node in the hierarchy. .. _DTD: http://docutils.sourceforge.net/docs/ref/docutils.dtd ZreStructuredTextNc@seZdZdZdZdZdZdZddZe j dkr6ddZ d$dd Z d%d d Z ddZddZddZddZddZddZddZddZd&d d!Zd'd"d#ZdS)(Nodez0Abstract base class of nodes in a document tree.NcCsdS)a8 Node instances are always true, even if they're empty. A node is more than a simple container. Its boolean "truth" does not depend on having one or more subnodes in the doctree. Use `len()` to check node length. Use `None` to represent a boolean false value. T)selfrri/private/var/folders/sf/wxz_36012wxg_prv29r6623x5vlqx8/T/pip-target-tft40_m7/lib/python/docutils/nodes.py__bool__4s z Node.__bool__)cCst|dS)NZraw_unicode_escape)strencode)rrrr__str__Bsz Node.__str__cCs,|dkrddlmm}|}||S)z6Return a DOM **fragment** representation of this Node.Nr)xml.dom.minidomdomminidomDocument _dom_node)rr domrootrrrasdomEsz Node.asdom rcCstdS)zs Return an indented pseudo-XML representation, for test purposes. Override in subclasses. N)NotImplementedError)rindentlevelrrrpformatLsz Node.pformatcCstdS)zReturn a copy of self.N)r)rrrrcopyTsz Node.copycCstdS)z3Return a deep copy of self (also copying children).N)r)rrrrdeepcopyXsz Node.deepcopycCstdS)z,Return a string representation of this Node.N)r)rrrrastext\sz Node.astextcCs@||_|jr<|j|_|jdkr(|jj|_|jdkr<|jj|_dS)N)parentdocumentsourcecurrent_sourceline current_line)rchildrrr setup_child`s   zNode.setup_childc Csd}|jjd|jjyy||Wn*ttfk rB|Stk rTYnX|j }y*x$|ddD]}| |rld}PqlWWnt k rYnXWnt k rd}YnX|S)a Traverse a tree of `Node` objects, calling the `dispatch_visit()` method of `visitor` when entering each node. (The `walkabout()` method is similar, except it also calls the `dispatch_departure()` method before exiting each node.) This tree traversal supports limited in-place tree modifications. Replacing one node with one or more nodes is OK, as is removing an element. However, if the node removed or replaced occurs after the current node, the old node will still be traversed, and any new nodes will not. Within ``visit`` methods (and ``depart`` methods for `walkabout()`), `TreePruningException` subclasses may be raised (`SkipChildren`, `SkipSiblings`, `SkipNode`, `SkipDeparture`). Parameter `visitor`: A `NodeVisitor` object, containing a ``visit`` implementation for each `Node` subclass encountered. Return true if we should stop the traversal. Fz6docutils.nodes.Node.walk calling dispatch_visit for %sNT) rreporterdebug __class____name__dispatch_visit SkipChildrenSkipNode SkipDeparturechildrenwalk SkipSiblings StopTraversal)rvisitorstopr*r rrrr+is,     z Node.walkcCsd}d}|jjd|jjyy||Wn*tk rB|Stk rXd}YnX|j}y*x$|ddD]}| |rpd}PqpWWnt k rYnXWn*t k rYnt k rd}YnX|r|jjd|jj| ||S)a Perform a tree traversal similarly to `Node.walk()` (which see), except also call the `dispatch_departure()` method before exiting each node. Parameter `visitor`: A `NodeVisitor` object, containing a ``visit`` and ``depart`` implementation for each `Node` subclass encountered. Return true if we should stop the traversal. TFz;docutils.nodes.Node.walkabout calling dispatch_visit for %sNz?docutils.nodes.Node.walkabout calling dispatch_departure for %s)rr"r#r$r%r&r(r)r* walkaboutr,r'r-dispatch_departure)rr.Z call_departr/r*r rrrr0s<         zNode.walkaboutcCs<g}t||r||x|jD]}|||q W|S)z:Specialized traverse() that only supports instance checks.) isinstanceappendr*extend_fast_traverse)rclsresultr rrrr5s    zNode._fast_traversecCs0g}||x|jD]}||qW|S)z:Specialized traverse() that doesn't check for a condition.)r3r*r4 _all_traverse)rr7r rrrr8s   zNode._all_traverseTFc Cs|rd}|r8|r8|s8|dkr$|St|tr8||St|trR|}|fdd}g}|rt|dksj||rt|||rt|jrx&|D]}||jdddd|dqW|s|r|} x^| j r| j | } x4| j | ddD]} || jd|dd|dqW|sPq| j } qW|S)a Return an iterable containing * self (if include_self is true) * all descendants in tree traversal order (if descend is true) * all siblings (if siblings is true) and their descendants (if also descend is true) * the siblings of the parent (if ascend is true) and their descendants (if also descend is true), and so on If `condition` is not None, the iterable contains only nodes for which ``condition(node)`` is true. If `condition` is a node class ``cls``, it is equivalent to a function consisting of ``return isinstance(node, cls)``. If ascend is true, assume siblings to be true as well. For example, given the following tree:: <--- emphasis.traverse() and <--- strong.traverse() are called. Foo Bar Baz Then list(emphasis.traverse()) equals :: [, , <#text: Foo>, <#text: Bar>] and list(strong.traverse(ascend=True)) equals :: [, <#text: Foo>, <#text: Bar>, , <#text: Baz>] TNcSs t||S)N)r2)node node_classrrr conditionsz Node.traverse..conditionF) include_selfdescendsiblingsascendr;) r8r2typer5r3lenr*r4traverserindex) rr;r<r=r>r?r:rr r9rDZsiblingrrrrCs>%             z Node.traversecCs6|j|||||d}y|dStk r0dSXdS)z Return the first node in the iterable returned by traverse(), or None if the iterable is empty. Parameter list is the same as of traverse. Note that include_self defaults to 0, though. )r;r<r=r>r?rN)rC IndexError)rr;r<r=r>r?iterablerrr next_nodes  zNode.next_node)N)rr)NTTFF)NFTFF)r% __module__ __qualname____doc__rrrrrsys version_infor rrrrrr!r+r0r5r8rCrHrrrrr$s,    .+  Jr)rc@seZdZdZddZdS) reprunicodezU A unicode sub-class that removes the initial u from unicode's repr. cCst|ddS)Nr@)r__repr__)rrrrrO5szreprunicode.__repr__N)r%rIrJrKrOrrrrrN0srNcCs$tjdkr t|tr |ddS|S)z4 Failsave conversion of `unicode` to `str`. )rasciibackslashreplace)rLrMr2rr )srrr ensure_str;s rSFcCs6|r|ddSxdD]}d||}qW|SdS)zw Return a string with nulls removed or restored to backslashes. Backslash-escaped spaces are also removed. \)z z rTN)replacejoinsplit)textZrestore_backslashesZrespect_whitespaceseprrrunescapeDs   r\c@seZdZdZdZdZejdkr*d!ddZn d"ddZd#d d Z d$d dZ ddZ ddZ ddZ ddZddZd%ddZd&ddZd'dd ZdS)(Textz Instances are terminal nodes (leaves) containing text only; no child nodes or attributes. Initialize by passing a string to the constructor. Access the text itself with the `astext` method. z#textr)rNcCst|trtdt||S)z7Prevent the rawsource argument from propagating to str.zexpecting str data, not bytes)r2bytes TypeErrorrN__new__)r6data rawsourcerrrr``s z Text.__new__cCs t||S)z7Prevent the rawsource argument from propagating to str.)rNr`)r6rarbrrrr`fsrVcCs ||_dS)N)rb)rrarbrrr__init__jsz Text.__init__cCs6|}t||kr$|d|dd}d|jt|fS)Nz ...z<%s: %r>)rBtagnamerN)rmaxlenrarrr shortreprns zText.shortreprcCs |jddS)ND)rg)rh)rrrrrOtsz Text.__repr__cCs|t|S)N)ZcreateTextNoder)rrrrrrwszText._dom_nodecCs tt|S)N)rNr\)rrrrrzsz Text.astextcCs|jt||jdS)N)rb)r$rNrb)rrrrrsz Text.copycCs|S)N)r)rrrrrsz Text.deepcopy rcs8|fdd|D}|s*dSd|dS)Ncsg|] }|qSrr).0r)rrr sz Text.pformat..rV )r splitlinesrX)rrrlinesr)rrrs z Text.pformatcCs|t|||jS)N)r$rNrstriprb)rcharsrrrrpsz Text.rstripcCs|t|||jS)N)r$rNlstriprb)rrqrrrrrsz Text.lstrip)N)N)rV)rd)rjr)N)N)r%rIrJrKrfr*rLrMr`rcrhrOrrrrrrprrrrrrr]Rs        r]c@sBeZdZdZdZdZeeZedZdZdZ d~dd Z d d Z d d Z ddZ ddZejdkrdeZdddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zdd/d0Z d1d2Z!d3d4Z"dd5d6Z#e!Z$e!Zdd7d8Z%d9d:Z&d;d<Z'd=d>Z(dd@dAZ)dBdCZ*dDdEZ+dFdGZ,dHdIZ-dJdKZ.dLdMZ/ddOdPZ0ddQdRZ1dSdTZ2dUdVZ3dWdXZ4e4dNdYfdZd[Z5dd\d]Z6dd^d_Z7dd`daZ8ddbdcZ9dddeZ:dfdgZ;dhdiZdjej=fdmdnZ?ddpdqZ@drdsZAdtduZBdvdwZCddxdyZDeEdzd{ZFeEd|d}ZGdS)Elementa `Element` is the superclass to all specific elements. Elements contain attributes and child nodes. Elements emulate dictionaries for attributes, indexing by attribute name (a string). To set the attribute 'att' to 'value', do:: element['att'] = 'value' There are two special attributes: 'ids' and 'names'. Both are lists of unique identifiers, and names serve as human interfaces to IDs. Names are case- and whitespace-normalized (see the fully_normalize_name() function), and IDs conform to the regular expression ``[a-z](-?[a-z0-9]+)*`` (see the make_id() function). Elements also emulate lists for child nodes (element nodes and/or text nodes), indexing by integer. To get the first child node, use:: element[0] Elements may be constructed using the ``+=`` operator. To add one new child node to element, do:: element += node This is equivalent to ``element.append(node)``. To add a list of multiple child nodes at once, use the same ``+=`` operator:: element += [node1, node2] This is equivalent to ``element.extend([node1, node2])``. )idsclassesnamesdupnames)backrefs)rrbNz rVcOs||_g|_||i|_x|jD]}g|j|<q$WxHt|D]8\}}|}||jkrr|dd|j|<qD||j|<qDW|jdkr|j j |_dS)N) rbr*r4 attributeslist_attributeslistitemslowerrfr$r%)rrbr*ryattvaluerrrrcs    zElement.__init__cCst||j}xB|D]6\}}t|tr.z%s) createElementrfattlistr2r{rXZ setAttributer* appendChildr)rrelement attributerr rrrrs   zElement._dom_nodecCsd}x8|jD].}||7}t|dkr |ddd}Pq W|drld|jjddd |dD|fSd |jj|fSdS) NrV<8z ...rvz <%s "%s": %s>z; cSsg|] }t|qSr)rS)rknrrrrl sz$Element.__repr__..z<%s: %s>)r*rhrBr$r%rX)rracrrrrOs   zElement.__repr__cCs:|dr,d|jjddd|dDfSd|jSdS)Nrvz <%s "%s"...>z; cSsg|] }t|qSr)rS)rkrrrrrlsz%Element.shortrepr..z<%s...>)r$r%rXrf)rrrrrhszElement.shortreprcCs:|jr.d|ddd|jD|fS|SdS)Nz%s%s%srVcSsg|] }t|qSr)r)rkrrrrrlsz'Element.__unicode__..)r*starttagrXendtagemptytag)rrrr __unicode__s  zElement.__unicode__)rcCs|dkr t}|jg}xr|D]f\}}|dkr>|d|qt|trbdd|D}d|}nt|}||}|d||fqWdd|S)Nz %s="True"cSsg|]}td|fqS)z%s)r)rkrrrrrl-sz$Element.starttag..rz%s=%sz<%s>)pseudo_quoteattrrfrr3r2r{rXr)r quoteattrpartsnamervaluesrrrr#s  zElement.starttagcCs d|jS)Nz)rf)rrrrr5szElement.endtagcCs$dd|jgdd|DS)Nz<%s/>rcSsg|]\}}d||fqS)z%s="%s"r)rkrrrrrrl:sz$Element.emptytag..)rXrfr)rrrrr8s zElement.emptytagcCs t|jS)N)rBr*)rrrr__len__=szElement.__len__cCst|tr||jkS||jkS)N)r2rryr*)rkeyrrr __contains__@s  zElement.__contains__cCsbt|tr|j|St|tr(|j|St|trV|jdksDtd|j|j|j St ddS)N)Nr@zcannot handle slice with stridezFelement index must be an integer, a slice, or an attribute name string) r2rryintr*slicestepAssertionErrorstartr/r_)rrrrr __getitem__Gs     zElement.__getitem__cCst|tr||jt|<npt|tr:||||j|<nPt|tr|jdksVtdx|D]}||q\W||j|j |j <nt ddS)N)Nr@zcannot handle slice with stridezFelement index must be an integer, a slice, or an attribute name string) r2rryrr!r*rrrrr/r_)rritemr9rrr __setitem__Ss      zElement.__setitem__cCsbt|tr|j|=nJt|tr(|j|=n6t|trV|jdksDtd|j|j|j =nt ddS)N)Nr@zcannot handle slice with stridezMelement index must be an integer, a simple slice, or an attribute name string) r2rryrr*rrrrr/r_)rrrrr __delitem__bs     zElement.__delitem__cCs |j|S)N)r*)rotherrrr__add__nszElement.__add__cCs ||jS)N)r*)rrrrr__radd__qszElement.__radd__cCs,t|tr||n|dk r(|||S)z4Append a node or a list of nodes to `self.children`.N)r2rr3r4)rrrrr__iadd__ts    zElement.__iadd__cCs|jdd|jDS)NcSsg|] }|qSr)r)rkr rrrrl~sz"Element.astext..)child_text_separatorrXr*)rrrrr|szElement.astextcCs6i}x,t|jD]\}}||r|||<qW|S)N)r{ryr|is_not_default)rZattsrrrrrnon_default_attributess   zElement.non_default_attributescCst|}||S)N)r{rr|sort)rrrrrrszElement.attlistcCs|j||S)N)ryget)rrfailobjrrrrsz Element.getcCs ||jkS)N)ry)rattrrrrhasattrszElement.hasattrcCs||jkr|j|=dS)N)ry)rrrrrdelattrs zElement.delattrcCs|j||S)N)ry setdefault)rrrrrrrszElement.setdefaultcCsRx*|dgD]}|dr|ddSqWy |j|Stk rL|SXdS)zReturn node's language tag. Look iteratively in self and parents for a class argument starting with ``language-`` and return the remainder of it (which should be a `BCP49` language tag) or the `fallback`. ruz language- N)r startswithrZ get_languageAttributeError)rfallbackr6rrrget_language_codes  zElement.get_language_codecCs|||j|dS)N)r!r*r3)rrrrrr3s zElement.appendcCsx|D]}||qWdS)N)r3)rrr9rrrr4s zElement.extendcCs<t|tr$|||j||n|dk r8||||<dS)N)r2rr!r*insert)rrDrrrrrs   zElement.insertcCs |j|S)N)r*pop)rirrrrsz Element.popcCs|j|dS)N)r*remove)rrrrrrszElement.removecCs |j|S)N)r*rD)rrrrrrDsz Element.indexcCs"||gkr||jkrdSdSdS)Nrr@)rz)rrrrrrszElement.is_not_defaultcCs8t|tr|j}x"|jD]}||||gqWdS)z Update basic attributes ('ids', 'names', 'classes', 'dupnames', but not 'source') from node or dictionary `dict_`. N)r2rrybasic_attributesappend_attr_listr)rdict_r~rrrupdate_basic_attss  zElement.update_basic_attscCs,x&|D]}|||kr|||qWdS)z For each element in values, if it does not exist in self[attr], append it. NOTE: Requires self[attr] and values to be sequence type and the former should specifically be a list. N)r3)rrrrrrrrs  zElement.append_attr_listcCs>t||ts||g||<t|ts.|g}|||dS)a  First, convert both self[attr] and value to a non-string sequence type; if either is not already a sequence, convert it to a list of one element. Then call append_attr_list. NOTE: self[attr] and value both must not be None. N)r2rr{r)rrrrrrcoerce_append_attr_lists  zElement.coerce_append_attr_listTcCs|s||dkr|||<dS)z If self[attr] does not exist or force is True or omitted, set self[attr] to value, otherwise do nothing. N)r)rrrforcerrr replace_attrszElement.replace_attrcCs|||k r|||dS)a If attr is an attribute of self, set self[attr] to [self[attr], value], otherwise set self[attr] to value. NOTE: replace is not used by this function and is kept only for compatibility with the other copy functions. N)rr)rrrrWrrrcopy_attr_convertszElement.copy_attr_convertcCsH|||k rDt||ts(t|tr6|||n||||dS)a If attr is an attribute of self and either self[attr] or value is a list, convert all non-sequence values to a sequence of 1 element and then concatenate the two sequence, setting the result to self[attr]. If both self[attr] and value are non-sequences and replace is True or self[attr] is None, replace self[attr] with value. Otherwise, do nothing. N)rr2r{rr)rrrrWrrrcopy_attr_coerces  zElement.copy_attr_coercecCsH|||k rDt||tr6t|tr6|||n||||dS)aM If attr is an attribute of self and both self[attr] and value are lists, concatenate the two sequences, setting the result to self[attr]. If either self[attr] or value are non-sequences and replace is True or self[attr] is None, replace self[attr] with value. Otherwise, do nothing. N)rr2r{rr)rrrrWrrrcopy_attr_concatenates  zElement.copy_attr_concatenatecCs |||k r||||dS)zz If replace is True or self[attr] is None, replace self[attr] with value. Otherwise, do nothing. N)rr)rrrrWrrrcopy_attr_consistent$szElement.copy_attr_consistentFcCsVt|tr|j}|r|j}n|j}||x$t||D]}||||||q8WdS)a. Updates all attributes from node or dictionary `dict_`. Appends the basic attributes ('ids', 'names', 'classes', 'dupnames', but not 'source') and then, for all other attributes in dict_, updates the same attribute in self. When attributes with the same identifier appear in both self and dict_, the two values are merged based on the value of update_fun. Generally, when replace is True, the values in self are replaced or merged with the values in dict_; otherwise, the values in self may be preserved or merged. When and_source is True, the 'source' attribute is included in the copy. NOTE: When replace is False, and self contains a 'source' attribute, 'source' is not replaced even when dict_ has a 'source' attribute, though it may still be merged into a list depending on the value of update_fun. NOTE: It is easier to call the update-specific methods then to pass the update_fun method to this function. N)r2rryis_not_list_attributeis_not_known_attributerfilter)rrZ update_funrW and_sourceZ filter_funr~rrrupdate_all_atts,s  zElement.update_all_attscCs||tj||dS)aC Updates all attributes from node or dictionary `dict_`. Appends the basic attributes ('ids', 'names', 'classes', 'dupnames', but not 'source') and then, for all other attributes in dict_, updates the same attribute in self. When attributes with the same identifier appear in both self and dict_ and replace is True, the values in self are replaced with the values in dict_; otherwise, the values in self are preserved. When and_source is True, the 'source' attribute is included in the copy. NOTE: When replace is False, and self contains a 'source' attribute, 'source' is not replaced even when dict_ has a 'source' attribute, though it may still be merged into a list depending on the value of update_fun. N)rrsr)rrrWrrrrupdate_all_atts_consistantlyRs z$Element.update_all_atts_consistantlycCs||tj||dS)a Updates all attributes from node or dictionary `dict_`. Appends the basic attributes ('ids', 'names', 'classes', 'dupnames', but not 'source') and then, for all other attributes in dict_, updates the same attribute in self. When attributes with the same identifier appear in both self and dict_ whose values aren't each lists and replace is True, the values in self are replaced with the values in dict_; if the values from self and dict_ for the given identifier are both of list type, then the two lists are concatenated and the result stored in self; otherwise, the values in self are preserved. When and_source is True, the 'source' attribute is included in the copy. NOTE: When replace is False, and self contains a 'source' attribute, 'source' is not replaced even when dict_ has a 'source' attribute, though it may still be merged into a list depending on the value of update_fun. N)rrsr)rrrWrrrrupdate_all_atts_concatenatinggs z%Element.update_all_atts_concatenatingcCs||tj||dS)a[ Updates all attributes from node or dictionary `dict_`. Appends the basic attributes ('ids', 'names', 'classes', 'dupnames', but not 'source') and then, for all other attributes in dict_, updates the same attribute in self. When attributes with the same identifier appear in both self and dict_ whose values are both not lists and replace is True, the values in self are replaced with the values in dict_; if either of the values from self and dict_ for the given identifier are of list type, then first any non-lists are converted to 1-element lists and then the two lists are concatenated and the result stored in self; otherwise, the values in self are preserved. When and_source is True, the 'source' attribute is included in the copy. NOTE: When replace is False, and self contains a 'source' attribute, 'source' is not replaced even when dict_ has a 'source' attribute, though it may still be merged into a list depending on the value of update_fun. N)rrsr)rrrWrrrrupdate_all_atts_coercions z Element.update_all_atts_coercioncCs|j|tj|ddS)a} Updates all attributes from node or dictionary `dict_`. Appends the basic attributes ('ids', 'names', 'classes', 'dupnames', but not 'source') and then, for all other attributes in dict_, updates the same attribute in self. When attributes with the same identifier appear in both self and dict_ then first any non-lists are converted to 1-element lists and then the two lists are concatenated and the result stored in self; otherwise, the values in self are preserved. When and_source is True, the 'source' attribute is included in the copy. NOTE: When replace is False, and self contains a 'source' attribute, 'source' is not replaced even when dict_ has a 'source' attribute, though it may still be merged into a list depending on the value of update_fun. )rN)rrsr)rrrrrrupdate_all_atts_converts zElement.update_all_atts_convertcCs g|_dS)N)r*)rrrrclearsz Element.clearcCsD||}t|tr(|||||<n|dk r@||||d<dS)z8Replace one child `Node` with another child or children.Nr@)rDr2rr!)roldnewrDrrrrWs     zElement.replacecCs|}t|ts4y |d}Wntk r2d}YnXt|trJ||n,x*|jD] }||rRtd|||fqRW|j||dS)zc Replace `self` node with `new`, where `new` is a node or a list of nodes. rNzLosing "%s" attribute: %s) r2rrFrsrrrrrW)rrupdater~rrr replace_selfs       zElement.replace_selfrcCsRt|ts|f}x.)rXrr*)rrrr)rrrrs zElement.pformatcCs4|jfd|ji|j}|j|_|j|_|j|_|S)Nrb)r$rbryrrr)robjrrrrs z Element.copycCs"|}|dd|jD|S)NcSsg|] }|qSr)r)rkr rrrrlsz$Element.deepcopy..)rr4r*)rrrrrrszElement.deepcopycCs2tjdtddd|kst|d|dS)z+Add a new class to the "classes" attribute.zadocutils.nodes.Element.set_class deprecated; append to Element['classes'] list attribute directly) stacklevelrruN)warningswarnDeprecationWarningrr3r})rrrrr set_class s  zElement.set_classcCsZd|_t|di|}t|di|}|r@|dk s:td|_|rV|dk sPtd|_dS)zQNote that this Element has been referenced by its name `name` or id `id`.r@Zexpect_referenced_by_nameZexpect_referenced_by_idN) referencedgetattrrr)rridZby_nameZby_idrrrnote_referenced_bys  zElement.note_referenced_bycCs ||jkS)z Returns True if and only if the given attribute is NOT one of the basic list attributes defined for all Elements. )rz)r6rrrrr"szElement.is_not_list_attributecCs ||jkS)zj Returns True if and only if the given attribute is NOT recognized by this class. )known_attributes)r6rrrrr*szElement.is_not_known_attribute)rV)N)N)N)rV)r)T)T)TF)TF)TF)F)rr)NN)Hr%rIrJrKrZlocal_attributesrzrrfrrcrrOrhrrLrMr rrrrrrrrrrrrrrrrrrZhas_keyrr3r4rrrrDrrrrrrrrrrrrrrrrWrmaxsizerrrrrrr classmethodrrrrrrrss#              %        rsc@seZdZdZdZdddZdS) TextElementa An element which directly contains text. Its children are all `Text` or `Inline` subclass nodes. You can check whether an element's context is inline simply by checking whether its immediate parent is a `TextElement` instance (including subclasses). This is handy for nodes like `image` that can appear both inline and as standalone body elements. If passing children to `__init__()`, make sure to set `text` to ``''`` or some other suitable value. rVcOs@|dkr(t|}tj|||f||ntj||f||dS)NrV)r]rsrc)rrbrZr*ryZtextnoderrrrcEs zTextElement.__init__N)rVrV)r%rIrJrKrrcrrrrr3s rc@seZdZdZdddZdS)FixedTextElementz5An element which directly contains preformatted text.rVcOs$tj|||f||d|jd<dS)Npreservez xml:space)rrcry)rrbrZr*ryrrrrcRszFixedTextElement.__init__N)rVrV)r%rIrJrKrcrrrrrNsrc@seZdZdZdS) ResolvablerN)r%rIrJresolvedrrrrr[src@seZdZddZdS) BackLinkablecCs|d|dS)Nrx)r3)rrefidrrr add_backrefbszBackLinkable.add_backrefN)r%rIrJrrrrrr`src@s eZdZdS)RootN)r%rIrJrrrrrjsrc@s eZdZdS)TitularN)r%rIrJrrrrrlsrc@seZdZdZdS)PreBibliographiczd d Zd?d d Zd dZ ddZ d@ddZ dAddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,ZdBd-d.Zd/d0ZdCd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z dS)Drz The document root element. Do not instantiate this class directly; use `docutils.utils.new_document()` instead. cOstj|f||d|_d|_||_||_g|_i|_i|_i|_ i|_ i|_ i|_ i|_ i|_i|_g|_g|_g|_g|_g|_g|_d|_d|_d|_g|_g|_ddl}|j||_d|_||_ dS)Nr@r)!rsrcrrsettingsr"indirect_targetssubstitution_defssubstitution_namesrefnamesrefidsnameids nametypesrt footnote_refs citation_refs autofootnotesautofootnote_refssymbol_footnotessymbol_footnote_refs footnotes citationsZautofootnote_startZsymbol_footnote_startid_startparse_messagestransform_messagesZdocutils.transformsZ transformsZ Transformer transformer decorationr)rrr"argskwargsZdocutilsrrrrcs<zdocument.__init__cCs|j}d|d<d|d<|S)zB Return dict with unpicklable references removed. Nr"r)__dict__r)rstaterrr __getstate__s zdocument.__getstate__NcCs6|dkrddlmm}|}||||S)z-Return a DOM representation of this document.Nr)r r r rrr)rr rrrrr s zdocument.asdomcCsxH|dD]<}||jkr |j||k r |jd|}|dkr ||7}q W|dsxp|dD]$}|jjt|}|r\||jkr\Pq\Wd}x:|r||jkr|jj|jjt|j}|jd7_qW|d |||j|<|S)NrtzDuplicate ID: "%s".rvrVr@) rtr"ZsevererZ id_prefixmake_idZauto_id_prefixrrr3)rr9msgnodermsgrrrrset_ids"  zdocument.set_idcCsHxB|dD]6}||jkr,||||||q ||j|<||j|<q WdS)a `self.nameids` maps names to IDs, while `self.nametypes` maps names to booleans representing hyperlink type (True==explicit, False==implicit). This method updates the mappings. The following state transition table shows how `self.nameids` ("ids") and `self.nametypes` ("types") change with new input (a call to this method), and what actions are performed ("implicit"-type system messages are INFO/1, and "explicit"-type system messages are ERROR/3): ==== ===== ======== ======== ======= ==== ===== ===== Old State Input Action New State Notes ----------- -------- ----------------- ----------- ----- ids types new type sys.msg. dupname ids types ==== ===== ======== ======== ======= ==== ===== ===== - - explicit - - new True - - implicit - - new False None False explicit - - new True old False explicit implicit old new True None True explicit explicit new None True old True explicit explicit new,old None True [#]_ None False implicit implicit new None False old False implicit implicit new,old None False None True implicit implicit new None True old True implicit implicit new old True ==== ===== ======== ======== ======= ==== ===== ===== .. [#] Do not clear the name-to-id map or invalidate the old target if both old and new targets are external and refer to identical URIs. The new target is invalidated regardless. rvN)rset_duplicate_name_idr)rr9rrexplicitrrrrset_name_id_map&s   zdocument.set_name_id_mapc Csf|j|}|j|}|p||j|<|r|rd}|dk r|j|} d|krp|d} | drpd| krp| d| krpd}|dkrt| |d|j|<|jj|d||g|d} |dkr|| 7}t||n&||j|<|dk r|j|} t| |n8|dk r|sd|j|<|j|} t| |t|||r8|sb|dk rb|jjd||g|d} |dkrb|| 7}dS)Nrrefurirvr@z%Duplicate explicit target name: "%s".)rx base_nodez%Duplicate implicit target name: "%s".)rrrtdupnamer"system_messageinfo) rr9rrrr Zold_idZ old_explicitrZold_noder"rrrrrMsL                 zdocument.set_duplicate_name_idcCs ||jkS)N)r)rrrrrhas_namewszdocument.has_namecCs"|||}|j|||dddS)N)r )rr!)rtargetrrrrrnote_implicit_target{s zdocument.note_implicit_targetcCs"|||}|j|||dddS)NT)r )rr!)rr(rrrrrnote_explicit_targets zdocument.note_explicit_targetcCs|j|dg|dS)Nrefname)rrr3)rr9rrr note_refnameszdocument.note_refnamecCs|j|dg|dS)Nr)rrr3)rr9rrr note_refidszdocument.note_refidcCs"|j||dr||dS)Nrv)rr3r,)rr(rrrnote_indirect_targets zdocument.note_indirect_targetcCs||dS)N)r)rr(rrrnote_anonymous_targetszdocument.note_anonymous_targetcCs|||j|dS)N)rr r3)rfootnoterrrnote_autofootnotes zdocument.note_autofootnotecCs|||j|dS)N)rr r3)rrefrrrnote_autofootnote_refs zdocument.note_autofootnote_refcCs|||j|dS)N)rr r3)rr0rrrnote_symbol_footnotes zdocument.note_symbol_footnotecCs|||j|dS)N)rrr3)rr2rrrnote_symbol_footnote_refs z!document.note_symbol_footnote_refcCs|||j|dS)N)rrr3)rr0rrr note_footnotes zdocument.note_footnotecCs0|||j|dg|||dS)Nr+)rr rr3r,)rr2rrrnote_footnote_refs zdocument.note_footnote_refcCs|j|dS)N)rr3)rcitationrrr note_citationszdocument.note_citationcCs0|||j|dg|||dS)Nr+)rr rr3r,)rr2rrrnote_citation_refs zdocument.note_citation_refcCsft|}||jkrJ|jjd||d}|dkr6||7}|j|}t||||j|<||jt|<dS)Nz-Duplicate substitution definition name: "%s".)r#)whitespace_normalize_namerr"errorr$rfully_normalize_name)rZsubdefZdef_namerrrZoldnoderrrnote_substitution_defs    zdocument.note_substitution_defcCst||d<dS)Nr+)r;)rZsubrefr+rrrnote_substitution_refszdocument.note_substitution_refcCs|j||dS)N)rZ add_pending)rpendingpriorityrrr note_pendingszdocument.note_pendingcCs|j|dS)N)rr3)rmessagerrrnote_parse_messageszdocument.note_parse_messagecCs|j|dS)N)rr3)rrCrrrnote_transform_messageszdocument.note_transform_messagecCs$||_|dkr||_n |d|_dS)Nr@)rr)rroffsetrrr note_sourceszdocument.note_sourcecCs*|j|j|jf|j}|j|_|j|_|S)N)r$rr"ryrr)rrrrrrs z document.copycCsB|jsr?rBrDrErGrrHrrrrrs<Y   '*    rc@s eZdZdS)titleN)r%rIrJrrrrrIsrIc@s eZdZdS)subtitleN)r%rIrJrrrrrJsrJc@s eZdZdS)rubricN)r%rIrJrrrrrKsrKc@s eZdZdS)docinfoN)r%rIrJrrrrrLsrLc@s eZdZdS)authorN)r%rIrJrrrrrMsrMc@s eZdZdS)authorsN)r%rIrJrrrrrNsrNc@s eZdZdS) organizationN)r%rIrJrrrrrOsrOc@s eZdZdS)addressN)r%rIrJrrrrrPsrPc@s eZdZdS)contactN)r%rIrJrrrrrQsrQc@s eZdZdS)versionN)r%rIrJrrrrrRsrRc@s eZdZdS)revisionN)r%rIrJrrrrrSsrSc@s eZdZdS)statusN)r%rIrJrrrrrTsrTc@s eZdZdS)dateN)r%rIrJrrrrrUsrUc@s eZdZdS) copyrightN)r%rIrJrrrrrVsrVc@seZdZddZddZdS)rcCs2t|jrt|jdts(|dt|jdS)Nr)rBr*r2headerr)rrrr get_headerszdecoration.get_headercCs0t|jrt|jdts&|t|jdS)Nr)rBr*r2footerr3)rrrr get_footer s zdecoration.get_footerN)r%rIrJrXrZrrrrrsrc@s eZdZdS)rWN)r%rIrJrrrrrWsrWc@s eZdZdS)rYN)r%rIrJrrrrrYsrYc@s eZdZdS)sectionN)r%rIrJrrrrr[sr[c@seZdZdZdS)topica Topics are terminal, "leaf" mini-sections, like block quotes with titles, or textual figures. A topic is just like a section, except that it has no subsections, and it doesn't have to conform to section placement rules. Topics are allowed wherever body elements (list, table, etc.) are allowed, but only at the top level of a section or document. Topics cannot nest inside topics, sidebars, or body elements; you can't have a topic inside a table, list, block quote, etc. N)r%rIrJrKrrrrr\s r\c@seZdZdZdS)sidebara Sidebars are like miniature, parallel documents that occur inside other documents, providing related or reference material. A sidebar is typically offset by a border and "floats" to the side of the page; the document's main text may flow around it. Sidebars can also be likened to super-footnotes; their content is outside of the flow of the document's main text. Sidebars are allowed wherever body elements (list, table, etc.) are allowed, but only at the top level of a section or document. Sidebars cannot nest inside sidebars, topics, or body elements; you can't have a sidebar inside a table, list, block quote, etc. N)r%rIrJrKrrrrr]*sr]c@s eZdZdS) transitionN)r%rIrJrrrrr^;sr^c@s eZdZdS) paragraphN)r%rIrJrrrrr_Bsr_c@s eZdZdS)compoundN)r%rIrJrrrrr`Csr`c@s eZdZdS) containerN)r%rIrJrrrrraDsrac@s eZdZdS) bullet_listN)r%rIrJrrrrrbEsrbc@s eZdZdS)enumerated_listN)r%rIrJrrrrrcFsrcc@s eZdZdS) list_itemN)r%rIrJrrrrrdGsrdc@s eZdZdS)definition_listN)r%rIrJrrrrreHsrec@s eZdZdS)definition_list_itemN)r%rIrJrrrrrfIsrfc@s eZdZdS)termN)r%rIrJrrrrrgJsrgc@s eZdZdS) classifierN)r%rIrJrrrrrhKsrhc@s eZdZdS) definitionN)r%rIrJrrrrriLsric@s eZdZdS) field_listN)r%rIrJrrrrrjMsrjc@s eZdZdS)fieldN)r%rIrJrrrrrkNsrkc@s eZdZdS) field_nameN)r%rIrJrrrrrlOsrlc@s eZdZdS) field_bodyN)r%rIrJrrrrrmPsrmc@seZdZdZdS)optionrVN)r%rIrJrrrrrrnSsrnc@seZdZddZdS)option_argumentcCs|ddt|S)N delimiterr)rrr)rrrrrZszoption_argument.astextN)r%rIrJrrrrrroXsroc@seZdZdZdS) option_groupz, N)r%rIrJrrrrrrq^srqc@s eZdZdS) option_listN)r%rIrJrrrrrrcsrrc@seZdZdZdS)option_list_itemz N)r%rIrJrrrrrrsfsrsc@s eZdZdS) option_stringN)r%rIrJrrrrrtksrtc@s eZdZdS) descriptionN)r%rIrJrrrrrulsruc@s eZdZdS) literal_blockN)r%rIrJrrrrrvmsrvc@s eZdZdS) doctest_blockN)r%rIrJrrrrrwnsrwc@s eZdZdS) math_blockN)r%rIrJrrrrrxosrxc@s eZdZdS) line_blockN)r%rIrJrrrrrypsryc@seZdZdZdS)rN)r%rIrJrrrrrrssrc@s eZdZdS) block_quoteN)r%rIrJrrrrrzxsrzc@s eZdZdS) attributionN)r%rIrJrrrrr{ysr{c@s eZdZdS) attentionN)r%rIrJrrrrr|zsr|c@s eZdZdS)cautionN)r%rIrJrrrrr}{sr}c@s eZdZdS)dangerN)r%rIrJrrrrr~|sr~c@s eZdZdS)r<N)r%rIrJrrrrr<}sr<c@s eZdZdS) importantN)r%rIrJrrrrr~src@s eZdZdS)noteN)r%rIrJrrrrrsrc@s eZdZdS)tipN)r%rIrJrrrrrsrc@s eZdZdS)hintN)r%rIrJrrrrrsrc@s eZdZdS)warningN)r%rIrJrrrrrsrc@s eZdZdS) admonitionN)r%rIrJrrrrrsrc@s eZdZdS)commentN)r%rIrJrrrrrsrc@s eZdZdS)substitution_definitionN)r%rIrJrrrrrsrc@s eZdZdS)r(N)r%rIrJrrrrr(sr(c@s eZdZdS)r0N)r%rIrJrrrrr0sr0c@s eZdZdS)r8N)r%rIrJrrrrr8sr8c@s eZdZdS)labelN)r%rIrJrrrrrsrc@s eZdZdS)figureN)r%rIrJrrrrrsrc@s eZdZdS)captionN)r%rIrJrrrrrsrc@s eZdZdS)legendN)r%rIrJrrrrrsrc@s eZdZdS)tableN)r%rIrJrrrrrsrc@s eZdZdS)tgroupN)r%rIrJrrrrrsrc@s eZdZdS)colspecN)r%rIrJrrrrrsrc@s eZdZdS)theadN)r%rIrJrrrrrsrc@s eZdZdS)tbodyN)r%rIrJrrrrrsrc@s eZdZdS)rowN)r%rIrJrrrrrsrc@s eZdZdS)entryN)r%rIrJrrrrrsrc@s"eZdZdZdddZddZdS)r%z System message element. Do not instantiate this class directly; use ``document.reporter.info/warning/error/severe()`` instead. NcOs^|dd}|r$td|}|f|}ytj||f||Wntd|fYnXdS)NrbrVzsystem_message: children=%r)rr_rsrcprint)rrCr*ryrbprrrrcs   zsystem_message.__init__cCs0|dd}d|d||d|dt|fS)NrrVz%s:%s: (%s/%s) %srrAr)rrsr)rrrrrrs zsystem_message.astext)N)r%rIrJrKrcrrrrrr%s r%c@s,eZdZdZd ddZd dd Zd d ZdS)r@aF The "pending" element is used to encapsulate a pending operation: the operation (transform), the point at which to apply it, and any data it requires. Only the pending operation's location within the document is stored in the public document tree (by the "pending" object itself); the operation and its data are stored in the "pending" object's internal instance attributes. For example, say you want a table of contents in your reStructuredText document. The easiest way to specify where to put it is from within the document, with a directive:: .. contents:: But the "contents" directive can't do its work until the entire document has been parsed and possibly transformed to some extent. So the directive code leaves a placeholder behind that will trigger the second phase of its processing, something like this:: + internal attributes Use `document.note_pending()` so that the `docutils.transforms.Transformer` stage of processing can run all pending transforms. NrVcOs(tj||f||||_|p i|_dS)N)rsrc transformdetails)rrrrbr*ryrrrrcs zpending.__init__ rcsdd|jj|jjfdg}t|j}|x|D]\}}t|trx| dd|f| dd| Dq6|rt|trt|dtr| dd|fx>|D] }| d d| DqWq6| d d||fq6Wt |dfd d|DS) Nz.. internal attributes:z .transform: %s.%sz .details:z%7s%s:rVcSsg|]}dd|fqS)z%9s%srVr)rkrrrrrlsz#pending.pformat..rcSsg|]}dd|fqS)z%9s%srVr)rkrrrrrlsz %7s%s: %rcsg|]}d|fqS)z %s%s r)rkr)rrrrrls)rrIr%r{rr|rr2rr3r4rrnrsrX)rrrZ internalsrrrrr)rrrrs*      zpending.pformatcCs6|j|j|j|jf|j}|j|_|j|_|j|_|S)N)r$rrrbryrrr)rrrrrrs z pending.copy)NrV)rr)r%rIrJrKrcrrrrrrr@s  r@c@seZdZdZdS)rawz@ Raw data that is to be passed untouched to the Writer. N)r%rIrJrKrrrrrsrc@s eZdZdS)emphasisN)r%rIrJrrrrrsrc@s eZdZdS)strongN)r%rIrJrrrrrsrc@s eZdZdS)literalN)r%rIrJrrrrrsrc@s eZdZdS) referenceN)r%rIrJrrrrr src@s eZdZdS)footnote_referenceN)r%rIrJrrrrr src@s eZdZdS)citation_referenceN)r%rIrJrrrrr src@s eZdZdS)substitution_referenceN)r%rIrJrrrrr src@s eZdZdS)title_referenceN)r%rIrJrrrrr src@s eZdZdS) abbreviationN)r%rIrJrrrrrsrc@s eZdZdS)acronymN)r%rIrJrrrrrsrc@s eZdZdS) superscriptN)r%rIrJrrrrrsrc@s eZdZdS) subscriptN)r%rIrJrrrrrsrc@s eZdZdS)mathN)r%rIrJrrrrrsrc@seZdZddZdS)imagecCs |ddS)NZaltrV)r)rrrrrsz image.astextN)r%rIrJrrrrrrsrc@s eZdZdS)inlineN)r%rIrJrrrrrsrc@s eZdZdS) problematicN)r%rIrJrrrrrsrc@s eZdZdS) generatedN)r%rIrJrrrrrsra< Text abbreviation acronym address admonition attention attribution author authors block_quote bullet_list caption caution citation citation_reference classifier colspec comment compound contact container copyright danger date decoration definition definition_list definition_list_item description docinfo doctest_block document emphasis entry enumerated_list error field field_body field_list field_name figure footer footnote footnote_reference generated header hint image important inline label legend line line_block list_item literal literal_block math math_block note option option_argument option_group option_list option_list_item option_string organization paragraph pending problematic raw reference revision row rubric section sidebar status strong subscript substitution_definition substitution_reference subtitle superscript system_message table target tbody term tgroup thead tip title title_reference topic transition version warningc@s<eZdZdZdZddZddZddZd d Zd d Z d S) NodeVisitora "Visitor" pattern [GoF95]_ abstract superclass implementation for document tree traversals. Each node class has corresponding methods, doing nothing by default; override individual methods for specific and useful behaviour. The `dispatch_visit()` method is called by `Node.walk()` upon entering a node. `Node.walkabout()` also calls the `dispatch_departure()` method before exiting a node. The dispatch methods call "``visit_`` + node class name" or "``depart_`` + node class name", resp. This is a base class for visitors whose ``visit_...`` & ``depart_...`` methods should be implemented for *all* node types encountered (such as for `docutils.writers.Writer` subclasses). Unimplemented methods will raise exceptions. For sparse traversals, where only certain node types are of interest, subclass `SparseNodeVisitor` instead. When (mostly or entirely) uniform processing is desired, subclass `GenericNodeVisitor`. .. [GoF95] Gamma, Helm, Johnson, Vlissides. *Design Patterns: Elements of Reusable Object-Oriented Software*. Addison-Wesley, Reading, MA, USA, 1995. rcCs ||_dS)N)r)rrrrrrcjszNodeVisitor.__init__cCs:|jj}t|d||j}|jjd|j|f||S)z Call self."``visit_`` + node class name" with `node` as parameter. If the ``visit_...`` method does not exist, call self.unknown_visit. visit_z;docutils.nodes.NodeVisitor.dispatch_visit calling %s for %s)r$r%r unknown_visitrr"r#)rr9 node_namemethodrrrr&ms zNodeVisitor.dispatch_visitcCs:|jj}t|d||j}|jjd|j|f||S)z Call self."``depart_`` + node class name" with `node` as parameter. If the ``depart_...`` method does not exist, call self.unknown_departure. depart_z?docutils.nodes.NodeVisitor.dispatch_departure calling %s for %s)r$r%runknown_departurerr"r#)rr9rrrrrr1zs zNodeVisitor.dispatch_departurecCs2|jjjs|jj|jkr.td|j|jjfdS)zk Called when entering unknown `Node` types. Raise an exception unless overridden. z!%s visiting unknown node type: %sN)rrstrict_visitorr$r%optionalr)rr9rrrrs  zNodeVisitor.unknown_visitcCs2|jjjs|jj|jkr.td|j|jjfdS)zi Called before exiting unknown `Node` types. Raise exception unless overridden. z"%s departing unknown node type: %sN)rrrr$r%rr)rr9rrrrs  zNodeVisitor.unknown_departureN) r%rIrJrKrrcr&r1rrrrrrrCs    rc@seZdZdZdS)SparseNodeVisitora Base class for sparse traversals, where only certain node types are of interest. When ``visit_...`` & ``depart_...`` methods should be implemented for *all* node types (such as for `docutils.writers.Writer` subclasses), subclass `NodeVisitor` instead. N)r%rIrJrKrrrrrsrc@s eZdZdZddZddZdS)GenericNodeVisitora Generic "Visitor" abstract superclass, for simple traversals. Unless overridden, each ``visit_...`` method calls `default_visit()`, and each ``depart_...`` method (when using `Node.walkabout()`) calls `default_departure()`. `default_visit()` (and `default_departure()`) must be overridden in subclasses. Define fully generic visitors by overriding `default_visit()` (and `default_departure()`) only. Define semi-generic visitors by overriding individual ``visit_...()`` (and ``depart_...()``) methods also. `NodeVisitor.unknown_visit()` (`NodeVisitor.unknown_departure()`) should be overridden for default behavior. cCstdS)z)Override for generic, uniform traversals.N)r)rr9rrr default_visitsz GenericNodeVisitor.default_visitcCstdS)z)Override for generic, uniform traversals.N)r)rr9rrrdefault_departuresz$GenericNodeVisitor.default_departureN)r%rIrJrKrrrrrrrsrcCs||dS)N)r)rr9rrr_call_default_visitsrcCs||dS)N)r)rr9rrr_call_default_departuresrcCsdS)Nr)rr9rrr_nopsrcCsRxL|D]D}ttd|tttd|tttd|tttd|tqWdS)z%Save typing with dynamic assignments:rrN)setattrrrrrr)rv_namerrr_add_node_class_namess  rc@s0eZdZdZddZddZddZdd Zd S) TreeCopyVisitorzQ Make a complete copy of a tree or branch, including element attributes. cCst||g|_g|_dS)N)rrc parent_stackr)rrrrrrcs zTreeCopyVisitor.__init__cCs |jdS)Nr)r)rrrr get_tree_copyszTreeCopyVisitor.get_tree_copycCs,|}|j||j|j||_dS)z9Copy the current node, and make it the new acting parent.N)rrr3r)rr9Znewnoderrrrs zTreeCopyVisitor.default_visitcCs|j|_dS)z#Restore the previous acting parent.N)rrr)rr9rrrrsz!TreeCopyVisitor.default_departureN)r%rIrJrKrcrrrrrrrrs rc@seZdZdZdS)TreePruningExceptionz Base class for `NodeVisitor`-related tree pruning exceptions. Raise subclasses from within ``visit_...`` or ``depart_...`` methods called from `Node.walk()` and `Node.walkabout()` tree traversals to prune the tree traversed. N)r%rIrJrKrrrrrsrc@seZdZdZdS)r'z Do not visit any children of the current node. The current node's siblings and ``depart_...`` method are not affected. N)r%rIrJrKrrrrr'sr'c@seZdZdZdS)r,z Do not visit any more siblings (to the right) of the current node. The current node's children and its ``depart_...`` method are not affected. N)r%rIrJrKrrrrr, sr,c@seZdZdZdS)r(zq Do not visit the current node's children, and do not call the current node's ``depart_...`` method. N)r%rIrJrKrrrrr(sr(c@seZdZdZdS)r)z Do not call the current node's ``depart_...`` method. The current node's children and siblings are not affected. N)r%rIrJrKrrrrr)sr)c@seZdZdZdS) NodeFoundz Raise to indicate that the target of a search has been found. This exception must be caught by the client; it is not caught by the traversal code. N)r%rIrJrKrrrrr'src@seZdZdZdS)r-a= Stop the traversal alltogether. The current node's ``depart_...`` method is not affected. The parent nodes ``depart_...`` methods are also called as usual. No other nodes are visited. This is an alternative to NodeFound that does not cause exception handling to trickle up to the caller. N)r%rIrJrKrrrrr-2sr-cCsr|}t|ts|}|t}|t}td| ddd}t dd | }t d|}t|S)a Convert `string` into an identifier and return it. Docutils identifiers will conform to the regular expression ``[a-z](-?[a-z0-9]+)*``. For CSS compatibility, identifiers (the "class" and "id" attributes) should have no underscores, colons, or periods. Hyphens may be used. - The `HTML 4.01 spec`_ defines identifiers based on SGML tokens: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). - However the `CSS1 spec`_ defines identifiers based on the "name" token, a tighter interpretation ("flex" tokenizer notation; "latin1" and "escape" 8-bit characters have been replaced with entities):: unicode \[0-9a-f]{1,4} latin1 [¡-ÿ] escape {unicode}|\[ -~¡-ÿ] nmchar [-a-z0-9]|{latin1}|{escape} name {nmchar}+ The CSS1 "nmchar" rule does not include underscores ("_"), colons (":"), or periods ("."), therefore "class" and "id" attributes should not contain these characters. They should be replaced with hyphens ("-"). Combined with HTML's requirements (the first character must be a letter; no "unicode", "latin1", or "escape" characters), this results in the ``[a-z](-?[a-z0-9]+)*`` pattern. .. _HTML 4.01 spec: http://www.w3.org/TR/html401 .. _CSS1 spec: http://www.w3.org/TR/REC-CSS1 ZNFKDrPignore-rrV)r}r2rdecode translate_non_id_translate_digraphs_non_id_translate unicodedata normalizer _non_id_charssubrXrY_non_id_at_ends)stringrrrrr?s#     rz [^a-z0-9]+z ^[-0-9]+|-+$odhrltbrfkrryzgjrReqrE)!ii'i1iBigiiiiiiiiiiiiiii%i4i5i6i7i<i?i@iGiIiKiMiOszZaeZoedbZqp)iSi8i9cCs&|d||d|d|_dS)Nrwrvr@)r3rr)r9rrrrr$sr$cCsd|S)z.Return a case- and whitespace-normalized name.r)rXr}rY)rrrrr=sr=cCsd|S)z$Return a whitespace-normalized name.r)rXrY)rrrrr;sr;cCs|ddddS)zDEscape string values that are elements of a list, for serialization.rUz\\rz\ )rW)rrrrrsrcCsd|S)zQuote attributes for pseudo-xmlz"%s"r)rrrrrsr)FF)rKZ __docformat__rLosrertypesrobjectrrMrrNrSr\r]rsrrrrrrrrrrrrrrrrrrrrrrrIrJrKrLrMrNrOrPrQrRrSrTrUrVrrWrYr[r\r]r^r_r`rarbrcrdrerfrgrhrirjrkrlrmrnrorqrrrsrtrurvrwrxryrrzr{r|r}r~r<rrrrrrrrr(r0r8rrrrrrrrrrrr%r@rrrrrrrrrrrrrrrrrrrYZnode_class_namesrrrrrrrr Exceptionrr'r,r(r)rr-rcompilerrrrr$r=r;rrrrrrs  K   N I "]            1