3

T'íc³"ã
@sîddlZddlZddlmZddlmZmZmZmZmZm	Z	m
Z
ddlmZddl
mZmZmZddlmZddlmZmZddlmZdd	lmZdd
lmZddlmZddlmZdd
l m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)m*Z*m+Z+ddl,m-Z-yddl.m/Z0Wn"e1k
r:ddl2m/Z0YnXerNddl3m4Z4e#j5e6ƒZ7Gdd„dej8ƒZ8Gdd„de0e%ƒZ/Gdd„dej9ƒZ9Gdd„dej:ƒZ:Gdd„dej;ƒZ;Gdd „d e%ƒZ<Gd!d"„d"e%ƒZ=d#ee>efd$œd%d&„Z?dS)'éN)Úpath)Ú
TYPE_CHECKINGÚAnyÚDictÚListÚSequenceÚTupleÚcast)Únodes)ÚNodeÚmake_idÚsystem_message)Ú
directives)ÚimagesÚtables)Úset_classes)Úaddnodes)ÚRemovedInSphinx60Warning)Úoptional_int)Ú
MathDomain)Ú__)Úlogging)ÚSphinxDirective)Úset_source_info)ÚSEPÚos_pathÚrelpath)Ú
OptionSpec)ÚMeta)ÚSphinxcs*eZdZdZeedœ‡fdd„Z‡ZS)ÚFigureziThe figure directive which applies `:name:` option to the figure node
    instead of the image node.
    )Úreturncs¤|jjddƒ}tƒjƒ}t|ƒdks4t|dtjƒr8|St|ƒdksHt‚t	tj
|dƒ}|rp||jd<|j|ƒ|jdkržt|ƒdkržt	tj
|dƒ}|j|_|gS)NÚnameéré)ÚoptionsÚpopÚsuperÚrunÚlenÚ
isinstancer
r
ÚAssertionErrorr	ÚfigureÚadd_nameÚlineÚcaption)Úselfr"ÚresultZfigure_noder/)Ú	__class__©ú;/tmp/pip-build-gk9425m9/sphinx/sphinx/directives/patches.pyr()s


z
Figure.run)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rrr(Ú
__classcell__r3r3)r2r4r $sr cs&eZdZeedœ‡fdd„Z‡ZS)r)r!csxtƒjƒ}xh|D]`}t|tjƒrt|jddtjƒr|jdd}|jj	|jj
ƒ|_|j|_
|d|_tj|_qW|S)Nr
rÚcontent)r'r(r*r
ÚpendingÚdetailsrZ
docutils_metaÚenvÚdoc2pathÚdocnameÚsourceÚlinenor.Z
rawcontentÚmetar2)r0r1ÚnoderB)r2r3r4r(?s


zMeta.run)r5r6r7rrr(r9r3r3)r2r4r>srcsJeZdZdZeedœ‡fdd„Zeej	ee
fdœ‡fdd„Z‡ZS)ÚRSTTablezxThe table directive which sets source and line information to its caption.

    Only for docutils-0.13 or older version.)r!cstjdtƒtƒjƒS)NzRSTTable is deprecated.)ÚwarningsÚwarnrr'r()r0)r2r3r4r(VszRSTTable.runcs$tƒjƒ\}}|rt||ƒ||fS)N)r'Ú
make_titler)r0ÚtitleÚmessage)r2r3r4rG[s
zRSTTable.make_title)
r5r6r7r8rrr(rr
rHr
rGr9r3r3)r2r4rDQsrDcs*eZdZdZeedœ‡fdd„Z‡ZS)ÚCSVTablez“The csv-table directive which searches a CSV file from Sphinx project's source
    directory when an absolute path is given via :file: option.
    )r!cs¨d|jkrž|jdjttjfƒrž|jjjj}|jd}t	j
|ƒr\tjt
dƒ|j|jfdnBt	j|jt|jddd…ƒƒ}t	j|j|jƒƒ}t||ƒ|jd<tƒjƒS)NÚfilezŽ":file:" option for csv-table directive now recognizes an absolute path as a relative path from source directory. Please update your document.)Úlocationr$)r%Ú
startswithrÚosÚsepÚstateÚdocumentÚsettingsr=rÚexistsÚloggerÚwarningrr?rAÚjoinÚsrcdirrÚdirnamer>rr'r()r0r=ÚfilenameÚabspathZdocdir)r2r3r4r(hs 


 zCSVTable.run)r5r6r7r8rrr(r9r3r3)r2r4rJcsrJcsJeZdZdZeedœ‡fdd„Zeej	ee
fdœ‡fdd„Z‡ZS)Ú	ListTablez}The list-table directive which sets source and line information to its caption.

    Only for docutils-0.13 or older version.)r!cstjdtƒtƒjƒS)NzListTable is deprecated.)rErFrr'r()r0)r2r3r4r(~sz
ListTable.runcs$tƒjƒ\}}|rt||ƒ||fS)N)r'rGr)r0rHrI)r2r3r4rGƒs
zListTable.make_title)
r5r6r7r8rrr(rr
rHr
rGr9r3r3)r2r4r[ysr[c@sDeZdZUdZdZejejeje	dœZ
e
dZe
edœdd„ZdS)	ÚCodezqParse and mark up content of a code block.

    This is compatible with docutils' :rst:dir:`code` directive.
    r$)ÚclassÚforcer"znumber-linesT)r!cCs¸|jƒt|jƒdj|jƒ}tj|||jjdgƒd|jkid}|j|ƒt	||ƒ|j
rl|j
d|d<n|jjjd|j
jƒ|d<d|jkr²d	|d
<|jdr²|jd|dd<|gS)
NÚ
Úclassesr^)r`r^Úhighlight_argsrÚlanguageÚhighlight_languageznumber-linesTZlinenosraZlinenostart)Zassert_has_contentrr%rVr:r
Z
literal_blockÚgetr-rÚ	argumentsr=Z	temp_dataÚconfigrc)r0ÚcoderCr3r3r4r(™s$





zCode.runN)r5r6r7r8Úoptional_argumentsrÚclass_optionÚflagÚ	unchangedrÚoption_specrÚhas_contentrrr(r3r3r3r4r\‹s
r\c@s^eZdZUdZdZdZdZejejej	ej
dœZee
edœdd„Ze
edd	œd
d„ZdS)Ú
MathDirectiveTrr$)Úlabelr"r]Únowrap)r!c	Cs˜dj|jƒ}|jr.|jdr.|jdd|}|jjd|jjdƒƒ}tj|||jjdgƒ|jjd|d|jkd}|j	|ƒ|j
|ƒ|g}|j|ƒ|S)	Nr_rz

