%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/templates.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZe
jd d#kr�ddlZddlZeZnddlZeZddlZddlZddlZddlZddlZddlZddlZddlZddl m!Z!m"Z"m#Z#ddl$Zddl%Zdd	l&m'Z'dd
l(m)Z)m*Z*m+Z+ddlm,Z-ej.e/�Z0ej1j2e-dd�Z3d
Z4ej5e4�Z6de7fd��YZ8de7fd��YZ9d�Z:d�Z;d�Z<d�Z=dd�Z?dd�Z@dd�ZAdd�ZBdd�ZCdd�ZDed�ZEe:e@�ZFe:eA�ZGe:eB�ZHe:eC�ZIe:eD�ZJieFd6eGd6eEd6eHd 6eId!6eJd"6ZKdS($u
Template render systems
i(tabsolute_importtprint_functiontunicode_literalsN(tsixiii(tSaltRenderErrortCommandExecutionErrortSaltInvocationError(tOrderedDict(tJinjaFiltert	JinjaTesttJinjaGlobal(t__path__u	templatesuutf-8t
AliasedLoadercB@s2eZdZd�Zd�Zd�Zd�ZRS(uh
    Light wrapper around the LazyLoader to redirect 'cmd.run' calls to
    'cmd.shell', for easy use of shellisms during templating calls

    Dotted aliases ('cmd.run') must resolve to another dotted alias
    (e.g. 'cmd.shell')

    Non-dotted aliases ('cmd') must resolve to a dictionary of function
    aliases for that module (e.g. {'run': 'shell'})
    cC@s
||_dS(N(twrapped(tselfR
((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyt__init__EscC@s|j|S(N(R
(Rtname((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyt__getitem__HscC@st|j|�S(N(tgetattrR
(RR((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyt__getattr__KscC@s
||jkS(N(R
(RR((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyt__contains__Ns(t__name__t
__module__t__doc__RRRR(((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyR9s

			t
AliasedModulecB@s eZdZd�Zd�ZRS(u
    Light wrapper around module objects returned by the LazyLoader's getattr
    for the purposes of `salt.cmd.run()` syntax in templates

    Allows for aliasing specific functions, such as `run` to `shell` for easy
    use of shellisms during templating calls
    cC@s||_||_dS(N(taliasesR
(RR
R((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyRZs	cC@st|j|�S(N(RR
(RR((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyR^s(RRRRR(((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyRRs	c@s(ttdd�fd�}�|_|S(Nc
@s4|dkri}nd|kr8t|d�|d<n|j|�|}d|ks]t�d|ksot�d|kr�|djdd�}|dk	r�||d<|j�jdd�jd	�s�tjj	|�}n|jdd�}|j
|jdd��}|d
kr#||}ntjj	|�jdd�}	i|d6|	dkr]dn|	d
6|	jdd�d6}
|j|
�n|jdd�|d<|jdd�|d<|jdd�|d<||d<nt|tj
�r�|r�|}q�yR|dk	r!tjj||�}ntj|dt��}|j�}WdQXWq�ttttfk
r�}
tjjj|�r�tdtd|�Stjd||
dtj �|
�q�Xn|j�}|j!�y��|||�}tjj"j#�ret$}tjj%j&|dt�jdtj'f�r4t}ntj'j|j(��}|re|tj'7}qenWnIt)k
r�}
tj*d��n�t+k
r�tdt$dt,j-��SX|r�tdtd|�St.j/ddt$dtjjj0��)}|j1tjj%j2|dt��WdQXtdtd|j3�SdS( Nusaltuoptsusaltenvuslsu.u/utplpathu\u	/init.slsi����utplfileuutpldirutpldotu
slsdotpathu:uslscolonpathu_usls_pathuslspathurtresulttdatau,Exception occurred while reading file %s: %stexc_info_on_logleveltencodingu
uRendering exception occurreduwbtdeletetprefix(4tNoneRtupdatetAssertionErrortreplacetlowertendswithtostpathtdirnametrfindt
isinstanceRtstring_typestjointcodecstopentSLS_ENCODINGtreadtUnicodeDecodeErrort
ValueErrortOSErrortIOErrortsalttutilstfilest	is_binarytdicttTruetlogterrortloggingtDEBUGtclosetplatformt
is_windowstFalsetstringutilst
to_unicodetlinesept
splitlinesRt	exceptiont	Exceptiont	tracebackt
format_excttempfiletNamedTemporaryFiletTEMPFILE_PREFIXtwritetto_bytesR(ttmplsrctfrom_strtto_strtcontextttmplpathtkwstslspathttemplatetittpldirttpldatattmplstrt_tmplsrctexctoutputtnewlinetoutf(t
render_str(s8/usr/lib/python2.7/site-packages/salt/utils/templates.pytrender_tmplds�	

!

		


-	

'((RBR Ra(RaRb((Ras8/usr/lib/python2.7/site-packages/salt/utils/templates.pytwrap_tmpl_funcbs[	cC@sGy/g|D]}|ddkr
|^q
dSWntk
rBnXdS(uC
    Return the line number where the template error was found
    iutop-level template codeutemplateu<module>i����N(utop-level template codeutemplateu<module>(t
IndexError(ttb_datatx((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyt_get_jinja_error_slug�s	
cC@s5yt|�}dj|�SWntk
r0nXdS(uB
    Return an understandable message from jinja error output
    u
{0}({1}):
{3}N(RgtformatRdR (Retline((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyt_get_jinja_error_message�s
cC@s*yt|�dSWntk
r%nXdS(uC
    Return the line number where the template error was found
    iN(RgRdR (Re((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyt_get_jinja_error_line�s

cC@s�|si}nd}t|�}t|�}t|�}t}d}d|kr�|ddkr�tjj|d�r�|d}t}q�nS|dj	dd�}|dj
|�r�tjj|d�r�t}|d}n|r{|rcdj|j�d�}t
jjj|��"}	t
jjj|	j��}
WdQX|t
jjj|
|d	d
�7}ndj|�}d}n||fS(u�
    Return the error line and error message output from
    a stacktrace.
    If we are in a macro, also output inside the message the
    exact location of the error in the macro
    uuslsiu	<unknown>u.u/u
{0}
Ntmarkeru    <======================(RgRkRjRBR R&R'texistsR:R#R%RhRFR5R6R7tfopenRCRDR0tget_context(ttraceRStoutR<Ritmsgtadd_logt
template_pathtfilentfp_ttemplate_contents((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyt_get_jinja_error�s<	

!
	c@s�|d}|d}d}t}|rKt|tj�rK|jt�}n|jtj	�ritj	}n|jd�r�d}n|s�|r�t
jtjj
|��}q�n*tjjj||d|jdt��}igd6|d6�tt
jd�r�djd	�ntt
jd
�r8�djd�ntt
jd�r^�djd
�n�djtjjj�|jdi�}|jdi�}t|t�r�|ni}t|t�r�|ni}|jdt�rtjd�tjd�t|d<t|d<n|jdt�rXtjd�tjd�t|d<t|d<n�fd�}	d|kr�|ddkr�|	|d�n
|	|d�|jdt�r�t
j��}
nt
jdt
j��}
|
jjd�}|
jj t!j"�|
jj t#j$�|dk	r0||
jd<n|
j%j t&j'�t(|
j%d<tjjj)|
j%d<tjj*j+|
jd <i}x�tj,|�D]�\}
}t|tj-�s�|||
<q�ny#tjj.j/|d!t�||
<Wq�t0k
r!}tjd"t�tjj*j|�||
<q�Xq�Wy2|
j1|�}|j%j |�|j2|�}WnYt
j3j4k
r�}t5j6t7j8�d#�}t9|d$|�d%}d}t:d&j;||�d'|��n�t
j3j<t
j3j=fk
rH}t5j6t7j8�d#�}t9|d$|�\}}|s'd}nt:d(j;||�||��nlt>t?fk
r�}t5j6t7j8�d#�}t9|d$|�\}}|s�d}nt:d)j;||�||��n�t@k
r�}t5jA�}t5j6t7j8�d#�}t9|d$|�\}}|sd}n|d*j;|�7}tjd+�tjd,d-t�tjd.|�tjd/|�tjd0|�tjd1|�t:d2j;||�||d3|��nX|r�||7}n|S(4Nuoptsusaltenvu
tpillar_rendu_pillar_rendu
extensionsuloaderuwith_ujinja2.ext.with_udou
jinja2.ext.douloopcontrolsujinja2.ext.loopcontrolsu	jinja_envu
jinja_sls_envujinja_trim_blocksuJinja2 trim_blocks is enableduzjinja_trim_blocks is deprecated and will be removed in a future release, please use jinja_env and/or jinja_sls_env insteadutrim_blocksujinja_lstrip_blocksuJinja2 lstrip_blocks is enabledu|jinja_lstrip_blocks is deprecated and will be removed in a future release, please use jinja_env and/or jinja_sls_env insteadu
lstrip_blocksc@s{xttj|�D]c\}}|j�}ttj|j��rctjd|||�|�|<qtj	d|�qWdS(Nu)Jinja2 environment %s was set to %s by %su'Jinja2 environment %s is not recognized(
Rt	iteritemsR$thasattrtjinja2tdefaultstupperR;tdebugtwarning(toptstoptnametktv(tenv_args(s8/usr/lib/python2.7/site-packages/salt/utils/templates.pytopt_jinja_env_helperVs
uslsuuallow_undefinedt	undefinedutojsonuodictushow_full_contextulistRuDFailed to decode using default encoding (%s), trying system encodingiRSiuJinja variable {0}{1}tbufuJinja syntax error: {0}{1}u7Problem running salt function in Jinja template: {0}{1}u
{0}uJinja Erroru
Exception:texc_infouOut: %suLine: %suTmplStr: %suTraceStr: %suJinja error: {0}{1}Rp(BR RBR*Rt	text_typetdecodeR/R%R&RER|tFileSystemLoaderR'R(R5R6tjinjatSaltCacheLoadertgetR{texttappendtSerializerExtensionR9R;RR�R:tEnvironmenttStrictUndefinedtfiltersttestsR!R	tsalt_jinja_testsRtsalt_jinja_filterstglobalsR
tsalt_jinja_globalsRtshow_full_contextRtis_listRzR+RCRDR1tfrom_stringtrendert
exceptionstUndefinedErrorRIt
extract_tbtsysR�RxRRhtTemplateRuntimeErrortTemplateSyntaxErrorRRRHRJ(R[RSRTR�tsaltenvtloaderR_t
opt_jinja_envtopt_jinja_sls_envR�t	jinja_envt
tojson_filtertdecoded_contexttkeytvaluetexRWR^R]RpRqRittracestr((R�s8/usr/lib/python2.7/site-packages/salt/utils/templates.pytrender_jinja_tmpl"s�

	!*







	
	

#!
				


c	C@sddl}ddlm}ddlm}|d}d}|s||r�ddlm}|dtj	j
|�g�}q�n%||d|d|jd	t��}yK||d
t
dd|kr�|djd
d�ndd|�j|�SWn,tk
rt|jj�j���nXdS(Ni(tTemplate(tSaltMakoTemplateLookupusaltenv(tTemplateLookuptdirectoriesuoptsRyu_pillar_rendtstrict_undefinedturiuslsu.u/tlookup(tmako.exceptionst
mako.templateR�tsalt.utils.makoR�R tmako.lookupR�R&R'R(R�RBR:R#R�RHRR�ttext_error_template(	R[RSRTtmakoR�R�R�R�R�((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pytrender_mako_tmpl�s,
$(	
cC@s#ddlm}||�j|�S(Ni(tTemplateParser(twemplate.wemplateR�R�(R[RSRTR�((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pytrender_wempy_tmpl�scC@s�|jdd�}|dks*|dkrIddlm}||�}nG|dkrtddlm}||�}ndd	lm}||�}|j|�j|�S(
u�
    Render a Genshi template. A method should be passed in as part of the
    context. If no method is passed in, xml is assumed. Valid methods are:

    .. code-block:

        - xml
        - xhtml
        - html
        - text
        - newtext
        - oldtext

    Note that the ``text`` method will call ``NewTextTemplate``. If ``oldtext``
    is desired, it must be called explicitly
    umethoduxmlutextunewtexti(tNewTextTemplateuoldtext(tOldTextTemplate(tMarkupTemplate(R�tgenshi.templateR�R�R�tgenerateR�(R[RSRTtmethodR�ttmplR�R�((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pytrender_genshi_tmpl�scC@s2ddlm}tjjj||d|g��S(u$
    Render a Cheetah template.
    i(R�t
searchList(tCheetah.TemplateR�R5R6RR�(R[RSRTR�((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pytrender_cheetah_tmplscK@s#tjj|�siStjj|�}|jd�d}tr�tjj||�}tj	j
||d|�}|dkr�t��ntj	j
|�}|jj|�|tj|<ntj||�}d|krBd|krBt|d|d�dddd	g}x4|D])}	d
j|	�}
t||
||	�qWnx"|D]}t||||�qIWy�|j�}|r�itd6|d6Stjjj�}
tjjj|
d
��#}|jtjjj|��WdQXitd6|
d6SWn,t k
rt!j"�}it#d6|d6SXdS(u�
    Render a template from a python source file

    Returns::

        {'result': bool,
         'data': <Error data or rendered file path>}
    u.iR�u__env__usaltenvusaltugrainsupillaruoptsu__{0}__uresultudatauw+N($R&R'tisfiletbasenametsplitt
USE_IMPORTLIBt	importlibt	machinerytSourceFileLoadertutiltspec_from_file_locationR tImportErrortmodule_from_specR�texec_moduleR�tmodulestimptload_sourcetsetattrRhtrunR:R5R6R7tmkstempRnRNRCRRRHRIRJRB(tsfntstringtkwargst
base_fnameRR�tspectmodtbuiltinstbuiltintargtkwargRttgtttargetttrb((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pytpysF	


"


ujinjaumakoupyuwempyugenshiucheetah(ii(LRt
__future__RRRR-R&R=RKRIR�R|t
jinja2.exttsalt.extRtversion_infotimportlib.machineryR�timportlib.utilR:R�R�RBtsalt.utils.dataR5tsalt.utils.dateutilstsalt.utils.httptsalt.utils.filestsalt.utils.platformtsalt.utils.yamlencodingtsalt.utils.hashutilstsalt.utils.stringutilstsalt.exceptionsRRRtsalt.utils.jinjatsalt.utils.networktsalt.utils.odictRtsalt.utils.decorators.jinjaRR	R
Rtsaltpatht	getLoggerRR;R'R,tTEMPLATE_DIRNAMER/t
getencodertSLS_ENCODERtobjectRRRcRgRjRkR RxR�R�R�R�R�R�tJINJAtMAKOtWEMPYtGENSHItCHEETAHtTEMPLATE_REGISTRY(((s8/usr/lib/python2.7/site-packages/salt/utils/templates.pyt<module>sv		e			5�	7

Zerion Mini Shell 1.0