o $a"J@sUdZddlZddlZddlmZddlmZddlmZddlmZddl m Z m Z m Z m Z mZmZmZmZmZmZmZmZddlZddlmZdd lmZdd lmZmZmZdd lmZm Z m!Z!dd l"m#Z#dd l$m%Z%m&Z&m'Z'ddl(m)Z)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0ddl1m2Z2ddl3m4Z4e25e6Z7e8dZ9e rddl:m;Z;ddlm?Z?e,@ejAjBZCeDZEeeeeFd<ededfddZGdeHdeIfddZJdeHd eeddfd!d"ZKdeHdeIfd#d$ZLdeHd%e4ddfd&d'ZMdeHddfd(d)ZNd*eedeIfd+d,ZOd*eeddfd-d.ZPd*eeddfd/d0ZQededfd1d2ZRed3eeHdedfd4d5ZSedWd3eeHdedfd6d7ZTGd8d9d9eUZVGd:d;d;ZWGdd?d?e)ZYGd@dAdAe)ZZdeIfdBdCZ[edDe%dEe'dedfdFdGZ\GdHdIdIeZ]GdJdKdKeZ^GdLdMdMZ_GdNdOdOe_Z`GdPdQdQejaZbdaceejdeFdR<dWdSeHdTe dejdfdUdVZedS)Xz sphinx.util.docutils ~~~~~~~~~~~~~~~~~~~~ Utility functions for docutils. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N)contextmanager)copy)path) ModuleType) IO TYPE_CHECKINGAnyCallableDict GeneratorListOptionalSetTupleTypecast)nodes) FileOutput)ElementNodesystem_message) Directive directivesroles)Inliner)State StateMachine StringList)Reporterunescape)version) SphinxError)_)logging) RoleFunctionz>^(.+?:(?:\d+)?): \((DEBUG|INFO|WARNING|ERROR|SEVERE)/(\d+)?\) )Builder)Config)BuildEnvironmentadditional_nodesreturn)NNNc cs~z&ttj}ttj}dVW|t_|t_ttD] }t|t|qdS|t_|t_ttD] }t|t|q2w)z"Create namespace for reST parsers.N) rr _directivesr_roleslistr(unregister_nodediscard)r*r+noder06/usr/lib/python3/dist-packages/sphinx/util/docutils.pydocutils_namespace0s"      r2namecC |tjvS)z1Check the *name* directive is already registered.)rr*r3r0r0r1is_directive_registeredA r6 directivecCt||dS)zRegister a directive to docutils. This modifies global state of docutils. So it is better to use this inside ``docutils_namespace()`` to prevent side-effects. N)rregister_directive)r3r8r0r0r1r:Fr:cCr4)z,Check the *name* role is already registered.)rr+r5r0r0r1is_role_registeredOr7r<rolecCr9)zRegister a role to docutils. This modifies global state of docutils. So it is better to use this inside ``docutils_namespace()`` to prevent side-effects. N)rregister_local_role)r3r=r0r0r1 register_roleTr;r?cCstj|ddS)z Unregister a role from docutils.N)rr+popr5r0r0r1unregister_role]rAr/cCsttjd|jS)z'Check the *node* is already registered.visit_)hasattrrGenericNodeVisitor__name__r/r0r0r1is_node_registeredbrBrHcCs2ttjd|jst|jgt|dSdS)zRegister a node to docutils. This modifies global state of some visitors. So it is better to use this inside ``docutils_namespace()`` to prevent side-effects. rCN)rDrrErF_add_node_class_namesr(addrGr0r0r1 register_nodegsrKcCsbttjd|jr/ttjd|jttjd|jttjd|jttjd|jdSdS)zaUnregister a node from docutils. This is inverse of ``nodes._add_nodes_class_names()``. rCdepart_N)rDrrErFdelattrSparseNodeVisitorrGr0r0r1r-rs r-c#sRddlmd dtdtdtffdd }z|tj_dVWtj_dStj_w) zPatch docutils.languages.get_language() temporarily. This ignores the second argument ``reporter`` to suppress warnings. refs: https://github.com/sphinx-doc/sphinx/issues/3788 r get_languageN language_codereporterr)cs|SNr0)rQrRrOr0r1patched_get_languagez2patched_get_language..patched_get_languagerS)docutils.languagesrPstrrrdocutils languages)rTr0rOr1rT~s rTconfdirc csz-tjdd}|rtt|dtjd<dVW|dur(tjdddS|tjd<dS|dur;tjddw|tjd<w)z?Let docutils know the location of ``docutils.conf`` for Sphinx.DOCUTILSCONFIGNz docutils.conf)osenvirongetrjoinabspathr@)rZdocutilsconfigr0r0r1using_user_docutils_confsrbc cslt(t| dVWdn1swYWddSWddS1s/wYdS)zPatch to docutils temporarily.N)rTrb)rZr0r0r1patch_docutilssPrcc@s eZdZdS)ElementLookupErrorN)rF __module__ __qualname__r0r0r0r1rdsrdc @seZdZdZd!ddZd"dd Zd eed ed eddfd dZ d"ddZ d"ddZ de de defddZ de dedejdeeeeeeffddZde dedededeeeeff dd ZdS)#sphinx_domainszcMonkey-patch directive and role dispatch, so that domain-specific markup takes precedence. envr'r)NcCs||_dd|_dd|_dS)NcWdgfSrSr0argsr0r0r1z)sphinx_domains.__init__..cWrirSr0rjr0r0r1rlrm)rhdirective_func roles_func)selfrhr0r0r1__init__s zsphinx_domains.__init__cC |dSrS)enablerpr0r0r1 __enter__ zsphinx_domains.__enter__exc_type exc_value tracebackcCrrrS)disable)rprwrxryr0r0r1__exit__rvzsphinx_domains.__exit__cCs$tj|_tj|_|jt_|jt_dSrS)rr8rnrr= role_funclookup_directive lookup_rolertr0r0r1rss zsphinx_domains.enablecCs|jt_|jt_dSrS)rnrr8r|rr=rtr0r0r1rzs zsphinx_domains.disabletyper3cCs|}d|vr6|dd\}}||jjvr,|j|}t|||}|dur+|gfSn$ttd||n|jj d}|durPt|||}|durP|gfSt|jd||}|durc|gfSt )ztLookup a markup element (directive or role), given its name which can be a full name (with domain). :Nz%unknown directive or role name: %s:%sdefault_domainstd) lowersplitrhdomains get_domaingetattrloggerwarningr" temp_datar^rd)rprr3 domain_namedomainelement def_domainr0r0r1lookup_domain_elements&  z$sphinx_domains.lookup_domain_elementdirective_namelanguage_moduledocumentcCs0z|d|WSty||||YSw)Nr8)rrdrn)rprrrr0r0r1r}s  zsphinx_domains.lookup_directive role_namelinenorRc Cs2z|d|WSty|||||YSw)Nr=)rrdr|)rprrrrRr0r0r1r~s  zsphinx_domains.lookup_role)rhr'r)Nr)N)rFrerf__doc__rqrur Exceptionrr{rsrzrWrrrrrr rr rr}intrr$r~r0r0r0r1rgs    0.rgc@seZdZdeddfddZdS) WarningStreamtextr)NcCsTt|}|st|ddS|\}}}td|}tj|||ddS)Nz )location) report_researchrrrstripgroupssublog)rprmatchedrrlevelmessager0r0r1writes zWarningStream.write)rFrerfrWrr0r0r0r1rsrc sZeZdZededdfddZejejddfdede d e d e d edd f fd d Z Z S)LoggingReporterrRr)cCs||j|j|j|j|jS)zACreate an instance of LoggingReporter from other reporter object.)source report_level halt_level debug_flag error_handler)clsrRr0r0r1 from_reporterszLoggingReporter.from_reporterFbackslashreplacerrrdebugrNcs(ttt}tj||||||ddS)N)r)rrrsuperrq)rprrrrrstream __class__r0r1rqs   zLoggingReporter.__init__) rFrerf classmethodrr WARNING_LEVEL SEVERE_LEVELrWrboolrq __classcell__r0r0rr1rs rcs"eZdZdZdfdd ZZS) NullReporterz A dummy reporter; write nothing.r)NcstddddS)Nri)rrqrtrr0r1rqszNullReporter.__init__r)rFrerfrrqrr0r0rr1r srcCstdkS)N)r r)__version_info__r0r0r0r1is_html5_writer_availablerUrstatecontentccsLz|jjj}tgd}||_|j|jj_dVW||jj_dS||jj_w)z1Switch current source input of state temporarily.N)memorRget_source_and_liner input_lines)rrr state_machiner0r0r1switch_source_inputs   rcs@eZdZdZdeddffdd Zdedeffdd ZZS) SphinxFileOutputz#Better FileOutput class for Sphinx.kwargsr)Nc s$|dd|_tjdi|dS)Noverwrite_if_changedFr0)r@rrrq)rprrr0r1rq,szSphinxFileOutput.__init__datacs|jr<|jrXz/SphinxDirective.get_location..r_rrtr0r0r1 get_locationVzSphinxDirective.get_locationr)r'r)r&)rFrerfrpropertyrhrrrWrrrrrr0r0r0r1r;s  rc@seZdZUdZeed<eed<eed<eed<eed<eed<e eed<igfdedededededede ed e e e e e ffd d Z d e e e e e ffd d ZedddZedddZdded e eeffddZdde ded dfddZd efddZdS) SphinxRolezA base class for Sphinx roles. This class provides helper methods for Sphinx roles. .. note:: The subclasses of this class might not work with docutils. This class is strongly coupled with Sphinx. r3rawtextrrinlineroptionsrr)cCsx||_t||_||_||_||_||_|r||_|S|j j dd|_|js1|j j j |_|js8td|S)N default_rolerzcannot determine default role!)rrrrrrrrr3rhrr^rrr!run)rpr3rrrrrrr0r0r1__call__ms   zSphinxRole.__call__cCstrS)NotImplementedErrorrtr0r0r1rszSphinxRole.runr'cCrr)rrrrhrtr0r0r1rhrzSphinxRole.envr&cCrrrrtr0r0r1rrzSphinxRole.configNcCs|dur|j}|jj|SrS)rrrRr)rprr0r0r1rszSphinxRole.get_source_infor/cCs||\|_|_dSrSr)rpr/rr0r0r1rszSphinxRole.set_source_infocCr)rrcsrrSrrr0r0r1rrz*SphinxRole.get_location..rrtr0r0r1rrzSphinxRole.get_locationrrrS)rFrerfrrW__annotations__rrr r rrrrrrrhrrrrr0r0r0r1r[s6     rcseZdZUdZeed<eed<eed<eed<edej Z igfdeded ed e d e d e d eedeeeeefffdd ZZS) ReferenceRolezA base class for reference roles. The reference roles can accept ``link title `` style as a text for the role. The parsed result; link title and target will be stored to ``self.title`` and ``self.target``. has_explicit_titledisabledtitletargetz^(.+?)\s*(?$r3rrrrrrr)c sv|d|_|j|}|r"d|_t|d|_t|d|_n d|_t||_t||_t |||||||S)N!TrF) startswithrexplicit_title_rematchrrgrouprrrr) rpr3rrrrrrrrr0r1rs    zReferenceRole.__call__)rFrerfrrrrWrecompileDOTALLrrrr r rrrrrr0r0rr1rs" rcs\eZdZdZdejddddffdd Zd eddffd d Zd eddffd d Z Z S)SphinxTranslatoraxA base class for Sphinx translators. This class adds a support for visitor/departure method for super node class if visitor/departure method for node class is not found. It also provides helper methods for Sphinx translators. .. note:: The subclasses of this class might not work with docutils. This class is strongly coupled with Sphinx. rbuilderr%r)Ncs&t|||_|j|_|j|_dSrS)rrqr rr)rprr rr0r1rqs  zSphinxTranslator.__init__r/cB|jjD]}t|d|jd}|r||dSqt|dS)z Dispatch node to appropriate visitor method. The priority of visitor method is: 1. ``self.visit_{node_class}()`` 2. ``self.visit_{super_node_class}()`` 3. ``self.unknown_visit()`` zvisit_%sN)r__mro__rrFrdispatch_visitrpr/ node_classmethodrr0r1r  zSphinxTranslator.dispatch_visitcr )z Dispatch node to appropriate departure method. The priority of departure method is: 1. ``self.depart_{node_class}()`` 2. ``self.depart_{super_node_class}()`` 3. ``self.unknown_departure()`` z depart_%sN)rr rrFrdispatch_departurer rr0r1rrz#SphinxTranslator.dispatch_departure) rFrerfrrrrqrr rrr0r0rr1rs  r__document_cache__ source_pathrcCsTtdur tj|a|durttj}ddlm}|j|tj |d}| |d|S)a&Return a new empty document object. This is an alternative of docutils'. This is a simple wrapper for ``docutils.utils.new_document()``. It caches the result of docutils' and use it on second call for instantiation. This makes an instantiation of document nodes much faster. Nr)addnodes)r) rrXutils new_documentrrsphinxrrrR note_source)rrrrr0r0r1rs    rrS)frr\r contextlibrrrtypesrtypingrrrr r r r r rrrrrXr docutils.iordocutils.nodesrrrdocutils.parsers.rstrrrdocutils.parsers.rst.statesrdocutils.statemachinerrrdocutils.utilsrr packagingr sphinx.errorsr! sphinx.localer" sphinx.utilr#sphinx.util.typingr$ getLoggerrFrrrsphinx.buildersr% sphinx.configr&sphinx.environmentr'parse __version__releasersetr(rr2rWrr6r:r<r?rArHrKr-rTrbrcrrdrgrrrrrrrrr NodeVisitorrrrrr0r0r0r1sx     8                 E  B"7