ror"r]rp)r`r?Únumberrorp)rVr:rer%rdr
Ú
math_blockr=r?r-rÚ
add_target)r0ZlatexrorCÚretr3r3r4r(Ås


zMathDirective.runN)rtr!cCsÖttj|dƒ}|ddks.|jjrN|drN|jjdƒ}d|jj|f|d<|dsZdStt|jj	dƒƒ}|j
|jj|d|d|j|dƒ|d<td	|dƒ}tj
dd|gd
}|jjj|ƒ|jd|ƒdS)NrroÚzsphinx.ext.math#equationsz%s:%dÚmath)rLrqzequation-%s)Úids)r	r
rrrfZmath_number_allr=Znew_serialnor?rZ
get_domainZ
note_equationZget_equation_number_forrÚtargetrPrQZnote_explicit_targetÚinsert)r0rtrCÚseqÚdomainZnode_idrxr3r3r4rs×szMathDirective.add_target)r5r6r7rmZrequired_argumentsrhZfinal_argument_whitespacerrkrirjrlrrrr(rsr3r3r3r4rn¹s
rnr)Úappr!cCsHtjdtƒtjdtƒtjdtƒtjdtƒtjdtƒddddœS)	Nr,rBz	csv-tablergrvÚbuiltinT)ÚversionZparallel_read_safeZparallel_write_safe)rZregister_directiver rrJr\rn)r|r3r3r4Úsetupïsr)@rNrErÚtypingrrrrrrr	Zdocutilsr
Zdocutils.nodesrrr
Zdocutils.parsers.rstrZdocutils.parsers.rst.directivesrrZdocutils.parsers.rst.rolesrZsphinxrZsphinx.deprecationrZsphinx.directivesrZsphinx.domains.mathrZ
sphinx.localerZsphinx.utilrZsphinx.util.docutilsrZsphinx.util.nodesrZsphinx.util.osutilrrrZsphinx.util.typingrZ$docutils.parsers.rst.directives.miscrZMetaBaseÚImportErrorZ$docutils.parsers.rst.directives.htmlZsphinx.applicationrÚ	getLoggerr5rTr rDrJr[r\rnÚstrrr3r3r3r4Ú<module>sB$
.6