B \-"@s dZdZddlZddlZddlZddlZddlZddlZGdddeZ ej dkrdGddde Z ne Z d d Z Gd d d e e ZGd dde ZGdddeZGdddeZGdddZGdddZGdddZGdddZGdddZGdddZGdd d eZGd!d"d"ZGd#d$d$ZGd%d&d&eZGd'd(d(eZGd)d*d*eZGd+d,d,eZGd-d.d.eZGd/d0d0Z Gd1d2d2Z!Gd3d4d4eZ"Gd5d6d6eZ#Gd7d8d8Z$Gd9d:d:eeeZ%Gd;d<dd>eeeZ'Gd?d@d@eeZ(GdAdBdBeeZ)GdCdDdDeeZ*GdEdFdFeeZ+GdGdHdHeeZ,GdIdJdJeeZ-GdKdLdLeeZ.GdMdNdNeeZ/GdOdPdPeeZ0GdQdRdReeZ1GdSdTdTeeZ2GdUdVdVeeZ3GdWdXdXeeZ4GdYdZdZeeZ5Gd[d\d\eeZ6Gd]d^d^eeZ7Gd_d`d`eeZ8GdadbdbeeZ9GdcddddeeZ:GdedfdfeeZ;GdgdhdheeZGdmdndneeZ?Gdodpdpe eZ@GdqdrdreeZAGdsdtdte eZBGdudvdve eZCGdwdxdxe eZDGdydzdze eZEGd{d|d|eeZFGd}d~d~e eZGGddde eZHGddde eZIGddde eZJGddde eZKGddde eZLGdddeeZMGddde eZNGddde eZOGddde eZPGdddeeZQGdddeeZRGdddeeZSGdddeeZTGddde eZUGdddeeZVGddde eZWGdddeeZXGdddeeZYGdddeeZZGdddeeZ[GdddeeZ\GdddeeZ]GdddeeZ^GdddeeZ_GdddeeZ`GdddeeZaGdddeeeZbGdddeeeZcGdddeee!ee#ZdGdddeeee$e#ZeGdddeeee$e#ZfGddde eZgGdddeeZhGdd„de eZiGddĄde eZjGddƄdeeZkGddȄde eZlGddʄde eZmGdd̄de eZnGdd΄de eZoGddЄde eZpGdd҄de eZqGddԄdeeeeZrGddքdeeeZsGdd؄dee!eeZtGddڄde!eZuGdd܄de!eZvGddބde!eZwGdddee!e"eZxGddde!e"eZyGddde!e"eZzGddde!eZ{Gddde!eZ|Gddde!eZ}Gddde!eZ~Gddde!eZGddde!eZGddde!eZGdddee!eZGddde!eZGddde!eZGddde!eZdZGdddZGdddeZGdddeZddZddZddZdd ZeeGd d d eZGd d d eZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZddZedZedZddd d!d"d#d$d$d%dd&d'd"d(d)d#d#d*d+d,d+d"d(d#d-d%d.d+d/d-d0d1d*d2!Zd3d4d5d6d7d8Zd9d:Zd;d<Zd=d>Zd?d@ZdAdBZdS(Ca 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 ddZddZddZddZddZddZddZd$ddZd%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)selfrr2/tmp/pip-build-uw_ogi45/docutils/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.deepcopycCs@||_|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)rrrrr*es,     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)rrrrr/s<         zNode.walkaboutcCs<g}t||r||x|jD]}|||q W|S)z:Specialized traverse() that only supports instance checks.) isinstanceappendr)extend_fast_traverse)rclsresultrrrrr4s    zNode._fast_traversecCs0g}||x|jD]}||qW|S)z:Specialized traverse() that doesn't check for a condition.)r2r)r3 _all_traverse)rr6rrrrr7s   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)r1)node node_classrrr conditionsz Node.traverse..conditionF) include_selfdescendsiblingsascendr:) r7r1typer4r2lenr)r3traverserindex) rr:r;r<r=r>r9rrr8rCZsiblingrrrrBs>%             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)rB IndexError)rr:r;r<r=r>iterablerrr next_nodes  zNode.next_node)N)rr)NTTFF)NFTFF)r$ __module__ __qualname____doc__rrrrrsys version_infor rrrrr r*r/r4r7rBrGrrrrr$s*    .+  Jr)rc@seZdZdZddZdS) reprunicodezU A unicode sub-class that removes the initial u from unicode's repr. cCst|ddS)Nr?)r__repr__)rrrrrN1szreprunicode.__repr__N)r$rHrIrJrNrrrrrM,srMcCs$tjdkr t|tr |ddS|S)z4 Failsave conversion of `unicode` to `str`. )rasciibackslashreplace)rKrLr1rr )srrr ensure_str9s rRc@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)r1bytes TypeErrorrM__new__)r5data rawsourcerrrrVPs z Text.__new__cCs t||S)z7Prevent the rawsource argument from propagating to str.)rMrV)r5rWrXrrrrVVscCs ||_dS)N)rX)rrWrXrrr__init__Zsz Text.__init__cCs6|}t||kr$|d|dd}d|jt|fS)Nz ...z<%s: %r>)rAtagnamerM)rmaxlenrWrrr shortrepr_s zText.shortreprcCs |jddS)ND)r^)r_)rrrrrNesz Text.__repr__cCs|t|S)N)ZcreateTextNoder)rrrrrrhszText._dom_nodecCst|S)N)rM)rrrrastextksz Text.astextcCs|jt||jdS)N)rX)r#rMrX)rrrrrwsz Text.copycCs|S)N)r)rrrrrzsz Text.deepcopy rcCs:g}||}x"|D]}|||dqWd|S)N rY) splitlinesr2join)rrrr6rrrrr}s z Text.pformatcCs|t||S)N)r#rMrstrip)rcharsrrrrfsz Text.rstripcCs|t||S)N)r#rMlstrip)rrgrrrrhsz Text.lstrip)N)N)rY)r[)rbr)N)N)r$rHrIrJr]r)rKrLrVrZr_rNrrarrrrfrhrrrrrSBs        rSc@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)rNz rYcOs||_g|_||i|_x|jD]}g|j|<q$WxHt|D]8\}}|}||jkrr|dd|j|<qD||j|<qDW|jdkr|j j |_dS)N) rXr)r3 attributeslist_attributeslistitemslowerr]r#r$)rrXr)roattvaluerrrrZs    zElement.__init__cCst||j}xB|D]6\}}t|trsz%Element._dom_node..z%s) createElementr]attlistr1rqreZ setAttributer) appendChildr)rrelement attributerurrrrrs   zElement._dom_nodecCsd}x8|jD].}||7}t|dkr |ddd}Pq W|drld|jjddd |dD|fSd |jj|fSdS) NrY<8z ...rlz <%s "%s": %s>z; cSsg|] }t|qSr)rR)rxnrrrrzsz$Element.__repr__..z<%s: %s>)r)r_rAr#r$re)rrWcrrrrNs   zElement.__repr__cCs:|dr,d|jjddd|dDfSd|jSdS)Nrlz <%s "%s"...>z; cSsg|] }t|qSr)rR)rxrrrrrzsz%Element.shortrepr..z<%s...>)r#r$rer])rrrrr_szElement.shortreprcCs:|jr.d|ddd|jD|fS|SdS)Nz%s%s%srYcSsg|] }t|qSr)r)rxrrrrrzsz'Element.__unicode__..)r)starttagreendtagemptytag)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)rw)rxryrrrrzsz$Element.starttag..rvz%s=%sz<%s>)pseudo_quoteattrr]r|r2r1rqrer)r quoteattrpartsnameruvaluesrrrrs  zElement.starttagcCs d|jS)Nz)r])rrrrr#szElement.endtagcCs$dd|jgdd|DS)Nz<%s/>rvcSsg|]\}}d||fqS)z%s="%s"r)rxrryrrrrz(sz$Element.emptytag..)rer]r|)rrrrr&s zElement.emptytagcCs t|jS)N)rAr))rrrr__len__+szElement.__len__cCst|tr||jkS||jkS)N)r1rror))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) r1rrointr)slicestepAssertionErrorstartr.rU)rrrrr __getitem__5s     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) r1rrorr r)rrrrr.rU)rritemr8rrr __setitem__As      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) r1rrorr)rrrrr.rU)rrrrr __delitem__Ps     zElement.__delitem__cCs |j|S)N)r))rotherrrr__add__\szElement.__add__cCs ||jS)N)r))rrrrr__radd___szElement.__radd__cCs,t|tr||n|dk r(|||S)z4Append a node or a list of nodes to `self.children`.N)r1rr2r3)rrrrr__iadd__bs    zElement.__iadd__cCs|jdd|jDS)NcSsg|] }|qSr)ra)rxrrrrrzlsz"Element.astext..)child_text_separatorrer))rrrrrajszElement.astextcCs6i}x,t|jD]\}}||r|||<qW|S)N)rqrorris_not_default)rZattsrrurrrnon_default_attributesns   zElement.non_default_attributescCst|}||S)N)rqrrrsort)rr|rrrr|uszElement.attlistcCs|j||S)N)roget)rrfailobjrrrrzsz Element.getcCs ||jkS)N)ro)rattrrrrhasattr}szElement.hasattrcCs||jkr|j|=dS)N)ro)rrrrrdelattrs zElement.delattrcCs|j||S)N)ro 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`. rkz language- N)r startswithrZ get_languageAttributeError)rfallbackr5rrrget_language_codes  zElement.get_language_codecCs|||j|dS)N)r r)r2)rrrrrr2s zElement.appendcCsx|D]}||qWdS)N)r2)rrr8rrrr3s zElement.extendcCs<t|tr$|||j||n|dk r8||||<dS)N)r1rr r)insert)rrCrrrrrs   zElement.insertcCs |j|S)N)r)pop)rirrrrsz Element.popcCs|j|dS)N)r)remove)rrrrrrszElement.removecCs |j|S)N)r)rC)rrrrrrCsz Element.indexcCs"||gkr||jkrdSdSdS)Nrr?)rp)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)r1rrobasic_attributesappend_attr_listr)rdict_rtrrrupdate_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)r2)rrrrurrrrs  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)r1rrqr)rrrurrrcoerce_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)rrruforcerrr 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)rrrureplacerrrcopy_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)rr1rqrr)rrrurrrrcopy_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)rr1rqrr)rrrurrrrcopy_attr_concatenates  zElement.copy_attr_concatenatecCs |||k r||||dS)zz If replace is True or selfpattr] is None, replace self[attr] with value. Otherwise, do nothing. N)rr)rrrurrrrcopy_attr_consistentszElement.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)r1rrois_not_list_attributeis_not_known_attributerfilter)rrZ update_funr and_sourceZ filter_funrtrrrupdate_all_attss  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)rrir)rrrrrrrupdate_all_atts_consistantly@s 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)rrir)rrrrrrrupdate_all_atts_concatenatingUs 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)rrir)rrrrrrrupdate_all_atts_coercionms 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)rrir)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?)rCr1rr )roldnewrCrrrrs     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) r1rrErirrrrr)rrupdatertrrr replace_selfs       zElement.replace_selfrcCsRt|ts|f}x.)rerr))rrrr)rrrrs zElement.pformatcCs|jfd|ji|jS)NrX)r#rXro)rrrrrsz Element.copycCs"|}|dd|jD|S)NcSsg|] }|qSr)r)rxrrrrrzsz$Element.deepcopy..)rr3r))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) stacklevelrvrkN)warningswarnDeprecationWarningrr2rs)rrrrr set_classs  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. )rp)r5rrrrr szElement.is_not_list_attributecCs ||jkS)zj Returns True if and only if the given attribute is NOT recognized by this class. )known_attributes)r5rrrrrszElement.is_not_known_attribute)rY)N)N)N)rY)r)T)T)TF)TF)TF)F)rr)NN)Hr$rHrIrJrZlocal_attributesrprr]rrZrrNr_rrKrLr rrrrrrrrrrrrarr|rrrrZhas_keyrr2r3rrrrCrrrrrrrrrrrrrrrrrmaxsizerrrrrrr classmethodrrrrrrris#              %        ric@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. rYcOs@|dkr(t|}tj|||f||ntj||f||dS)NrY)rSrirZ)rrXtextr)roZtextnoderrrrZ/s zTextElement.__init__N)rYrY)r$rHrIrJrrZrrrrrs rc@seZdZdZdddZdS)FixedTextElementz5An element which directly contains preformatted text.rYcOs$tj|||f||d|jd<dS)NZpreservez xml:space)rrZro)rrXrr)rorrrrZ<szFixedTextElement.__init__N)rYrY)r$rHrIrJrZrrrrr8src@seZdZdZdS) ResolvablerN)r$rHrIZresolvedrrrrrEsrc@seZdZddZdS) BackLinkablecCs|d|dS)Nrn)r2)rrefidrrr add_backrefLszBackLinkable.add_backrefN)r$rHrIrrrrrrJsrc@s eZdZdS)RootN)r$rHrIrrrrrTsrc@s eZdZdS)TitularN)r$rHrIrrrrrVsrc@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)!rirZrrsettingsr!indirect_targetssubstitution_defssubstitution_namesrefnamesrefidsnameids nametypesrj footnote_refs citation_refs autofootnotesautofootnote_refssymbol_footnotessymbol_footnote_refs footnotes citationsZautofootnote_startZsymbol_footnote_startid_startparse_messagestransform_messagesZdocutils.transformsZ transformsZ Transformer transformer decorationr)rrr!argskwargsZdocutilsrrrrZs<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 rr}r)rr rrrrrs 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)NrjzDuplicate ID: "%s".rlrYr?) rjr!ZsevererZ id_prefixmake_idZauto_id_prefixrrr2)rr8msgnodermsgrrrrset_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. rlN)rset_duplicate_name_idr)rr8rrexplicitrrrrset_name_id_maps   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)Nrrefurirlr?z%Duplicate explicit target name: "%s".)rn base_nodez%Duplicate implicit target name: "%s".)rrrjdupnamer!system_messageinfo) rr8rrrrZold_idZ old_explicitrZold_noderrrrrr7sL                 zdocument.set_duplicate_name_idcCs ||jkS)N)r)rrrrrhas_nameaszdocument.has_namecCs"|||}|j|||dddS)N)r)rr)rtargetrrrrrnote_implicit_targetes zdocument.note_implicit_targetcCs"|||}|j|||dddS)NT)r)rr)rrrrrrrnote_explicit_targetis zdocument.note_explicit_targetcCs|j|dg|dS)Nrefname)rrr2)rr8rrr note_refnamemszdocument.note_refnamecCs|j|dg|dS)Nr)rrr2)rr8rrr note_refidpszdocument.note_refidcCs"|j||dr||dS)Nrl)rr2r#)rrrrrnote_indirect_targetss zdocument.note_indirect_targetcCs||dS)N)r)rrrrrnote_anonymous_targetxszdocument.note_anonymous_targetcCs|||j|dS)N)rrr2)rfootnoterrrnote_autofootnote{s zdocument.note_autofootnotecCs|||j|dS)N)rrr2)rrefrrrnote_autofootnote_refs zdocument.note_autofootnote_refcCs|||j|dS)N)rrr2)rr'rrrnote_symbol_footnotes zdocument.note_symbol_footnotecCs|||j|dS)N)rrr2)rr)rrrnote_symbol_footnote_refs z!document.note_symbol_footnote_refcCs|||j|dS)N)rrr2)rr'rrr note_footnotes zdocument.note_footnotecCs0|||j|dg|||dS)Nr")rrrr2r#)rr)rrrnote_footnote_refs zdocument.note_footnote_refcCs|j|dS)N)rr2)rcitationrrr note_citationszdocument.note_citationcCs0|||j|dg|||dS)Nr")rrrr2r#)rr)rrrnote_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!errorrrfully_normalize_name)rZsubdefZdef_namerrrZoldnoderrrnote_substitution_defs    zdocument.note_substitution_defcCst||d<dS)Nr")r2)rZsubrefr"rrrnote_substitution_refszdocument.note_substitution_refcCs|j||dS)N)r Z add_pending)rpendingpriorityrrr note_pendingszdocument.note_pendingcCs|j|dS)N)r r2)rmessagerrrnote_parse_messageszdocument.note_parse_messagecCs|j|dS)N)r r2)rr:rrrnote_transform_messageszdocument.note_transform_messagecCs$||_|dkr||_n |d|_dS)Nr?)rr)rroffsetrrr note_sourceszdocument.note_sourcecCs|j|j|jf|jS)N)r#rr!ro)rrrrrsz document.copycCsB|jsrr?rrrrrs<Y   '*    rc@s eZdZdS)titleN)r$rHrIrrrrr@sr@c@s eZdZdS)subtitleN)r$rHrIrrrrrAsrAc@s eZdZdS)rubricN)r$rHrIrrrrrBsrBc@s eZdZdS)docinfoN)r$rHrIrrrrrCsrCc@s eZdZdS)authorN)r$rHrIrrrrrDsrDc@s eZdZdS)authorsN)r$rHrIrrrrrEsrEc@s eZdZdS) organizationN)r$rHrIrrrrrFsrFc@s eZdZdS)addressN)r$rHrIrrrrrGsrGc@s eZdZdS)contactN)r$rHrIrrrrrHsrHc@s eZdZdS)versionN)r$rHrIrrrrrIsrIc@s eZdZdS)revisionN)r$rHrIrrrrrJsrJc@s eZdZdS)statusN)r$rHrIrrrrrKsrKc@s eZdZdS)dateN)r$rHrIrrrrrLsrLc@s eZdZdS) copyrightN)r$rHrIrrrrrMsrMc@seZdZddZddZdS)r cCs2t|jrt|jdts(|dt|jdS)Nr)rAr)r1headerr)rrrr get_headerszdecoration.get_headercCs0t|jrt|jdts&|t|jdS)Nr)rAr)r1footerr2)rrrr get_footers zdecoration.get_footerN)r$rHrIrOrQrrrrr sr c@s eZdZdS)rNN)r$rHrIrrrrrNsrNc@s eZdZdS)rPN)r$rHrIrrrrrPsrPc@s eZdZdS)sectionN)r$rHrIrrrrrRsrRc@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$rHrIrJrrrrrSs rSc@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$rHrIrJrrrrrTsrTc@s eZdZdS) transitionN)r$rHrIrrrrrU"srUc@s eZdZdS) paragraphN)r$rHrIrrrrrV)srVc@s eZdZdS)compoundN)r$rHrIrrrrrW*srWc@s eZdZdS) containerN)r$rHrIrrrrrX+srXc@s eZdZdS) bullet_listN)r$rHrIrrrrrY,srYc@s eZdZdS)enumerated_listN)r$rHrIrrrrrZ-srZc@s eZdZdS) list_itemN)r$rHrIrrrrr[.sr[c@s eZdZdS)definition_listN)r$rHrIrrrrr\/sr\c@s eZdZdS)definition_list_itemN)r$rHrIrrrrr]0sr]c@s eZdZdS)termN)r$rHrIrrrrr^1sr^c@s eZdZdS) classifierN)r$rHrIrrrrr_2sr_c@s eZdZdS) definitionN)r$rHrIrrrrr`3sr`c@s eZdZdS) field_listN)r$rHrIrrrrra4srac@s eZdZdS)fieldN)r$rHrIrrrrrb5srbc@s eZdZdS) field_nameN)r$rHrIrrrrrc6srcc@s eZdZdS) field_bodyN)r$rHrIrrrrrd7srdc@seZdZdZdS)optionrYN)r$rHrIrrrrrre:srec@seZdZddZdS)option_argumentcCs|ddt|S)N delimiterrv)rrra)rrrrraAszoption_argument.astextN)r$rHrIrarrrrrf?srfc@seZdZdZdS) option_groupz, N)r$rHrIrrrrrrhEsrhc@s eZdZdS) option_listN)r$rHrIrrrrriJsric@seZdZdZdS)option_list_itemz N)r$rHrIrrrrrrjMsrjc@s eZdZdS) option_stringN)r$rHrIrrrrrkRsrkc@s eZdZdS) descriptionN)r$rHrIrrrrrlSsrlc@s eZdZdS) literal_blockN)r$rHrIrrrrrmTsrmc@s eZdZdS) doctest_blockN)r$rHrIrrrrrnUsrnc@s eZdZdS) math_blockN)r$rHrIrrrrroVsroc@s eZdZdS) line_blockN)r$rHrIrrrrrpWsrpc@seZdZdZdS)rN)r$rHrIrrrrrrZsrc@s eZdZdS) block_quoteN)r$rHrIrrrrrq_srqc@s eZdZdS) attributionN)r$rHrIrrrrrr`srrc@s eZdZdS) attentionN)r$rHrIrrrrrsasrsc@s eZdZdS)cautionN)r$rHrIrrrrrtbsrtc@s eZdZdS)dangerN)r$rHrIrrrrrucsruc@s eZdZdS)r3N)r$rHrIrrrrr3dsr3c@s eZdZdS) importantN)r$rHrIrrrrrvesrvc@s eZdZdS)noteN)r$rHrIrrrrrwfsrwc@s eZdZdS)tipN)r$rHrIrrrrrxgsrxc@s eZdZdS)hintN)r$rHrIrrrrryhsryc@s eZdZdS)warningN)r$rHrIrrrrrzisrzc@s eZdZdS) admonitionN)r$rHrIrrrrr{jsr{c@s eZdZdS)commentN)r$rHrIrrrrr|ksr|c@s eZdZdS)substitution_definitionN)r$rHrIrrrrr}lsr}c@s eZdZdS)rN)r$rHrIrrrrrmsrc@s eZdZdS)r'N)r$rHrIrrrrr'nsr'c@s eZdZdS)r/N)r$rHrIrrrrr/osr/c@s eZdZdS)labelN)r$rHrIrrrrr~psr~c@s eZdZdS)figureN)r$rHrIrrrrrqsrc@s eZdZdS)captionN)r$rHrIrrrrrrsrc@s eZdZdS)legendN)r$rHrIrrrrrssrc@s eZdZdS)tableN)r$rHrIrrrrrtsrc@s eZdZdS)tgroupN)r$rHrIrrrrrusrc@s eZdZdS)colspecN)r$rHrIrrrrrvsrc@s eZdZdS)theadN)r$rHrIrrrrrwsrc@s eZdZdS)tbodyN)r$rHrIrrrrrxsrc@s eZdZdS)rowN)r$rHrIrrrrrysrc@s eZdZdS)entryN)r$rHrIrrrrrzsrc@s"eZdZdZdddZddZdS)rz System message element. Do not instantiate this class directly; use ``document.reporter.info/warning/error/severe()`` instead. NcOsR|rtd|}|f|}ytj|df||Wntd|fYnXdS)NrYzsystem_message: children=%r)rVrirZprint)rr:r)roprrrrZs  zsystem_message.__init__cCs0|dd}d|d||d|dt|fS)NrrYz%s:%s: (%s/%s) %srr@r)rrira)rrrrrras zsystem_message.astext)N)r$rHrIrJrZrarrrrr}s rc@s,eZdZdZd ddZd dd Zd d ZdS)r7aF 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. NrYcOs(tj||f||||_|p i|_dS)N)rirZ transformdetails)rrrrXr)rorrrrZs 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:rYcSsg|]}dd|fqS)z%9s%srYr)rxrrrrrzsz#pending.pformat..rcSsg|]}dd|fqS)z%9s%srYr)rxrrrrrzsz %7s%s: %rcsg|]}d|fqS)z %s%s r)rxr)rrrrrzs)rrHr$rqrrrrr1rr2r3rrdrire)rrrZ internalsrrruryr)rrrrs*      zpending.pformatcCs|j|j|j|jf|jS)N)r#rrrXro)rrrrrsz pending.copy)NrY)rr)r$rHrIrJrZrrrrrrr7s  r7c@seZdZdZdS)rawz@ Raw data that is to be passed untouched to the Writer. N)r$rHrIrJrrrrrsrc@s eZdZdS)emphasisN)r$rHrIrrrrrsrc@s eZdZdS)strongN)r$rHrIrrrrrsrc@s eZdZdS)literalN)r$rHrIrrrrrsrc@s eZdZdS) referenceN)r$rHrIrrrrrsrc@s eZdZdS)footnote_referenceN)r$rHrIrrrrrsrc@s eZdZdS)citation_referenceN)r$rHrIrrrrrsrc@s eZdZdS)substitution_referenceN)r$rHrIrrrrrsrc@s eZdZdS)title_referenceN)r$rHrIrrrrrsrc@s eZdZdS) abbreviationN)r$rHrIrrrrrsrc@s eZdZdS)acronymN)r$rHrIrrrrrsrc@s eZdZdS) superscriptN)r$rHrIrrrrrsrc@s eZdZdS) subscriptN)r$rHrIrrrrrsrc@s eZdZdS)mathN)r$rHrIrrrrrsrc@seZdZddZdS)imagecCs |ddS)NZaltrY)r)rrrrrasz image.astextN)r$rHrIrarrrrrsrc@s eZdZdS)inlineN)r$rHrIrrrrrsrc@s eZdZdS) problematicN)r$rHrIrrrrrsrc@s eZdZdS) generatedN)r$rHrIrrrrrsra< 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)rrrrrrZLszNodeVisitor.__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")rr8 node_namemethodrrrr%Os 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")rr8rrrrrr0\s 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)rr8rrrris  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)rr8rrrrus  zNodeVisitor.unknown_departureN) r$rHrIrJrrZr%r0rrrrrrr%s    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$rHrIrJrrrrrsrc@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)rr8rrr default_visitsz GenericNodeVisitor.default_visitcCstdS)z)Override for generic, uniform traversals.N)r)rr8rrrdefault_departuresz$GenericNodeVisitor.default_departureN)r$rHrIrJrrrrrrrsrcCs||dS)N)r)rr8rrr_call_default_visitsrcCs||dS)N)r)rr8rrr_call_default_departuresrcCsdS)Nr)rr8rrr_nopsrcCsRxL|D]D}ttd|tttd|tttd|tttd|tqWdS)z%Save typing with dynamic assignments:rrN)setattrrrrrr)rl_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)rrZ parent_stackr)rrrrrrZs 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)rrr2r)rr8Znewnoderrrrs zTreeCopyVisitor.default_visitcCs|j|_dS)z#Restore the previous acting parent.N)rrr)rr8rrrrsz!TreeCopyVisitor.default_departureN)r$rHrIrJrZrrrrrrrrs 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$rHrIrJrrrrrsrc@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$rHrIrJrrrrr&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$rHrIrJrrrrr+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$rHrIrJrrrrr'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$rHrIrJrrrrr(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$rHrIrJrrrrr 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$rHrIrJrrrrr,sr,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 ZNFKDrOignore-rvrY)rsr1rdecode translate_non_id_translate_digraphs_non_id_translate unicodedata normalizer _non_id_charssubresplit_non_id_at_ends)stringrrrrr!s#     rz [^a-z0-9]+z ^[-0-9]+|-+$odhrltbrfkrryzgjrQeqrD)!ii'i1iBigiiiiiiiiiiiiiii%i4i5i6i7i<i?i@iGiIiKiMiOszZaeZoedbZqp)iSi8i9cCs&|d||d|d|_dS)Nrmrlr?)r2rr)r8rrrrrsrcCsd|S)z.Return a case- and whitespace-normalized name.rv)rersr)rrrrr4sr4cCsd|S)z$Return a whitespace-normalized name.rv)rer)rrrrr2sr2cCs|ddddS)zDEscape string values that are elements of a list, for serialization.\z\\rvz\ )r)rurrrrwsrwcCsd|S)zQuote attributes for pseudo-xmlz"%s"r)rurrrrsr)rJZ __docformat__rKosrertypesrobjectrrLrrMrRrSrirrrrrrrrrrrrrrrrrrrrrrr@rArBrCrDrErFrGrHrIrJrKrLrMr rNrPrRrSrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrdrerfrhrirjrkrlrmrnrorprrqrrrsrtrur3rvrwrxryrzr{r|r}rr'r/r~rrrrrrrrrrrr7rrrrrrrrrrrrrrrrrrrZnode_class_namesrrrrrrrr Exceptionrr&r+r'r(rr,rcompilerrrrrr4r2rwrrrrrs   L   K E "]            1