U n^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. Tselfrrh/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/docutils/docutils/nodes.py__bool__4s z Node.__bool__cCst|dS)NZraw_unicode_escape)strencoderrrr__str__Bsz Node.__str__cCs,|dkrddlmm}|}||S)z6Return a DOM **fragment** representation of this Node.Nr)xml.dom.minidomdomminidomDocument _dom_noderrdomrootrrrasdomEsz Node.asdom rcCstdS)zs Return an indented pseudo-XML representation, for test purposes. Override in subclasses. NNotImplementedErrorrindentlevelrrrpformatLsz Node.pformatcCstdS)zReturn a copy of self.NrrrrrcopyTsz Node.copycCstdS)z3Return a deep copy of self (also copying children).NrrrrrdeepcopyXsz Node.deepcopycCstdS)z,Return a string representation of this Node.Nrrrrrastext\sz Node.astextcCs@||_|jr<|j|_|jdkr(|jj|_|jdkr<|jj|_dSN)parentdocumentsourcecurrent_sourceline current_line)rchildrrr setup_child`s   zNode.setup_childc Csd}|jjd|jjzz||Wn0ttfk rH|YWStk rZYnX|j }z(|ddD]}| |rpd}qqpWnt 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) r!reporterdebug __class____name__dispatch_visit SkipChildrenSkipNode SkipDeparturechildrenwalk SkipSiblings StopTraversal)rvisitorstopr0r&rrrr1is0     z Node.walkcCsd}d}|jjd|jjzz||Wn0tk rH|YWStk r^d}YnX|j}z(|ddD]}| |rtd}qqtWnt 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)r!r(r)r*r+r,r.r/r0 walkaboutr2r-r3dispatch_departure)rr4Z call_departr5r0r&rrrr6sD        zNode.walkaboutcCs8g}t||r|||jD]}|||q|S)z:Specialized traverse() that only supports instance checks.) isinstanceappendr0extend_fast_traverse)rclsresultr&rrrr;s    zNode._fast_traversecCs,g}|||jD]}||q|S)z:Specialized traverse() that doesn't check for a condition.)r9r0r: _all_traverse)rr=r&rrrr>s   zNode._all_traverseTFc Cs|rd}|r8|r8|s8|dkr$|St|tr8||St|trR|}|fdd}g}|rt|dksj||rt|||rt|jr|D]}||jdddd|dq|s|r|} | j r| j | } | j | ddD]} || jd|dd|dq|sqq| j } q|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||Sr)r8)node node_classrrr conditionsz Node.traverse..conditionF) include_selfdescendsiblingsascendrA) r>r8typer;r9lenr0r:traverser index) rrArBrCrDrEr@rr&r?rJZsiblingrrrrIsF%            z Node.traversecCs:|j|||||d}z |dWStk r4YdSXdS)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. )rArBrCrDrErN)rI IndexError)rrArBrCrDrEiterablerrr next_nodes  zNode.next_node)N)rr)NTTFF)NFTFF)r+ __module__ __qualname____doc__r r!r"r$rsys version_infor rrrrrr'r1r6r;r>rIrNrrrrr$s4    .+  Krrc@seZdZdZddZdS) reprunicodezU A unicode sub-class that removes the initial u from unicode's repr. cCst|ddSNrF)r __repr__rrrrrV5szreprunicode.__repr__N)r+rOrPrQrVrrrrrT0srTcCs$tjdkr t|tr |ddS|S)z4 Failsave conversion of `unicode` to `str`. rasciibackslashreplace)rRrSr8r r )srrr ensure_str;s rZFcCs2|r|ddSdD]}d||}q|SdS)zw Return a string with nulls removed or restored to backslashes. Backslash-escaped spaces are also removed. \)z z r[N)replacejoinsplit)textZrestore_backslashesZrespect_whitespaceseprrrunescapeDs  rcc@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#textrrNcCst|trtdt||S)7Prevent the rawsource argument from propagating to str.zexpecting str data, not bytes)r8bytes TypeErrorrT__new__r<data rawsourcerrrrh`s z Text.__new__cCs t||S)re)rTrhrirrrrhfsr]cCs ||_dSrrk)rrjrkrrr__init__jsz Text.__init__cCs6|}t||kr$|d|dd}d|jt|fS)N ...z<%s: %r>)rHtagnamerT)rmaxlenrjrrr shortreprns zText.shortreprcCs |jddS)ND)rr)rsrrrrrVtsz Text.__repr__cCs|t|Sr)ZcreateTextNoder )rrrrrrwszText._dom_nodecCs tt|Sr)rTrcrrrrrzsz Text.astextcCs|jt||jdS)Nrl)r*rTrkrrrrrsz Text.copycCs|Sr)rrrrrrsz Text.deepcopyrrcs8|fdd|D}|s*dSd|dS)Ncsg|] }|qSrr.0r$rrr sz Text.pformat..r] )r splitlinesr_)rrrlinesrrwrrs z Text.pformatcCs|t|||jSr)r*rTrstriprkrcharsrrrr|sz Text.rstripcCs|t|||jSr)r*rTlstriprkr}rrrrsz Text.lstrip)N)N)r])rn)rr)N)N)r+rOrPrQrqr0rRrSrhrmrsrVrrrrrr|rrrrrrdRs        rdc@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)r"rkNz r]cOs||_g|_||i|_|jD]}g|j|<q"t|D]8\}}|}||jkrl|dd|j|<q>||j|<q>|jdkr|j j |_dSr) rkr0r: attributeslist_attributeslistitemslowerrqr*r+)rrkr0rattvaluerrrrms      zElement.__init__cCsl||j}|D]6\}}t|tr:ddd|D}||d|q|jD]}|| |qR|S)N cSsg|]}td|fqS%s serial_escapervvrrrrxsz%Element._dom_node..r) createElementrqattlistr8rr_Z setAttributer0 appendChildr)rrelement attributerr&rrrrs   zElement._dom_nodecCs~d}|jD]0}||7}t|dkr |ddd}q; cSsg|] }t|qSrrZrvnrrrrx sz$Element.__repr__..z<%s: %s>)r0rsrHr*r+r_)rrjcrrrrVs   zElement.__repr__cCs:|dr,d|jjddd|dDfSd|jSdS)Nrz <%s "%s"...>rcSsg|] }t|qSrrrrrrrxsz%Element.shortrepr..z<%s...>)r*r+r_rqrrrrrss zElement.shortreprcCs:|jr.d|ddd|jD|fS|SdS)Nz%s%s%sr]cSsg|] }t|qSr)r )rvrrrrrxsz'Element.__unicode__..)r0starttagr_endtagemptytagrrrr __unicode__s zElement.__unicode__rcCs|dkr t}|jg}|D]f\}}|dkr<|d|qt|tr`dd|D}d|}nt|}||}|d||fqdd|S)Nz %s="True"cSsg|]}td|fqSrrrrrrrx-sz$Element.starttag..rz%s=%sz<%s>)pseudo_quoteattrrqrr9r8rr_r )r quoteattrpartsnamervaluesrrrr#s  zElement.starttagcCs d|jS)Nz)rqrrrrr5szElement.endtagcCs$dd|jgdd|DS)Nz<%s/>rcSsg|]\}}d||fqS)z%s="%s"r)rvrrrrrrx:sz$Element.emptytag..)r_rqrrrrrr8s  zElement.emptytagcCs t|jSr)rHr0rrrr__len__=szElement.__len__cCst|tr||jkS||jkSr)r8r rr0rkeyrrr __contains__@s  zElement.__contains__cCsbt|tr|j|St|tr(|j|St|trV|jdksDtd|j|j|j St ddSNrUcannot handle slice with stridezFelement index must be an integer, a slice, or an attribute name string r8r rintr0slicestepAssertionErrorstartr5rgrrrr __getitem__Gs     zElement.__getitem__cCst|tr||jt|<nlt|tr:||||j|<nLt|tr~|jdksVtd|D]}||qZ||j|j |j <nt ddSr) r8r rrr'r0rrrrr5rg)rritemr?rrr __setitem__Ss      zElement.__setitem__cCsbt|tr|j|=nJt|tr(|j|=n6t|trV|jdksDtd|j|j|j =nt ddS)NrUrzMelement index must be an integer, a simple slice, or an attribute name stringrrrrr __delitem__bs     zElement.__delitem__cCs |j|Srr0rotherrrr__add__nszElement.__add__cCs ||jSrrrrrr__radd__qszElement.__radd__cCs,t|tr||n|dk r(|||S)z4Append a node or a list of nodes to `self.children`.N)r8rr9r:rrrr__iadd__ts    zElement.__iadd__cCs|jdd|jDS)NcSsg|] }|qSr)rrvr&rrrrx~sz"Element.astext..)child_text_separatorr_r0rrrrr|szElement.astextcCs2i}t|jD]\}}||r|||<q|Sr)rrris_not_default)rZattsrrrrrnon_default_attributess   zElement.non_default_attributescCst|}||Sr)rrrsort)rrrrrrszElement.attlistcCs|j||Sr)rgetrrfailobjrrrrsz Element.getcCs ||jkSrrrattrrrrhasattrszElement.hasattrcCs||jkr|j|=dSrrrrrrdelattrs zElement.delattrcCs|j||Sr)r setdefaultrrrrrszElement.setdefaultcCsX|dgD]}|dr |ddSq z|j|WStk rR|YSXdS)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`. rz language- N)r startswithr Z get_languageAttributeError)rfallbackr<rrrget_language_codes zElement.get_language_codecCs|||j|dSr)r'r0r9rrrrrr9s zElement.appendcCs|D]}||qdSrr9)rrr?rrrr:szElement.extendcCs<t|tr$|||j||n|dk r8||||<dSr)r8rr'r0insert)rrJrrrrrs   zElement.insertcCs |j|Sr)r0pop)rirrrrsz Element.popcCs|j|dSr)r0removerrrrrszElement.removecCs |j|Sr)r0rJrrrrrJsz Element.indexcCs"||gkr||jkrdSdSdS)NrrFrrrrrrszElement.is_not_defaultcCs4t|tr|j}|jD]}||||gqdS)z Update basic attributes ('ids', 'names', 'classes', 'dupnames', but not 'source') from node or dictionary `dict_`. N)r8rrbasic_attributesappend_attr_listr)rdict_rrrrupdate_basic_attss  zElement.update_basic_attscCs(|D]}|||kr|||qdS)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. Nr)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)r8rrr)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. Nr)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)rrrrrr^rrrcopy_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)rr8rrrrrrrcopy_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)rr8rrrrrrrcopy_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)rrrrrrcopy_attr_consistent$szElement.copy_attr_consistentFcCsRt|tr|j}|r|j}n|j}||t||D]}||||||q6dS)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)r8rris_not_list_attributeis_not_known_attributerfilter)rrZ update_funr^ and_sourceZ filter_funrrrrupdate_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)rrrrrr^rrrrupdate_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)rrrrrrrupdate_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)rrrrrrrupdate_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)rrr)rrrrrrupdate_all_atts_converts zElement.update_all_atts_convertcCs g|_dSrrrrrrclearsz Element.clearcCsD||}t|tr(|||||<n|dk r@||||d<dS)z8Replace one child `Node` with another child or children.NrF)rJr8rr')roldnewrJrrrr^s     zElement.replacecCs|}t|ts4z |d}Wntk r2d}YnXt|trJ||n(|jD] }||rPtd|||fqP|j||dS)zc Replace `self` node with `new`, where `new` is a node or a list of nodes. rNzLosing "%s" attribute: %s) r8rrLrrrrr r^)rrupdaterrrr replace_selfs       zElement.replace_selfrcCsRt|ts|f}t|tt||D](}|D]}t|||r,|Sq,q$dS)aM Return the index of the first child whose class exactly matches. Parameters: - `childclass`: A `Node` subclass to search for, or a tuple of `Node` classes. If a tuple, any of the classes may match. - `start`: Initial index to check. - `end`: Initial index to *not* check. N)r8tuplerangeminrHrZ childclassrendrJrrrrfirst_child_matching_classs z"Element.first_child_matching_classcCsTt|ts|f}t|tt||D]*}|D]}t|j||r,q$q,|Sq$dS)aI Return the index of the first child whose class does *not* match. Parameters: - `childclass`: A `Node` subclass to skip, or a tuple of `Node` classes. If a tuple, none of the classes may match. - `start`: Initial index to check. - `end`: Initial index to *not* check. N)r8rrrrHr0rrrrfirst_child_not_matching_classs  z&Element.first_child_not_matching_classrcs2dd|fgfdd|jDS)Nr]z%s%s csg|]}|dqS)rF)rrrrrrrxsz#Element.pformat..)r_rr0rrrrrs  zElement.pformatcCs4|jfd|ji|j}|j|_|j|_|j|_|S)Nrk)r*rkrr!r"r$robjrrrrs z Element.copycCs"|}|dd|jD|S)NcSsg|] }|qSr)rrrrrrxsz$Element.deepcopy..)rr:r0)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) stacklevelrrN)warningswarnDeprecationWarningrr9rrrrrr 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`.rFZexpect_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. rr<rrrrr"szElement.is_not_list_attributecCs ||jkS)zj Returns True if and only if the given attribute is NOT recognized by this class. )known_attributesr rrrr*szElement.is_not_known_attribute)r])N)N)N)r])r)T)T)TF)TF)TF)F)rr)NN)Hr+rOrPrQrZlocal_attributesrr rqrrmrrVrsrrRrSr rrrrrrrrrrrrrrrrrrZhas_keyrr9r:rrrrJrrrrrrrrrrrrrrrr^rmaxsizerrrrrrr  classmethodrrrrrrrs#               &         rc@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. r]cOs@|dkr(t|}tj|||f||ntj||f||dS)Nr])rdrrm)rrkrar0rZtextnoderrrrmEs zTextElement.__init__N)r]r])r+rOrPrQrrmrrrrr3s rc@seZdZdZdddZdS)FixedTextElementz5An element which directly contains preformatted text.r]cOs$tj|||f||d|jd<dS)Npreservez xml:space)rrmr)rrkrar0rrrrrmRszFixedTextElement.__init__N)r]r])r+rOrPrQrmrrrrrNsrc@seZdZdZdS) ResolvablerN)r+rOrPZresolvedrrrrr[src@seZdZddZdS) BackLinkablecCs|d|dS)Nrr)rrefidrrr add_backrefbszBackLinkable.add_backrefN)r+rOrPrrrrrr`src@s eZdZdS)RootNr+rOrPrrrrrjsrc@s eZdZdS)TitularNrrrrrrlsrc@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)Dr!z 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)NrFr)!rrmr#r%settingsr(indirect_targetssubstitution_defssubstitution_namesrefnamesrefidsnameids nametypesr footnote_refs citation_refs autofootnotesautofootnote_refssymbol_footnotessymbol_footnote_refs footnotes citationsZautofootnote_startZsymbol_footnote_startid_startparse_messagestransform_messagesZdocutils.transformsZ transformsZ Transformer transformer decorationr!)rr)r(argskwargsZdocutilsrrrrms<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 rrrrrrrrrr s zdocument.asdomcCs|dD]<}||jkr|j||k r|jd|}|dkr||7}q|ds|dD]&}|jjt|}|rV||jkrVqqVd}|r||jkr|jj|jjt|j}|jd7_q|d |||j|<|S)NrzDuplicate ID: "%s".rr]rF) rr(Zseverer)Z id_prefixmake_idZauto_id_prefixr r9r9)rr?msgnoder msgrrrrset_ids*    zdocument.set_idcCsD|dD]6}||jkr*||||||q||j|<||j|<qdS)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. rN)r/set_duplicate_name_idr0)rr?r rDexplicitrrrrset_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)NrrefurirrFz%Duplicate explicit target name: "%s".)r base_nodez%Duplicate implicit target name: "%s".)r/r0rdupnamer(system_messageinfo) rr?r rrDrHZold_idZ old_explicitrZold_noderJrErrrrGMsZ               zdocument.set_duplicate_name_idcCs ||jkSr)r/rrrrhas_namewszdocument.has_namecCs"|||}|j|||dddS)NrHrFrIrtargetrDr rrrnote_implicit_target{s zdocument.note_implicit_targetcCs"|||}|j|||dddS)NTrPrQrRrrrnote_explicit_targets zdocument.note_explicit_targetcCs|j|dg|dSNrefname)r-rr9rr?rrr note_refnameszdocument.note_refnamecCs|j|dg|dS)Nr)r.rr9rXrrr note_refidszdocument.note_refidcCs"|j||dr||dS)Nr)r*r9rYrrSrrrnote_indirect_targets zdocument.note_indirect_targetcCs||dSr)rFr[rrrnote_anonymous_targetszdocument.note_anonymous_targetcCs|||j|dSr)rFr3r9rfootnoterrrnote_autofootnotes zdocument.note_autofootnotecCs|||j|dSr)rFr4r9rrefrrrnote_autofootnote_refs zdocument.note_autofootnote_refcCs|||j|dSr)rFr5r9r^rrrnote_symbol_footnotes zdocument.note_symbol_footnotecCs|||j|dSr)rFr6r9rarrrnote_symbol_footnote_refs z!document.note_symbol_footnote_refcCs|||j|dSr)rFr7r9r^rrr note_footnotes zdocument.note_footnotecCs0|||j|dg|||dSrV)rFr1rr9rYrarrrnote_footnote_refs zdocument.note_footnote_refcCs|j|dSr)r8r9)rcitationrrr note_citationszdocument.note_citationcCs0|||j|dg|||dSrV)rFr2rr9rYrarrrnote_citation_refs zdocument.note_citation_refcCsft|}||jkrJ|jjd||d}|dkr6||7}|j|}t||||j|<||jt|<dS)Nz-Duplicate substitution definition name: "%s".)rK)whitespace_normalize_namer+r(errorrLr,fully_normalize_name)rZsubdefZdef_namerDrrEZoldnoderrrnote_substitution_defs    zdocument.note_substitution_defcCst||d<dSrV)rk)rZsubrefrWrrrnote_substitution_refszdocument.note_substitution_refcCs|j||dSr)r<Z add_pending)rpendingpriorityrrr note_pendingszdocument.note_pendingcCs|j|dSr)r:r9rmessagerrrnote_parse_messageszdocument.note_parse_messagecCs|j|dSr)r;r9rsrrrnote_transform_messageszdocument.note_transform_messagecCs$||_|dkr||_n |d|_dSrU)r#r%)rr"offsetrrr note_sourceszdocument.note_sourcecCs*|j|j|jf|j}|j|_|j|_|Sr)r*r)r(rr"r$rrrrrs z document.copycCsB|js + internal attributes Use `document.note_pending()` so that the `docutils.transforms.Transformer` stage of processing can run all pending transforms. Nr]cOs(tj||f||||_|p i|_dSr)rrm transformdetails)rrrrkr0rrrrrms zpending.__init__rrcs dd|jj|jjfdg}t|j}||D]\}}t|trv| dd|f| dd| Dq4|rt|trt|dtr| dd|f|D] }| d d| Dqq4| d d||fq4t |dfd d|DS) Nz.. internal attributes:z .transform: %s.%sz .details:z%7s%s:r]cSsg|]}dd|fqSz%9s%sr]rrurrrrxsz#pending.pformat..rcSsg|]}dd|fqSrrrurrrrxsz %7s%s: %rcsg|]}d|fqS)z %s%s rrurrrrxs)rrOr+rrrrr8rr9r:rrzrr_)rrrZ internalsrrrrrrrrs8        zpending.pformatcCs6|j|j|j|jf|j}|j|_|j|_|j|_|Sr)r*rrrkrr!r"r$rrrrrsz pending.copy)Nr])rr)r+rOrPrQrmrrrrrrrps  rpc@seZdZdZdS)rawz@ Raw data that is to be passed untouched to the Writer. Nrrrrrrsrc@s eZdZdS)emphasisNrrrrrrsrc@s eZdZdS)strongNrrrrrrsrc@s eZdZdS)literalNrrrrrrsrc@s eZdZdS) referenceNrrrrrr src@s eZdZdS)footnote_referenceNrrrrrr src@s eZdZdS)citation_referenceNrrrrrr src@s eZdZdS)substitution_referenceNrrrrrr src@s eZdZdS)title_referenceNrrrrrr src@s eZdZdS) abbreviationNrrrrrrsrc@s eZdZdS)acronymNrrrrrrsrc@s eZdZdS) superscriptNrrrrrrsrc@s eZdZdS) subscriptNrrrrrrsrc@s eZdZdS)mathNrrrrrrsrc@seZdZddZdS)imagecCs |ddS)NZaltr]rrrrrrsz image.astextNrrrrrrsrc@s eZdZdS)inlineNrrrrrrsrc@s eZdZdS) problematicNrrrrrrsrc@s eZdZdS) generatedNrrrrrrsra< 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 ||_dSr)r!rr!rrrrmjszNodeVisitor.__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_visitr!r(r)rr?Z node_namemethodrrrr,mszNodeVisitor.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_departurer!r(r)rrrrr7zszNodeVisitor.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: %sNr!r)Zstrict_visitorr*r+optionalrrXrrrrs   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: %sNrrXrrrrs   zNodeVisitor.unknown_departureN) r+rOrPrQrrmr,r7rrrrrrrCs    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. Nrrrrrrsrc@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. cCstdSz)Override for generic, uniform traversals.NrrXrrr default_visitsz GenericNodeVisitor.default_visitcCstdSrrrXrrrdefault_departuresz$GenericNodeVisitor.default_departureN)r+rOrPrQrrrrrrrsrcCs||dSr)rrXrrr_call_default_visitsrcCs||dSr)rrXrrr_call_default_departuresrcCsdSrrrXrrr_nopsrcCsN|D]D}ttd|tttd|tttd|tttd|tqdS)z%Save typing with dynamic assignments:rrN)setattrrrrrr)r_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|_dSr)rrm parent_stackr rrrrrms zTreeCopyVisitor.__init__cCs |jdSr)r rrrr get_tree_copyszTreeCopyVisitor.get_tree_copycCs,|}|j||j|j||_dS)z9Copy the current node, and make it the new acting parent.N)rr r9r)rr?Znewnoderrrrs zTreeCopyVisitor.default_visitcCs|j|_dS)z#Restore the previous acting parent.N)rrr rXrrrrsz!TreeCopyVisitor.default_departureN)r+rOrPrQrmrrrrrrrrs 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. Nrrrrrrsrc@seZdZdZdS)r-z Do not visit any children of the current node. The current node's siblings and ``depart_...`` method are not affected. Nrrrrrr-sr-c@seZdZdZdS)r2z 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. Nrrrrrr2 sr2c@seZdZdZdS)r.zq Do not visit the current node's children, and do not call the current node's ``depart_...`` method. Nrrrrrr.sr.c@seZdZdZdS)r/z Do not call the current node's ``depart_...`` method. The current node's children and siblings are not affected. Nrrrrrr/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. Nrrrrrr'src@seZdZdZdS)r3a= 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. Nrrrrrr32sr3cCsr|}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 ZNFKDrWignore-rr])rr8r decode translate_non_id_translate_digraphs_non_id_translate unicodedata normalizer _non_id_charssubr_r`_non_id_at_ends)stringr rrrrC?s#     rCz [^a-z0-9]+z ^[-0-9]+|-+$odhrltbrfkrryzgjrYeqrK)!ii'i1iBigiiiiiiiiiiiiiii%i4i5i6i7i<i?i@iGiIiKiMiOszZaeZoedbZqp)iSi8i9cCs&|d||d|d|_dS)NrrrF)r9rr)r?rrrrrLsrLcCsd|S)z.Return a case- and whitespace-normalized name.r)r_rr`rrrrrmsrmcCsd|S)z$Return a whitespace-normalized name.r)r_r`rrrrrksrkcCs|ddddS)zDEscape string values that are elements of a list, for serialization.r\z\\rz\ )r^rrrrrsrcCsd|S)zQuote attributes for pseudo-xmlz"%s"rrrrrrsr)FF)rQZ __docformat__rRosrertypesrobjectrrSr rTrZrcrdrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r!rzr{r|r}r~rrrrrrrrrr=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr$rrrrrrlrrrrrrrrrSr_rhrrrrrrrrrrrrMrprrrrrrrrrrrrrrrrrrr`Znode_class_namesrrrrrrrr Exceptionrr-r2r.r/rr3rCcompilerrrrrLrmrkrrrrrrs  K   N I ]            1  $