3

T'ícîã@sdZddlZddlmZddlmZddlmZmZmZm	Z	m
Z
ddlmZddl
mZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZmZGdd„dƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZ Gdd„deƒZ!dS)z'Templates utility functions for Sphinx.éN)Úpartial)Úpath)ÚCallableÚDictÚListÚTupleÚUnion)ÚTemplateNotFound)ÚEnvironment)Ú
BaseLoader)ÚSandboxedEnvironment)Úpackage_dir)ÚSphinxFileSystemLoader)Úget_translator)ÚrstÚ	texescapec@sBeZdZdeddœdd„Zeeedœdd„Zeeedœd	d
„ZdS)ÚBaseRendererN)ÚloaderÚreturncCs.t|dgd|_t|jjd<|jjtƒƒdS)Nzjinja2.ext.i18n)rÚ
extensionsÚrepr)rÚenvrÚfiltersZinstall_gettext_translationsr)Úselfr©rú6/tmp/pip-build-gk9425m9/sphinx/sphinx/util/template.pyÚ__init__szBaseRenderer.__init__)Ú
template_nameÚcontextrcCs|jj|ƒj|ƒS)N)rZget_templateÚrender)rrrrrrrszBaseRenderer.render)ÚsourcerrcCs|jj|ƒj|ƒS)N)rZfrom_stringr)rr rrrrÚ
render_stringszBaseRenderer.render_string)N)	Ú__name__Ú
__module__Ú__qualname__rrÚstrrrr!rrrrrsrcsFeZdZeeeefddœ‡fdd„Zeeeedœdd„ƒZ	‡Z
S)ÚFileRendererN)Úsearch_pathrcs8t|tƒr|g}nttd|ƒƒ}t|ƒ}tƒj|ƒdS)N)Ú
isinstancer%ÚlistÚfilterrÚsuperr)rr'r)Ú	__class__rrr!s

zFileRenderer.__init__)ÚfilenamerrcCs(tjj|ƒ}tjj|ƒ}||ƒj||ƒS)N)ÚosrÚdirnameÚbasenamer)Úclsr-rr/r0rrrÚrender_from_file+szFileRenderer.render_from_file)r"r#r$rr%rrÚclassmethodrr2Ú
__classcell__rr)r,rr& s 
r&csHeZdZdeeeefddœ‡fdd„
Zeeeedœdd„ƒZ	‡Z
S)	ÚSphinxRendererN)Ú
template_pathrcs&|dkrtjjtdƒ}tƒj|ƒdS)NÚ	templates)r.rÚjoinr
r+r)rr6)r,rrr3szSphinxRenderer.__init__)r-rrcCstj||ƒS)N)r&r2)r1r-rrrrr28szSphinxRenderer.render_from_file)N)r"r#r$rr%rrr3rr2r4rr)r,rr52s"r5cs(eZdZdeeddœ‡fdd„
Z‡ZS)Ú
LaTeXRendererN)r6Úlatex_enginercsŒ|dkrtjjtddƒ}tƒj|ƒttj|d}||j	j
d<||j	j
d<tj|j	j
d<d|j	_d|j	_
d	|j	_d|j	_d
|j	_d|j	_dS)Nr7Zlatex)r:ÚeÚescapeZeabbrz<%=z%>z<%z<#z#>)r.rr8r
r+rrrr<rrZescape_abbrZvariable_start_stringZvariable_end_stringZblock_start_stringZblock_end_stringZcomment_start_stringZcomment_end_string)rr6r:r<)r,rrr>szLaTeXRenderer.__init__)NN)r"r#r$r%rr4rr)r,rr9=sr9cs4eZdZdeeeefeddœ‡fdd„
Z‡ZS)ÚReSTRendererN)r6ÚlanguagercsHtƒj|ƒ|jj|dtj|jjd<tj|jjd<tj|jjd<dS)N)r>r;r<Úheading)r+rrÚextendrr<rr?)rr6r>)r,rrrTs
zReSTRenderer.__init__)NN)r"r#r$rr%rrr4rr)r,rr=Ssr=c@sHeZdZdZeeeeeddœdd„Zeeeeee	fdœdd„Z
dS)	ÚSphinxTemplateLoaderz(A loader supporting template inheritanceN)ÚconfdirÚtemplates_pathsÚsystem_templates_pathsrcCshg|_g|_x(|D] }ttj||ƒƒ}|jj|ƒqWx,|D]$}t|ƒ}|jj|ƒ|jj|ƒq<WdS)N)ÚloadersÚ
sysloadersrrr8Úappend)rrBrCrDZtemplates_pathrrrrrcs

zSphinxTemplateLoader.__init__)ÚenvironmentÚtemplatercCs`|jdƒr|j}|dd…}n|j}x.|D]&}y|j||ƒStk
rNYq*Xq*Wt|ƒ‚dS)Nú!é)Ú
startswithrFrEÚ
get_sourcer	)rrHrIrErrrrrMqs


zSphinxTemplateLoader.get_source)r"r#r$Ú__doc__r%rrr
rrrMrrrrrA`s
rA)"rNr.Ú	functoolsrrÚtypingrrrrrZjinja2r	Zjinja2.environmentr
Zjinja2.loadersrZjinja2.sandboxrZsphinxr
Zsphinx.jinja2gluerZ
sphinx.localerZsphinx.utilrrrr&r5r9r=rArrrrÚ<module>s$