3

T'ícÿã@s¼dZddlZddlmZmZmZmZddlmZddl	m
Z
ddlmZddl
mZmZmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlm Z ddl!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'm(Z(m)Z)ddl*m+Z+ddl,m-Z-m.Z.m/Z/ddl0m1Z1ddl2m3Z3er2ddl4m5Z5e/j6e7ƒZ8Gdd„dej9ƒZ:Gdd„de:ƒZ;Gdd„de:ƒZ<Gdd„deƒZ=eeeedœdd „Z>Gd!d"„d"eƒZ?d#e e@ejAd$œd%d&„ZBdS)'zInput/Output fileséN)Ú
TYPE_CHECKINGÚAnyÚListÚType)Únodes)Ú	Publisher)ÚValues)Ú	FileInputÚInputÚ
NullOutput)ÚParser)Ú
standalone)Ú	Transform)ÚDanglingReferences)ÚUnfilteredWriter)Úaddnodes)ÚBuildEnvironment)ÚAutoIndexUpgraderÚDoctreeReadEventÚ
FigureAlignerÚSphinxTransformer)ÚLocaleÚPreserveTranslatableMessagesÚRemoveTranslatableInline)Ú
SphinxDomains)ÚUnicodeDecodeErrorHandlerÚget_filetypeÚlogging)ÚLoggingReporter)ÚUIDTransform)ÚSphinxcszeZdZUdZgZeeeeeddœ‡fdd„Z	dddœdd	„Z
eeed
œ‡fdd„Zej
d
œ‡fd
d„Z‡ZS)ÚSphinxBaseReaderzm
    A base class of readers for Sphinx.

    This replaces reporter by Sphinx's on generating document.
    N)ÚargsÚkwargsÚreturncsXddlm}t|ƒdkrFt|d|ƒrF|d|_|jj|_|dd…}tƒj||ŽdS)Nr)r é)	Úsphinx.applicationr ÚlenÚ
isinstanceÚ_appÚenvÚ_envÚsuperÚ__init__)Úselfr"r#r )Ú	__class__©ú+/tmp/pip-build-gk9425m9/sphinx/sphinx/io.pyr-+s

zSphinxBaseReader.__init__r )Úappr$cCs||_|j|_dS)N)r)r*r+)r.r2r0r0r1Úsetup4szSphinxBaseReader.setup)r$cs:tƒjƒ|j}tg}x|D]}||kr|j|ƒqW|S)N)r,Úget_transformsÚ
transformsrÚremove)r.r5ÚunusedÚ	transform)r/r0r1r48s
zSphinxBaseReader.get_transformscsBtƒjƒ}tj|_t|ƒ|_|jj|jj	ƒ|j
}tj|ƒ|_
|S)zm
        Creates a new document object which has a special reporter object good
        for logging.
        )
r,Únew_documentrÚdocumentr/rZtransformerZset_environmentÚsettingsr*ÚreporterrZ
from_reporter)r.r:r<)r/r0r1r9Cs

zSphinxBaseReader.new_document)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r5rrrrr-r3r4rr:r9Ú
__classcell__r0r0)r/r1r!"s
	r!csNeZdZdZdddœ‡fdd„Zeeeej	dœdd	„Z
eed
œdd„Z
‡ZS)
ÚSphinxStandaloneReaderz-
    A basic document reader for Sphinx.
    r N)r2r$cs"|j|jjƒ|_tƒj|ƒdS)N)r5Úregistryr4r,r3)r.r2)r/r0r1r3[szSphinxStandaloneReader.setup)ÚsourceÚparserr;r$cCs4||_|js||_||_|j|jƒ|_|jƒ|jS)N)rDrEr;Úread_sourcer*ÚinputÚparser:)r.rDrEr;r0r0r1Úread_szSphinxStandaloneReader.read)r*r$cCs*|jjƒ}|g}|jjd|j|ƒ|dS)z-Read content from source and do post-process.zsource-readr)rDrIÚeventsÚemitÚdocname)r.r*ÚcontentÚargr0r0r1rFhs
z"SphinxStandaloneReader.read_source)r=r>r?r@r3r
rrrr:rIrÚstrrFrAr0r0)r/r1rBVs	rBcs(eZdZdZdddœ‡fdd„Z‡ZS)ÚSphinxI18nReadera
    A document reader for i18n.

    This returns the source line number of original text as current source line number
    to let users know where the error happened.
    Because the translated texts are partial and they don't have correct line numbers.
    r N)r2r$csZtƒj|ƒ|j|jjƒ|_ttttt	t
ttg}x"|D]}||jkr8|jj
|ƒq8WdS)N)r,r3r5rCr4rrrrrrrrr6)r.r2r7r8)r/r0r1r3{s

zSphinxI18nReader.setup)r=r>r?r@r3rAr0r0)r/r1rPrsrPc@s"eZdZdZdZddœdd„ZdS)ÚSphinxDummyWriterz0Dummy writer module used for generating doctree.ÚhtmlN)r$cCsdS)Nr0)r.r0r0r1Ú	translateŒszSphinxDummyWriter.translate)rR)r=r>r?r@Ú	supportedrSr0r0r0r1rQ‡srQ)rDr"r#r$cOs|S)z.Bypass source object as is to cheat Publisher.r0)rDr"r#r0r0r1ÚSphinxDummySourceClasssrUcs*eZdZdZeeddœ‡fdd„Z‡ZS)ÚSphinxFileInputzA basic FileInput for Sphinx.N)r"r#r$csd|d<tƒj||ŽdS)NÚsphinxÚ
error_handler)r,r-)r.r"r#)r/r0r1r-—szSphinxFileInput.__init__)r=r>r?r@rr-rAr0r0)r/r1rV•srVr )r2r*Úfilenamer$cCs t|jƒ}tjd|ƒtƒ}|j|ƒt|jj|ƒ}|j	j
||ƒ}|jjdkr`|j
fkr`tj
|_
t||tƒttƒd}|jd|jdƒ|j|d|jƒ|jS)z(Parse a document and convert to doctree.rWZCommonMarkParser)ÚreaderrEÚwriterZsource_classZdestinationN)Úsource_path)rrLÚcodecsÚregister_errorrBr3rÚconfigZ
source_suffixrCZcreate_source_parserr/r=Z
settings_specÚ	RSTParserrrQrVrZprocess_programmatic_settingsr;Z
set_sourceÚpublishr:)r2r*rYrXrZZfiletyperEZpubr0r0r1Úread_docœs"


rb)Cr@r]ÚtypingrrrrZdocutilsrZ
docutils.corerZdocutils.frontendrZdocutils.ior	r
rZdocutils.parsersrZdocutils.parsers.rstr`Zdocutils.readersr
Zdocutils.transformsrZdocutils.transforms.referencesrZdocutils.writersrrWrZsphinx.environmentrZsphinx.transformsrrrrZsphinx.transforms.i18nrrrZsphinx.transforms.referencesrZsphinx.utilrrrZsphinx.util.docutilsrZsphinx.versioningrr&r Ú	getLoggerr=ÚloggerÚReaderr!rBrPrQrUrVrOr:rbr0r0r0r1Ú<module>s<
4