3

T'íc+ã@sdZddlmZmZmZmZmZmZmZm	Z	ddl
mZddlm
Z
ddlmZddlmZddlmZddlmZdd	lmZdd
lmZmZer¸ddlmZddlmZdd
lm Z ej!e"ƒZ#Gdd„deƒZ$Gdd„deƒZ%Gdd„deƒZ&dee'efdœdd„Z(dS)zThe citation domain.é)Ú
TYPE_CHECKINGÚAnyÚDictÚListÚOptionalÚSetÚTupleÚcast)Únodes)ÚElement)Úpending_xref)ÚDomain)Ú__)ÚSphinxTransform)Úlogging)Úcopy_source_infoÚmake_refnode)ÚSphinx)ÚBuilder)ÚBuildEnvironmentc
@sþeZdZdZdZdZddiZeee	e
e	e	effdœdd„ƒZeee	e
e	fdœdd	„ƒZe	d
dœdd
„Zee	ed
dœdd„Zejd
dœdd„Zed
dœdd„Zd
dœdd„Zde	de	e	eeeedœdd„Zde	de	eeee
e	efdœdd„Zd
S) ÚCitationDomainzDomain for citations.ÚcitationÚrefzcitation not found: %(target)s)ÚreturncCs|jjdiƒS)NÚ	citations)ÚdataÚ
setdefault)Úself©rú9/tmp/pip-build-gk9425m9/sphinx/sphinx/domains/citation.pyr"szCitationDomain.citationscCs|jjdiƒS)NÚ
citation_refs)rr)rrrrr &szCitationDomain.citation_refsN)ÚdocnamercCsxx0t|jjƒƒD]\}\}}}||kr|j|=qWx@t|jjƒƒD].\}}||hkr^|j|=qB||krB|j|ƒqBWdS)N)ÚlistrÚitemsr Úremove)rr!ÚkeyÚfnZ_lZ_linenoÚdocnamesrrrÚ	clear_doc*s

zCitationDomain.clear_doc)r'Ú	otherdatarcCs~x.|djƒD]\}}|d|kr||j|<qWxH|djƒD]8\}}|jj|tƒƒ}x|D]}||kr\|j|ƒq\Wq>WdS)Nrrr )r#rr rÚsetÚadd)rr'r)r%rr r!rrrÚmerge_domaindata4s
zCitationDomain.merge_domaindata)ÚnodercCsh|djƒ}||jkrF|jj|j|dƒ}tjtdƒ|||ddd|d|dd|jf|j|<dS)Nrz+duplicate citation %s, other instance in %srr)ÚlocationÚtypeÚsubtyper!Úids)ÚastextrÚenvZdoc2pathÚloggerÚwarningrÚline)rr-ÚlabelÚpathrrrÚ
note_citation?s
zCitationDomain.note_citationcCs&|jj|dtƒƒ}|j|jjƒdS)NÚ	reftarget)r rr*r+r3r!)rr-r'rrrÚnote_citation_referenceGsz&CitationDomain.note_citation_referencecCsHxB|jjƒD]4\}\}}}||jkrtjtdƒ|dd||fdqWdS)Nz Citation [%s] is not referenced.rr)r/r0r.)rr#r r4r5r)rÚnamer!Z_labelidÚlinenorrrÚcheck_consistencyKs
z CitationDomain.check_consistencyrr)r3ÚfromdocnameÚbuilderÚtypÚtargetr-ÚcontnodercCs,|jj|dƒ\}}	}
|sdSt||||	|ƒS)NÚr)rDrDr)rÚgetr)rr3r?r@rArBr-rCr!Zlabelidr=rrrÚresolve_xrefQs
zCitationDomain.resolve_xref)r3r?r@rBr-rCrcCs0|j|||d|||ƒ}|dkr"gSd|fgSdS)Nr)rF)rr3r?r@rBr-rCZrefnoderrrÚresolve_any_xref[szCitationDomain.resolve_any_xref)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r<r7Zdangling_warningsÚpropertyrÚstrrÚintrrr r(rr,r
rr9rr;r>rrrFrGrrrrrs&"
rc@s$eZdZdZdZeddœdd„ZdS)ÚCitationDefinitionTransformz3Mark citation definition labels as not smartquoted.ikN)ÚkwargsrcKs\tt|jjdƒƒ}xD|jjtjƒD]2}|jj|d<|j	|ƒttj
|dƒ}d|d<q"WdS)Nrr!rFÚsupport_smartquotes)r	rr3Ú
get_domainÚdocumentÚfindallr
rr!r9r7)rrPÚdomainr-r7rrrÚapplyis
z!CitationDefinitionTransform.apply)rHrIrJrKÚdefault_priorityrrVrrrrrOesrOc@s$eZdZdZdZeddœdd„ZdS)ÚCitationReferenceTransformz|
    Replace citation references by pending_xref nodes before the default
    docutils transform tries to resolve them.
    ikN)rPrcKsŒtt|jjdƒƒ}xt|jjtjƒD]b}|jƒ}t	|dd|dd|d|j
dgƒd}|tj|d|ƒ7}t||ƒ|j
|ƒ|j|ƒq"WdS)	NrrTFr1Úclasses)Z	refdomainZreftyper:ZrefwarnrQr1rYz[%s])r	rr3rRrSrTr
Zcitation_referencer2rrEÚinlinerZreplace_selfr;)rrPrUr-rBrrrrrV|s

z CitationReferenceTransform.apply)rHrIrJrKrWrrVrrrrrXusrXr)ÚapprcCs,|jtƒ|jtƒ|jtƒdddddœS)NÚbuiltinéT)ÚversionZenv_versionZparallel_read_safeZparallel_write_safe)Z
add_domainrZ
add_transformrOrX)r[rrrÚsetups


r_N))rKÚtypingrrrrrrrr	Zdocutilsr
Zdocutils.nodesrZsphinx.addnodesrZsphinx.domainsr
Z
sphinx.localerZsphinx.transformsrZsphinx.utilrZsphinx.util.nodesrrZsphinx.applicationrZsphinx.buildersrZsphinx.environmentrÚ	getLoggerrHr4rrOrXrMr_rrrrÚ<module>s$(
M