3

T'íckã@sœdZddlmZddlmZddlmZmZmZm	Z	m
Z
mZmZm
Z
ddlmZmZmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZydd
lm Z Wn e!k
rÜddlm"Z YnXerîddl#m$Z$e%e&dœdd„Z'e%e(dœdd„Z)e
e(e%fe%dœdd„Z*ee(e
edœdd„Z+ee%e%dœdd„Z,Gdd„dƒZ-e e	e%eee%dœd d!„ƒZ.Gd"d#„d#eƒZ/Gd$d%„d%eeƒZ0d&S)'z+Glue code for the jinja2 templating engine.é)Úpath)Úpformat)Ú
TYPE_CHECKINGÚAnyÚCallableÚDictÚIteratorÚListÚTupleÚUnion)Ú
BaseLoaderÚFileSystemLoaderÚTemplateNotFound)ÚEnvironment)ÚSandboxedEnvironment)Úopen_if_exists)ÚTemplateBridge)ÚTheme)Úlogging)Úmtimes_of_files)Úpass_context)Úcontextfunction)ÚBuilder)ÚvalÚreturncCst|tƒr|jƒdkSt|ƒS)NÚtrueÚ1ÚyesÚon)rrrr)Ú
isinstanceÚstrÚlowerÚbool)r©r#ú3/tmp/pip-build-gk9425m9/sphinx/sphinx/jinja2glue.pyÚ_tobools
r%cCs"yt|ƒStk
rdSXdS)Nr)ÚintÚ
ValueError)rr#r#r$Ú_toint sr(cCs4|dkrdSt|ƒjƒr0t|ƒdkr(dSd|S|S)a
    Make val a css dimension. In particular the following transformations
    are performed:

    - None -> 'initial' (default CSS value)
    - 0 -> '0'
    - ints and string representations of ints are interpreted as pixels.

    Everything else is returned unchanged.
    NÚinitialrÚ0z%spx)r Úisdigitr&)rr#r#r$Ú_todim's
r,)ÚvaluesÚslicesrc
csÀt|ƒ}d}x$|D]}|dt|ddƒ7}qW||}d}x|t|ƒD]p}d}|}	||dkrjt|ƒ}n@x>||d…D].}|dt|ddƒ7}|d7}||krxPqxW||	|…VqHWdS)Nré)ÚlistÚlenÚrange)
r-r.ÚseqÚlengthÚvalueZitems_per_sliceÚoffsetZslice_numberÚcountÚstartr#r#r$Ú_slice_index9s"

r9)ÚcontextÚkeyrcCs>d|kri|jd<|r:||jdkr:d|jd|<d|SdS)z+Helper to output each access key only once.Z_accesskeysr/zaccesskey="%s"Ú)Úvars)r:r;r#r#r$Ú	accesskeyNs
r>c@s:eZdZddœdd„Zedœdd„Zedœdd„ZeZdS)	ÚidgenN)rcCs
d|_dS)Nr)Úid)Úselfr#r#r$Ú__init__Yszidgen.__init__cCs|jS)N)r@)rAr#r#r$Úcurrent\sz
idgen.currentcCs|jd7_|jS)Nr/)r@)rAr#r#r$Ú__next___szidgen.__next__)Ú__name__Ú
__module__Ú__qualname__rBr&rCrDÚnextr#r#r#r$r?Xsr?)r:ÚmessageÚargsÚkwargsrcOsJd|kr*|jdƒ|jddƒ}d||f}tjdƒ}|j|f|ž|ŽdS)NZpagenameZfile_suffixr<zin rendering %s: %sz
sphinx.themes)ÚgetrÚ	getLoggerÚwarning)r:rIrJrKÚfilenameÚloggerr#r#r$rNes
rNc@s,eZdZdZeeeeeefdœdd„ZdS)ÚSphinxFileSystemLoaderzd
    FileSystemLoader subclass that is not so strict about '..'  entries in
    template names.
    )ÚenvironmentÚtemplatercs€xr|jD]h}tj||ƒ‰tˆƒ}|dkr*q||jƒj|jƒ}WdQRXtjˆƒ‰tdœ‡‡fdd„}|ˆ|fSWt	|ƒ‚dS)N)rcs(ytjˆƒˆkStk
r"dSXdS)NF)rÚgetmtimeÚOSErrorr#)rOÚmtimer#r$Úuptodate€sz3SphinxFileSystemLoader.get_source.<locals>.uptodate)
Ú
searchpathrÚjoinrÚreadÚdecodeÚencodingrTr"r)rArRrSrXÚfÚcontentsrWr#)rOrVr$Ú
get_sourceus
z!SphinxFileSystemLoader.get_sourceN)	rErFrGÚ__doc__rr r
rr_r#r#r#r$rQosrQc@sxeZdZdZddeeeddœdd„Zeeedœdd	„Z	eeed
œdd„Z
ed
œdd„Ze
eeeeefdœdd„ZdS)ÚBuiltinTemplateLoaderzK
    Interfaces the rendering environment of jinja2 for use in Sphinx.
    Nr)ÚbuilderÚthemeÚdirsrc	sB|r |jƒ}|dd„|Dƒ}n|r6t|ƒ}t|ƒ}ng}g}tˆjjƒ|_ˆjjr‚‡fdd„ˆjjDƒ}||dd…<||dd…<||_dd„|Dƒ|_ˆjj	dk	}|r®dgng}t
