o $a@sdZddlmZmZmZmZmZmZmZm Z ddl m Z ddl m Z ddlmZddlmZddlmZddlmZdd lmZdd lmZmZer\dd lmZdd lmZdd lm Z e!e"Z#GdddeZ$GdddeZ%GdddeZ&dddee'effddZ(dS)z sphinx.domains.citation ~~~~~~~~~~~~~~~~~~~~~~~ The citation domain. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. ) TYPE_CHECKINGAnyDictListOptionalSetTuplecast)nodes)Element) pending_xref)Domain)__)SphinxTransform)logging)copy_source_info make_refnode)Sphinx)Builder)BuildEnvironmentc@seZdZdZdZdZddiZedee e e e e fffddZ edee e e ffdd Zd e dd fd d Zdee dedd fddZdejdd fddZdedd fddZd%ddZddde ddde de ded edeefd!d"Zddde ddde ded edee e effd#d$Zd S)&CitationDomainzDomain for citations.citationrefzcitation not found: %(target)sreturncC|jdiS)N citationsdata setdefaultselfr!9/usr/lib/python3/dist-packages/sphinx/domains/citation.pyr*zCitationDomain.citationscCr)N citation_refsrrr!r!r"r$.r#zCitationDomain.citation_refsdocnameNcCspt|jD]\}\}}}||kr|j|=qt|jD]\}}||hkr,|j|=q||vr5||qdS)N)listritemsr$remove)r r%keyfn_llinenodocnamesr!r!r" clear_doc2s   zCitationDomain.clear_docr- otherdatacCsr|dD]\}}|d|vr||j|<q|dD]\}}|j|t}|D] }||vr5||q*qdS)Nrrr$)r'rr$rsetadd)r r-r/r)rr$r%r!r!r"merge_domaindata<s   zCitationDomain.merge_domaindatanodecCsh|d}||jvr#|j|j|d}tjtd|||ddd|d|dd|jf|j|<dS)Nrz+duplicate citation %s, other instance in %srr)locationtypesubtyper%ids)astextrenvdoc2pathloggerwarningrline)r r3labelpathr!r!r" note_citationGs  "zCitationDomain.note_citationcCs&|j|dt}||jjdS)N reftarget)r$rr0r1r9r%)r r3r-r!r!r"note_citation_referenceOsz&CitationDomain.note_citation_referencecCsD|jD]\}\}}}||jvrtjtd|dd||fdqdS)Nz Citation [%s] is not referenced.rr)r5r6r4)rr'r$r;r<r)r namer%labelidr,r!r!r"check_consistencySs   z CitationDomain.check_consistencyr9r fromdocnamebuilderrtyptargetcontnodec Cs,|j|d\}} } |sdSt|||| |S)N)rKr)rgetr) r r9rFrGrHrIr3rJr%rDr,r!r!r" resolve_xrefYs zCitationDomain.resolve_xrefc Cs,||||d|||}|durgSd|fgS)Nr)rM)r r9rFrGrIr3rJrefnoder!r!r"resolve_any_xrefcs zCitationDomain.resolve_any_xref)rN)__name__ __module__ __qualname____doc__rCr>dangling_warningspropertyrstrrintrrr$r.rr2r rr@r rBrEr rrMrOr!r!r!r"r sF"     rc@&eZdZdZdZdeddfddZdS)CitationDefinitionTransformz3Mark citation definition labels as not smartquoted.kkwargsrNcKsXtt|jd}|jtjD]}|jj|d<| |ttj |d}d|d<qdS)Nrr%rFsupport_smartquotes) r rr9 get_domaindocumenttraverser rr%r@r>)r r[domainr3r>r!r!r"applyqs   z!CitationDefinitionTransform.applyrPrQrRrSdefault_priorityrrar!r!r!r"rYmsrYc@rX)CitationReferenceTransformz| Replace citation references by pending_xref nodes before the default docutils transform tries to resolve them. rZr[rNc Kstt|jd}|jtjD]1}|}t |dd|dd|d| dgd}|t |d|7}t ||| |||qdS) NrrTFr7classes) refdomainreftyperArefwarnr\r7rez[%s])r rr9r]r^r_r citation_referencer8r rLinliner replace_selfrB)r r[r`r3rIrr!r!r"ras    z CitationReferenceTransform.applyrbr!r!r!r"rd}srdapprrcCs,|t|t|tdddddS)NbuiltinT)version env_versionparallel_read_safeparallel_write_safe) add_domainr add_transformrYrd)rlr!r!r"setups   ruN))rStypingrrrrrrrr docutilsr docutils.nodesr sphinx.addnodesr sphinx.domainsr sphinx.localersphinx.transformsr sphinx.utilrsphinx.util.nodesrrsphinx.applicationrsphinx.buildersrsphinx.environmentr getLoggerrPr;rrYrdrVrur!r!r!r"s&(           M