B dY="@sh dZddlmZddlmZdZddlZddlZddlZddl Z ddl Z ej dkrZe Z e ZGdddeZGd d d eZej dkrGd d d e Zne Zd dZdJddZGdddeeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGd d!d!eZGd"d#d#eZGd$d%d%eZGd&d'd'eZ Gd(d)d)eZ!Gd*d+d+eZ"Gd,d-d-e"Z#Gd.d/d/e"Z$Gd0d1d1e"Z%Gd2d3d3e"Z&Gd4d5d5eZ'Gd6d7d7eZ(Gd8d9d9eZ)Gd:d;d;eZ*Gdd?d?eZ,Gd@dAdAee!eZ-GdBdCdCeeeZ.GdDdEdEeeeZ/GdFdGdGeeZ0GdHdIdIeeZ1GdJdKdKeeZ2GdLdMdMeeZ3GdNdOdOeeZ4GdPdQdQeeZ5GdRdSdSeeZ6GdTdUdUeeZ7GdVdWdWeeZ8GdXdYdYeeZ9GdZd[d[eeZ:Gd\d]d]eeZ;Gd^d_d_e eZGdddedee!eZ?Gdfdgdge!eZ@Gdhdidie!eZAGdjdkdke!eZBGdldmdme#eZCGdndodoe#eZDGdpdqdqe#eZEGdrdsdse$eZFGdtdudue$eZGGdvdwdwe(eZHGdxdydye$eZIGdzd{d{e(eZJGd|d}d}e(eZKGd~dde(eZLGddde(eZMGddde$eZNGddde(eZOGddde(eZPGddde(eZQGddde(eZRGddde(eZSGddde(eZTGddde$eZUGddde(eZVGddde(eZWGddde(eZXGddde#eZYGddde#eZZGddde#eZ[Gddde#eZ\Gddde(eZ]Gddde#eZ^Gddde(eZ_Gddde%eZ`Gddde%eZaGddde%eZbGddde%eZcGddde%eZdGddde%eZeGddde%eZfGddde%eZgGddde%eZhGddde%eZiGddde&e'eZjGddde&e'eZkGddde&e'e)ee+ZlGddde#eee,e+ZmGddÄde#eee,e+ZnGddńde(eZoGddDŽde#eZpGddɄde(eZqGdd˄de(eZrGdd̈́de#eZsGddτde(eZtGddфde(eZuGddӄde(eZvGddՄde(eZwGddׄde(eZxGddلde(eZyGddۄde&eeeZzGdd݄de&e'eZ{Gdd߄de&e)eeZ|Gddde)eZ}Gddde)eZ~Gddde)eZGddde#e)e*eZGddde)e*eZGddde)e*eZGddde)eZGddde)eZGddde)eZGddde)eZGddde)eZGddde)eZGddde)eZGddde#e)eZGddde)eZGddde)eZGddde)eZdZGdddeZGdddeZGdddeZd d Zd d Zd dZddZeeGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdd d eZd!d"Zed#Zed$Zd%d&d'd(d)d*d+d+d,d&d-d.d)d/d0d*d*d1d2d3d2d)d/d*d4d,d5d2d6d4d7d8d1d9!Zd:d;d<d=d>d?Zd@dAZdBdCZdDdEZdFdGZdHdIZdS(Ka 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 )print_function)CounterreStructuredTextN)rc@seZdZdZddZeejZeejZeejZeej Z eej Z eej Z eej Z eej Z eejZeejZeejZeejZdS)_traversal_listFcsdfdd}|S)Nzm The iterable returned by Node.traverse() will become an iterator instead of a list in Docutils > 0.16.cs,|jstjtddd|_|f||S)N) stacklevelT)donewarningswarn FutureWarning)selfargskwargs)funmsg5/tmp/pip-target-jj3kjtpb/lib/python/docutils/nodes.pywrapper,sz3_traversal_list._warning_decorator..wrapperr)rrr)rrr_warning_decorator(sz"_traversal_list._warning_decoratorN)__name__ __module__ __qualname__r rlist__add__ __contains__ __getitem__ __reversed__ __setitem__appendcountextendindexinsertpopreverserrrrr%s           rc@seZdZdZdZdZdZdZddZe j dkr2eZ e j dkrDddZ d&dd Z d'd d ZddZddZddZddZddZddZddZddZd(d d!Zd)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. Tr)r rrr__bool__Us z Node.__bool__)rrcCst|dS)NZraw_unicode_escape)unicodeencode)r rrr__str__fsz Node.__str__cCs,|dkrddlmm}|}||S)z6Return a DOM **fragment** representation of this Node.Nr)xml.dom.minidomdomminidomDocument _dom_node)r r,domrootrrrasdomisz Node.asdom rcCstdS)zs Return an indented pseudo-XML representation, for test purposes. Override in subclasses. N)NotImplementedError)r indentlevelrrrpformatpsz Node.pformatcCstdS)zReturn a copy of self.N)r3)r rrrcopyxsz Node.copycCstdS)z3Return a deep copy of self (also copying children).N)r3)r rrrdeepcopy|sz Node.deepcopycCstdS)z,Return a string representation of this Node.N)r3)r rrrastextsz Node.astextcCs@||_|jr<|j|_|jdkr(|jj|_|jdkr<|jj|_dS)N)parentdocumentsourcecurrent_sourceline current_line)r childrrr setup_childs   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) r;reporterdebug __class__rdispatch_visit SkipChildrenSkipNode SkipDeparturechildrenwalk SkipSiblings StopTraversal)r visitorstoprIr@rrrrJs,     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)r;rBrCrDrrErGrHrI walkaboutrKrFrLdispatch_departure)r rMZ call_departrNrIr@rrrrOs<         zNode.walkaboutccs>t||r|Vx(|jD]}x||D] }|Vq(WqWdS)z3Return iterator that only supports instance checks.N) isinstancerI_fast_traverse)r clsr@subnoderrrrRs   zNode._fast_traverseccs2|Vx&|jD]}x|D] }|VqWqWdS)z3Return iterator that doesn't check for a condition.N)rI _all_traverse)r r@rTrrrrUs zNode._all_traverseTFcCst||||||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>] )r _traverse)r condition include_selfdescendsiblingsascendrrrtraverses) z Node.traversec csT|rd}|r`|r`|s`|dkr8x|D] }|Vq&WdSt|tr`x||D] }|VqNWdSt|trz|}|fdd}|r|dks||r|V|rt|jrx0|D](}x"|j|dddddD] }|VqWqW|s|rP|} xl| jrN| j| } xB| j| ddD],} x$| j|d|dddD] }|Vq&Wq W|sFPq| j} qWdS)z>Return iterator over nodes following `self`. See `traverse()`.TNcSs t||S)N)rQ)node node_classrrrrW5sz!Node._traverse..conditionF)rWrXrYrZr[) rUrQtyperRlenrIrVr:r") r rWrXrYrZr[rTr^r@r]r"ZsiblingrrrrV!sD          zNode._traversecCs4||||||}yt|Stk r.dSXdS)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 False, though. N)rVnext StopIteration)r rWrXrYrZr[Z node_iteratorrrr next_nodeOs  zNode.next_node)N)r2r)NTTFF)NTTFF)NFTFF)rrr__doc__r:r;r<r>r'sys version_info __nonzero__r*r1r6r7r8r9rArJrOrRrUr\rVrdrrrrr&Es4     .+ + -r&c@seZdZdZddZdS) reprunicodezU A unicode sub-class that removes the initial u from unicode's repr. cCst|ddS)Nr_)r(__repr__)r rrrrjeszreprunicode.__repr__N)rrrrerjrrrrri`sricCs$tjdkr t|tr |ddS|S)z4 Failsave conversion of `unicode` to `str`. )rrasciibackslashreplace)rfrgrQr(r))srrr ensure_strks rnFcCs6|r|ddSxdD]}d||}qW|SdS)zw Return a string with nulls removed or restored to backslashes. Backslash-escaped spaces are also removed. \)z z roN)replacejoinsplit)textZrestore_backslashesZrespect_whitespaceseprrrunescapets   rwc@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)rrNcCst|trtdt||S)z7Prevent the rawsource argument from propagating to str.zexpecting str data, not bytes)rQbytes TypeErrorri__new__)rSdata rawsourcerrrr{s z Text.__new__cCs t||S)z7Prevent the rawsource argument from propagating to str.)rir{)rSr|r}rrrr{srqcCs ||_dS)N)r})r r|r}rrr__init__sz Text.__init__cCs6|}t||kr$|d|dd}d|jt|fS)Nz ...z<%s: %r>)ratagnameri)r maxlenr|rrr shortreprs zText.shortreprcCs |jddS)ND)r)r)r rrrrjsz Text.__repr__cCs|t|S)N)ZcreateTextNoder()r r0rrrr/szText._dom_nodecCs tt|S)N)rirw)r rrrr9sz Text.astextcCs|jt||jdS)N)r})rDrir})r rrrr7sz Text.copycCs|S)N)r7)r rrrr8sz Text.deepcopy rcs8|fdd|D}|s*dSd|dS)Ncsg|] }|qSrr).0r>)r4rr sz Text.pformat..rq )r9 splitlinesrs)r r4r5linesr)r4rr6s z Text.pformatcCs|t|||jS)N)rDrirstripr})r charsrrrrsz Text.rstripcCs|t|||jS)N)rDrilstripr})r rrrrrsz Text.lstrip)N)N)rq)r)rr)N)N)rrrrerrIrfrgr{r~rrjr/r9r7r8r6rrrrrrrxs        rxc@s>eZdZdZdZdZeeZedZdZdZ d~dd Z d d Z d d Z ddZ ddZejdkrdeZdddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zdd-d.Zd/d0Z d1d2Z!dd3d4Z"e Z#d5d6Z$dd7d8Z%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<r}Nz rqcOs||_g|_||i|_x|jD]}g|j|<q$WxD|D]8\}}|}||jkrn|dd|j|<q@||j|<q@W|jdkr|jj |_dS)N) r}rIr! attributeslist_attributesitemslowerrrDr)r r}rIrattvaluerrrr~ s    zElement.__init__cCst||j}xB|D]6\}}t|tr.z%s) createElementrattlistrQrrsZ setAttributerI appendChildr/)r r0element attributerr@rrrr/)s   zElement._dom_nodecCsd}x8|jD].}||7}t|dkr |ddd}Pq W|drld|jjddd |dD|fSd |jj|fSdS) Nrq<8z ...rz <%s "%s": %s>z; cSsg|] }t|qSr)rn)rnrrrr<sz$Element.__repr__..z<%s: %s>)rIrrarDrrs)r r|crrrrj3s   zElement.__repr__cCs:|dr,d|jjddd|dDfSd|jSdS)Nrz <%s "%s"...>z; cSsg|] }t|qSr)rn)rrrrrrCsz%Element.shortrepr..z<%s...>)rDrrsr)r rrrr@szElement.shortreprcCs:|jr.d|ddd|jD|fS|SdS)Nz%s%s%srqcSsg|] }t|qSr)r()rrrrrrJsz'Element.__unicode__..)rIstarttagrsendtagemptytag)r rrr __unicode__Gs  zElement.__unicode__)rrcCs|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)rrrrrr\sz$Element.starttag..rz%s=%sz<%s>)pseudo_quoteattrrrrrQrrsr()r quoteattrpartsnamervaluesrrrrRs  zElement.starttagcCs d|jS)Nz)r)r rrrrdszElement.endtagcCs$dd|jgdd|DS)Nz<%s/>rcSsg|]\}}d||fqS)z%s="%s"r)rrrrrrrisz$Element.emptytag..)rsrr)r rrrrgs zElement.emptytagcCs t|jS)N)rarI)r rrr__len__lszElement.__len__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) rQ basestringrintrIslicestepAssertionErrorstartrNrz)r keyrrrros     zElement.__getitem__cCst|tr||jt|<npt|tr:||||j|<nPt|tr|jdksVt dx|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) rQrrstrrrArIrrrrrNrz)r ritemr]rrrr{s      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) rQrrrrIrrrrrNrz)r rrrr __delitem__s     zElement.__delitem__cCs |j|S)N)rI)r otherrrrrszElement.__add__cCs ||jS)N)rI)r rrrr__radd__szElement.__radd__cCs,t|tr||n|dk r(|||S)z4Append a node or a list of nodes to `self.children`.N)rQr&rr!)r rrrr__iadd__s    zElement.__iadd__cCs|jdd|jDS)NcSsg|] }|qSr)r9)rr@rrrrsz"Element.astext..)child_text_separatorrsrI)r rrrr9szElement.astextcCs2i}x(|jD]\}}||r|||<qW|S)N)rris_not_default)r Zattsrrrrrnon_default_attributess   zElement.non_default_attributescCst|}|S)N)sortedrr)r rrrrrszElement.attlistcCs|j||S)N)rget)r rfailobjrrrrsz Element.getcCs ||jkS)N)r)r attrrrrhasattrszElement.hasattrcCs||jkr|j|=dS)N)r)r rrrrdelattrs zElement.delattrcCs|j||S)N)r setdefault)r rrrrrrszElement.setdefaultcCst|tr||jkS||jkS)N)rQrrrI)r rrrrrs  zElement.__contains__cCsRx*|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`. rz language- N)r startswithr:Z get_languageAttributeError)r fallbackrSrrrget_language_codes  zElement.get_language_codecCs|||j|dS)N)rArIr)r rrrrrs zElement.appendcCsx|D]}||qWdS)N)r)r rr]rrrr!s zElement.extendcCs<t|tr$|||j||n|dk r8||||<dS)N)rQr&rArIr#)r r"rrrrr#s   zElement.insertcCs |j|S)N)rIr$)r irrrr$sz Element.popcCs|j|dS)N)rIremove)r rrrrrszElement.removecCs |j|S)N)rIr")r rrrrr"sz Element.indexcCs"||gkr||jkrdSdSdS)Nrr_)r)r rrrrrszElement.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)rQr&rbasic_attributesappend_attr_listr)r dict_rrrrupdate_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)r)r rrrrrrrs  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)rQrrr)r rrrrrcoerce_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)r rrforcerrr 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)r rrrrrrrcopy_attr_convert&szElement.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)rrQrrr)r rrrrrrrcopy_attr_coerce1s  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)rrQrrr)r rrrrrrrcopy_attr_concatenateAs  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)r rrrrrrrcopy_attr_consistentPszElement.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)rQr&ris_not_list_attributeis_not_known_attributerfilter)r rZ update_funrr and_sourceZ filter_funrrrrupdate_all_attsXs  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)rrr)r 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)rrr)r rrrrrrrupdate_all_atts_concatenatings 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)rrr)r 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)r rrrrrupdate_all_atts_converts zElement.update_all_atts_convertcCs g|_dS)N)rI)r rrrclearsz Element.clearcCsD||}t|tr(|||||<n|dk r@||||d<dS)z8Replace one child `Node` with another child or children.Nr_)r"rQr&rA)r oldnewr"rrrrrs     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) rQr& IndexErrorrrrrr:rr)r rupdaterrrr replace_selfs       zElement.replace_selfrcCsRt|ts|f}x.)rsrrI)r r4r5r)r4r5rr6$s zElement.pformatcCs4|jfd|ji|j}|j|_|j|_|j|_|S)Nr})rDr}rr;r<r>)r objrrrr7)s z Element.copycCs"|}|dd|jD|S)NcSsg|] }|qSr)r8)rr@rrrr2sz$Element.deepcopy..)r7r!rI)r r7rrrr80szElement.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 directlyr)rrrN)r r DeprecationWarningrrr)r rrrr set_class5s  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)r ridZby_nameZby_idrrrnote_referenced_by=s  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. )r)rSrrrrrNszElement.is_not_list_attributecCs ||jkS)zj Returns True if and only if the given attribute is NOT recognized by this class. )known_attributes)rSrrrrrVszElement.is_not_known_attribute)rq)N)N)N)rq)r)T)T)TF)TF)TF)F)rr)NN)HrrrrerZlocal_attributesrrrrr~r/rjrrrfrgr*rrrrrrrrrrr9rrrrrrZhas_keyrrrr!r#r$rr"rrrrrrrrrrrrrrrrrrmaxsizerrr6r7r8rr 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. rqcOs@|dkr(t|}tj|||f||ntj||f||dS)Nrq)rxrr~)r r}rurIrZtextnoderrrr~qs zTextElement.__init__N)rqrq)rrrrerr~rrrrr_s rc@seZdZdZdddZdS)FixedTextElementz5An element which directly contains preformatted text.rqcOs$tj|||f||d|jd<dS)NZpreservez xml:space)rr~r)r r}rurIrrrrr~~szFixedTextElement.__init__N)rqrq)rrrrer~rrrrrzsrc@seZdZdZdS) ResolvablerN)rrrresolvedrrrrrsrc@seZdZddZdS) BackLinkablecCs|d|dS)Nr)r)r refidrrr add_backrefszBackLinkable.add_backrefN)rrrrrrrrrsrc@s eZdZdS)RootN)rrrrrrrrsrc@s eZdZdS)TitularN)rrrrrrrrsrc@seZdZdZdS)PreBibliographiczddZd?d d Zd@d d ZddZ ddZ dAddZ dBddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-ZdCd.d/Zd0d1ZdDd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zdr1rrrrnote_explicit_targets zdocument.note_explicit_targetcCs|j|dg|dS)Nrefname)rrr)r r]rrr note_refnameszdocument.note_refnamecCs|j|dg|dS)Nr)rrr)r r]rrr note_refidszdocument.note_refidcCs"|j||dr||dS)Nr)rrrB)r r>rrrnote_indirect_targets zdocument.note_indirect_targetcCs||dS)N)r3)r r>rrrnote_anonymous_targetszdocument.note_anonymous_targetcCs|||j|dS)N)r3rr)r footnoterrrnote_autofootnotes zdocument.note_autofootnotecCs|||j|dS)N)r3rr)r refrrrnote_autofootnote_refs zdocument.note_autofootnote_refcCs|||j|dS)N)r3rr)r rFrrrnote_symbol_footnotes zdocument.note_symbol_footnotecCs|||j|dS)N)r3r r)r rHrrrnote_symbol_footnote_refs z!document.note_symbol_footnote_refcCs|||j|dS)N)r3r!r)r rFrrr note_footnotes zdocument.note_footnotecCs0|||j|dg|||dS)NrA)r3rrrrB)r rHrrrnote_footnote_refs zdocument.note_footnote_refcCs|j|dS)N)r"r)r citationrrr note_citationszdocument.note_citationcCs0|||j|dg|||dS)NrA)r3rrrrB)r rHrrrnote_citation_refs zdocument.note_citation_refcCsft|}||jkrJ|jjd||d}|dkr6||7}|j|}t||||j|<||jt|<dS)Nz-Duplicate substitution definition name: "%s".)r8)whitespace_normalize_namerrBerrorr9rfully_normalize_name)r ZsubdefZdef_namer1rrZoldnoderrrnote_substitution_defs    zdocument.note_substitution_defcCst||d<dS)NrA)rQ)r ZsubrefrArrrnote_substitution_refszdocument.note_substitution_refcCs|j||dS)N)r&Z add_pending)r pendingpriorityrrr note_pendingszdocument.note_pendingcCs|j|dS)N)r$r)r messagerrrnote_parse_messageszdocument.note_parse_messagecCs|j|dS)N)r%r)r rYrrrnote_transform_messageszdocument.note_transform_messagecCs$||_|dkr||_n |d|_dS)Nr_)r=r?)r r<offsetrrr note_source!szdocument.note_sourcecCs*|j|j|jf|j}|j|_|j|_|S)N)rDrrBrr<r>)r rrrrr7(s z document.copycCsB|jssr_c@s eZdZdS)subtitleN)rrrrrrrr`?sr`c@s eZdZdS)rubricN)rrrrrrrra@srac@s eZdZdS)docinfoN)rrrrrrrrbGsrbc@s eZdZdS)authorN)rrrrrrrrcHsrcc@s eZdZdS)authorsN)rrrrrrrrdIsrdc@s eZdZdS) organizationN)rrrrrrrreJsrec@s eZdZdS)addressN)rrrrrrrrfKsrfc@s eZdZdS)contactN)rrrrrrrrgLsrgc@s eZdZdS)versionN)rrrrrrrrhMsrhc@s eZdZdS)revisionN)rrrrrrrriNsric@s eZdZdS)statusN)rrrrrrrrjOsrjc@s eZdZdS)dateN)rrrrrrrrkPsrkc@s eZdZdS) copyrightN)rrrrrrrrlQsrlc@seZdZddZddZdS)r'cCs2t|jrt|jdts(|dt|jdS)Nr)rarIrQheaderr#)r rrr get_headerZszdecoration.get_headercCs0t|jrt|jdts&|t|jdS)Nr)rarIrQfooterr)r rrr get_footer_s zdecoration.get_footerN)rrrrnrprrrrr'Xsr'c@s eZdZdS)rmN)rrrrrrrrmesrmc@s eZdZdS)roN)rrrrrrrrofsroc@s eZdZdS)sectionN)rrrrrrrrqmsrqc@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)rrrrerrrrrrps rrc@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)rrrrerrrrrs~srsc@s eZdZdS) transitionN)rrrrrrrrtsrtc@s eZdZdS) paragraphN)rrrrrrrrusruc@s eZdZdS)compoundN)rrrrrrrrvsrvc@s eZdZdS) containerN)rrrrrrrrwsrwc@s eZdZdS) bullet_listN)rrrrrrrrxsrxc@s eZdZdS)enumerated_listN)rrrrrrrrysryc@s eZdZdS) list_itemN)rrrrrrrrzsrzc@s eZdZdS)definition_listN)rrrrrrrr{sr{c@s eZdZdS)definition_list_itemN)rrrrrrrr|sr|c@s eZdZdS)termN)rrrrrrrr}sr}c@s eZdZdS) classifierN)rrrrrrrr~sr~c@s eZdZdS) definitionN)rrrrrrrrsrc@s eZdZdS) field_listN)rrrrrrrrsrc@s eZdZdS)fieldN)rrrrrrrrsrc@s eZdZdS) field_nameN)rrrrrrrrsrc@s eZdZdS) field_bodyN)rrrrrrrrsrc@seZdZdZdS)optionrqN)rrrrrrrrrsrc@seZdZddZdS)option_argumentcCs|ddt|S)N delimiterr)rrr9)r rrrr9szoption_argument.astextN)rrrr9rrrrrsrc@seZdZdZdS) option_groupz, N)rrrrrrrrrsrc@s eZdZdS) option_listN)rrrrrrrrsrc@seZdZdZdS)option_list_itemz N)rrrrrrrrrsrc@s eZdZdS) option_stringN)rrrrrrrrsrc@s eZdZdS) descriptionN)rrrrrrrrsrc@s eZdZdS) literal_blockN)rrrrrrrrsrc@s eZdZdS) doctest_blockN)rrrrrrrrsrc@s eZdZdS) math_blockN)rrrrrrrrsrc@s eZdZdS) line_blockN)rrrrrrrrsrc@seZdZdZdS)r>N)rrrr4rrrrr>sr>c@s eZdZdS) block_quoteN)rrrrrrrrsrc@s eZdZdS) attributionN)rrrrrrrrsrc@s eZdZdS) attentionN)rrrrrrrrsrc@s eZdZdS)cautionN)rrrrrrrrsrc@s eZdZdS)dangerN)rrrrrrrrsrc@s eZdZdS)rRN)rrrrrrrrRsrRc@s eZdZdS) importantN)rrrrrrrrsrc@s eZdZdS)noteN)rrrrrrrrsrc@s eZdZdS)tipN)rrrrrrrrsrc@s eZdZdS)hintN)rrrrrrrrsrc@s eZdZdS)warningN)rrrrrrrrsrc@s eZdZdS) admonitionN)rrrrrrrrsrc@s eZdZdS)commentN)rrrrrrrrsrc@s eZdZdS)substitution_definitionN)rrrrrrrrsrc@s eZdZdS)r>N)rrrrrrrr>sr>c@s eZdZdS)rFN)rrrrrrrrFsrFc@s eZdZdS)rNN)rrrrrrrrNsrNc@s eZdZdS)labelN)rrrrrrrrsrc@s eZdZdS)figureN)rrrrrrrrsrc@s eZdZdS)captionN)rrrrrrrrsrc@s eZdZdS)legendN)rrrrrrrrsrc@s eZdZdS)tableN)rrrrrrrrsrc@s eZdZdS)tgroupN)rrrrrrrrsrc@s eZdZdS)colspecN)rrrrrrrrsrc@s eZdZdS)theadN)rrrrrrrrsrc@s eZdZdS)tbodyN)rrrrrrrrsrc@s eZdZdS)rowN)rrrrrrrrsrc@s eZdZdS)entryN)rrrrrrrrsrc@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)Nr}rqzsystem_message: children=%r)rrurr~print)r rYrIrr}prrrr~s   zsystem_message.__init__cCs0|dd}d|d||d|dt|fS)Nr>rqz%s:%s: (%s/%s) %sr<r`r5)rrr9)r r>rrrr9s zsystem_message.astext)N)rrrrer~r9rrrrr:s r:c@s,eZdZdZd ddZd dd Zd d ZdS)rVaF 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. NrqcOs(tj||f||||_|p i|_dS)N)rr~ transformdetails)r rrr}rIrrrrr~ s zpending.__init__ rcs dd|jj|jjfdg}t|j}x|D]\}}t|trp|dd|f| dd| Dq.|rt|t rt|dtr|dd|fx>|D] }| d d| DqWq.|d d||fq.Wt |dfd d|DS) Nz.. internal attributes:z .transform: %s.%sz .details:z%7s%s:rqcSsg|]}dd|fqS)z%9s%srqr)rr>rrrr5sz#pending.pformat..rcSsg|]}dd|fqS)z%9s%srqr)rr>rrrr;sz %7s%s: %rcsg|]}d|fqS)z %s%s r)rr>)r4r5rrr@s)rrrrrrrQr&rr!r6rrrrs)r r4r5Z internalsrrrrr)r4r5rr6+s(      zpending.pformatcCs6|j|j|j|jf|j}|j|_|j|_|j|_|S)N)rDrrr}rr;r<r>)r rrrrr7Cs z pending.copy)Nrq)rr)rrrrer~r6r7rrrrrVs  rVc@seZdZdZdS)rawz@ Raw data that is to be passed untouched to the Writer. N)rrrrerrrrrLsrc@s eZdZdS)emphasisN)rrrrrrrrYsrc@s eZdZdS)strongN)rrrrrrrrZsrc@s eZdZdS)literalN)rrrrrrrr[src@s eZdZdS) referenceN)rrrrrrrr\src@s eZdZdS)footnote_referenceN)rrrrrrrr]src@s eZdZdS)citation_referenceN)rrrrrrrr^src@s eZdZdS)substitution_referenceN)rrrrrrrr_src@s eZdZdS)title_referenceN)rrrrrrrr`src@s eZdZdS) abbreviationN)rrrrrrrrasrc@s eZdZdS)acronymN)rrrrrrrrbsrc@s eZdZdS) superscriptN)rrrrrrrrcsrc@s eZdZdS) subscriptN)rrrrrrrrdsrc@s eZdZdS)mathN)rrrrrrrresrc@seZdZddZdS)imagecCs |ddS)NZaltrq)r)r rrrr9jsz image.astextN)rrrr9rrrrrhsrc@s eZdZdS)inlineN)rrrrrrrrnsrc@s eZdZdS) problematicN)rrrrrrrrosrc@s eZdZdS) generatedN)rrrrrrrrpsra< 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;)r r;rrrr~szNodeVisitor.__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)rDrr unknown_visitr;rBrC)r r] node_namemethodrrrrEs 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)rDrrunknown_departurer;rBrC)r r]rrrrrrPs 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)r;rstrict_visitorrDroptionalr3)r r]rrrrs  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)r;rrrDrrr3)r r]rrrrs  zNodeVisitor.unknown_departureN) rrrrerr~rErPrrrrrrrs    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)rrrrerrrrrsrc@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)r3)r r]rrr default_visitsz GenericNodeVisitor.default_visitcCstdS)z)Override for generic, uniform traversals.N)r3)r r]rrrdefault_departuresz$GenericNodeVisitor.default_departureN)rrrrerrrrrrrsrcCs||dS)N)r)r r]rrr_call_default_visitsrcCs||dS)N)r)r r]rrr_call_default_departuresrcCsdS)Nr)r r]rrr_nopsrcCsRxL|D]D}ttd|tttd|tttd|tttd|tqWdS)z%Save typing with dynamic assignments:rrN)setattrrrrrr)r_namerrr_add_node_class_names s  rc@s0eZdZdZddZddZddZdd Zd S) TreeCopyVisitorzQ Make a complete copy of a tree or branch, including element attributes. cCst||g|_g|_dS)N)rr~ parent_stackr:)r r;rrrr~1s zTreeCopyVisitor.__init__cCs |jdS)Nr)r:)r rrr get_tree_copy6szTreeCopyVisitor.get_tree_copycCs,|}|j||j|j||_dS)z9Copy the current node, and make it the new acting parent.N)r7r:rr)r r]Znewnoderrrr9s zTreeCopyVisitor.default_visitcCs|j|_dS)z#Restore the previous acting parent.N)rr$r:)r r]rrrr@sz!TreeCopyVisitor.default_departureN)rrrrer~rrrrrrrr+s 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)rrrrerrrrrEsrc@seZdZdZdS)rFz Do not visit any children of the current node. The current node's siblings and ``depart_...`` method are not affected. N)rrrrerrrrrFRsrFc@seZdZdZdS)rKz 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)rrrrerrrrrK\srKc@seZdZdZdS)rGzq Do not visit the current node's children, and do not call the current node's ``depart_...`` method. N)rrrrerrrrrGfsrGc@seZdZdZdS)rHz Do not call the current node's ``depart_...`` method. The current node's children and siblings are not affected. N)rrrrerrrrrHpsrHc@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)rrrrerrrrrzsrc@seZdZdZdS)rLa= 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)rrrrerrrrrLsrLcCsr|}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 ZNFKDrkignorer,rrq)rrQr(decode translate_non_id_translate_digraphs_non_id_translate unicodedata normalizer) _non_id_charssubrsrt_non_id_at_endsr)stringrrrrr/s#     r/z [^a-z0-9]+z ^[-0-9]+|-+$odhrltbrfkrryzgjrmeqr)!ii'i1iBigiiiiiiiiiiiiiii%i4i5i6i7i<i?i@iGiIiKiMiOszZaeZoedbZqp)iSi8i9cCs&|d||d|d|_dS)Nrrr_)rrr)r]rrrrr9sr9cCsd|S)z.Return a case- and whitespace-normalized name.r)rsrrt)rrrrrSsrScCsd|S)z$Return a whitespace-normalized name.r)rsrt)rrrrrQsrQcCs|ddddS)zDEscape string values that are elements of a list, for serialization.rpz\\rz\ )rr)rrrrrsrcCsd|S)zQuote attributes for pseudo-xmlz"%s"r)rrrrr sr)FF)re __future__r collectionsr __docformat__rfosrer rrgrr(rrrobjectr&rirnrwrxrrrrrrrrrrrrr r r r r rrrrrr;r_r`rarbrcrdrerfrgrhrirjrkrlr'rmrorqrrrsrtrurvrwrxryrzr{r|r}r~rrrrrrrrrrrrrrrrr>rrrrrrRrrrrrrrrr>rFrNrrrrrrrrrrrr:rVrrrrrrrrrrrrrrrrrrrtZnode_class_namesrrrrrrrr ExceptionrrFrKrGrHrrLr/compilerrrrr9rSrQrrrrrrs      K   ^ H " ]            1