||d|_t|jj
d<t|jj
d	<t|jj
d
<t|jj
d<ttƒ|jjd<t|jjd
<ttƒ|jjd<t|jjd<|r>|jjˆjj	ƒdS)NcSsg|]}tj|dƒ‘qS)z..)rrY)Ú.0Úpr#r#r$ú
<listcomp>–sz.BuiltinTemplateLoader.init.<locals>.<listcomp>csg|]}tjˆj|ƒ‘qSr#)rrYZconfdir)reÚtp)rbr#r$rg¡srcSsg|]}t|ƒ‘qSr#)rQ)reÚxr#r#r$rgªszjinja2.ext.i18n)ÚloaderÚ
extensionsZtoboolZtointZtodimZslice_indexÚdebugrNr>r?)Zget_theme_dirsr0r1ÚconfigZtemplates_pathÚtemplatepathlenÚ	pathchainÚloadersZappZ
translatorrrRr%Úfiltersr(r,r9rrÚglobalsrNr>r?Zinstall_gettext_translations)	rArbrcrdroZloaderchainZcfg_templates_pathZuse_i18nrkr#)rbr$Úinits<


zBuiltinTemplateLoader.init)rSr:rcCs|jj|ƒj|ƒS)N)rRZget_templateÚrender)rArSr:r#r#r$rt»szBuiltinTemplateLoader.render)Úsourcer:rcCs|jj|ƒj|ƒS)N)rRZfrom_stringrt)rArur:r#r#r$Ú
render_string¾sz#BuiltinTemplateLoader.render_string)rcCstt|jdƒƒS)Nz.html)Úmaxrro)rAr#r#r$Únewest_template_mtimeÁsz+BuiltinTemplateLoader.newest_template_mtime)rRrSrcCsf|j}|jdƒr*||jd…}|dd…}x.|D]&}y|j||ƒStk
rTYq0Xq0Wt|ƒ‚dS)Nú!r/)rpÚ
startswithrnr_r)rArRrSrprjr#r#r$r_Æs


z BuiltinTemplateLoader.get_source)NN)rErFrGr`rr	r rsrrtrvÚfloatrxrr
rr_r#r#r#r$ra‰s+raN)1r`ÚosrÚpprintrÚtypingrrrrrr	r
rZjinja2rr
rZjinja2.environmentrZjinja2.sandboxrZjinja2.utilsrZsphinx.applicationrZsphinx.themingrZsphinx.utilrZsphinx.util.osutilrrÚImportErrorrZsphinx.buildersrr r"r%r&r(r,r9r>r?rNrQrar#r#r#r$Ú<module>s6(