https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/genshi/template/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/genshi/template/__pycache__/base.cpython-310.pyc
o

!�b�^�@s.dZddlmZddlZddlZddlmZmZmZddl	m
Z
mZmZm
Z
mZmZddlmZgd�ZdZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�Zdd�Zddd�Zddd�ZGdd�de�Ze� e�Gdd�de��Z!Gdd�de!�Z"e"j#Z#e"j$Z$e"j%Z%e"j&Z&dS) zBasic templating functionality.�)�dequeN)�
numeric_types�StringIO�BytesIO)�Attrs�Stream�StreamEventKind�START�TEXT�_ensure)�
ParseError)�Context�DirectiveFactory�Template�
TemplateError�TemplateRuntimeError�TemplateSyntaxError�BadDirectiveErrorzrestructuredtext enc@�eZdZdZddd�ZdS)rz?Base exception class for errors related to template processing.N���cCsT|durd}||_|dks|dkrd|j||f}t�||�||_||_||_dS)a9Create the exception.
        
        :param message: the error message
        :param filename: the filename of the template
        :param lineno: the number of line in the template at which the error
                       occurred
        :param offset: the column number at which the error occurred
        Nz<string>rz%s (%s, line %d))�msg�	Exception�__init__�filename�lineno�offset��self�messagerrr�r�6/usr/lib/python3/dist-packages/genshi/template/base.pyr!s	
zTemplateError.__init__�Nrr��__name__�
__module__�__qualname__�__doc__rrrrr rsrc@r)rz|Exception raised when an expression in a template causes a Python syntax
    error, or the template is not well-formed.
    NrcCs>t|t�r|jdurt|��d|jd�}t�||||�dS)a8Create the exception
        
        :param message: the error message
        :param filename: the filename of the template
        :param lineno: the number of line in the template at which the error
                       occurred
        :param offset: the column number at which the error occurred
        Nz
 (line %d)�)�
isinstance�SyntaxErrorr�str�replacerrrrrr r:s	zTemplateSyntaxError.__init__r!r"rrrr r5src@r)rz�Exception raised when an unknown directive is encountered when parsing
    a template.
    
    An unknown directive is any attribute using the namespace for directives,
    with a local name that doesn't match any registered directive.
    NrcCst�|d|||�dS)z�Create the exception
        
        :param name: the name of the directive
        :param filename: the filename of the template
        :param lineno: the number of line in the template at which the error
                       occurred
        zbad directive "%s"N)rr)r�namerrrrr rPs�zBadDirectiveError.__init__)Nrr"rrrr rHsrc@seZdZdZdS)rzfException raised when an the evaluation of a Python expression in a
    template causes an error.
    N)r#r$r%r&rrrr r\src@s�eZdZdZdd�Zdd�Zdd�ZeZdd	�Zd
d�Z	dd
�Z
dd�Zd!dd�Zd!dd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �ZdS)"r
apContainer for template input data.
    
    A context provides a stack of scopes (represented by dictionaries).
    
    Template directives such as loops can push a new scope on the stack with
    data that should only be available inside the loop. When the loop
    terminates, that scope can get popped off the stack again.
    
    >>> ctxt = Context(one='foo', other=1)
    >>> ctxt.get('one')
    'foo'
    >>> ctxt.get('other')
    1
    >>> ctxt.push(dict(one='frost'))
    >>> ctxt.get('one')
    'frost'
    >>> ctxt.get('other')
    1
    >>> ctxt.pop()
    {'one': 'frost'}
    >>> ctxt.get('one')
    'foo'
    csbt|g��_�jj�_�jj�_g�_g�_�fdd�}d�fdd�	}|�d|�|�d|�dS)	zZInitialize the template context with the given keyword arguments as
        data.
        cs|�vS)z]Return whether a variable with the specified name exists in the
            expression scope.r)r,�rrr �defined�sz!Context.__init__.<locals>.definedNcs��||�S)z�If a variable of the specified name is defined, return its value.
            Otherwise, return the provided default value, or ``None``.��get)r,�defaultr-rr �value_of�sz"Context.__init__.<locals>.value_ofr.r2�N)	r�frames�popleft�pop�
appendleft�push�_match_templates�
_choice_stack�
setdefault)r�datar.r2rr-r r{s

zContext.__init__cCstt|j��Sr3)�repr�listr4r-rrr �__repr__�szContext.__repr__cCs|�|�dduS)zuReturn whether a variable exists in any of the scopes.
        
        :param key: the name of the variable
        �N)�_find)r�keyrrr �__contains__�szContext.__contains__cCs|jD]	}||vr||=qdS)zaRemove a variable from all scopes.
        
        :param key: the name of the variable
        N�r4)rrB�framerrr �__delitem__�s

��zContext.__delitem__cCs"|�|�\}}|durt|��|S)aGet a variables's value, starting at the current scope and going
        upward.
        
        :param key: the name of the variable
        :return: the variable value
        :raises KeyError: if the requested variable wasn't found in any scope
        N)rA�KeyError)rrB�valuerErrr �__getitem__�szContext.__getitem__cCst|���S)z�Return the number of distinctly named variables in the context.
        
        :return: the number of variables in the context
        )�len�itemsr-rrr �__len__�szContext.__len__cCs||jd|<dS)z�Set a variable in the current scope.
        
        :param key: the name of the variable
        :param value: the variable value
        rNrD)rrBrHrrr �__setitem__�szContext.__setitem__NcCs,|jD]}||vr|||fSq|dfS)a&Retrieve a given variable's value and the frame it was found in.

        Intended primarily for internal use by directives.
        
        :param key: the name of the variable
        :param default: the default value to return when the variable is not
                        found
        NrD�rrBr1rErrr rA�s

	�z
Context._findcCs$|jD]}||vr||Sq|S)z�Get a variable's value, starting at the current scope and going
        upward.
        
        :param key: the name of the variable
        :param default: the default value to return when the variable is not
                        found
        rDrNrrr r0�s

�zContext.getcs*g�|jD]
}��fdd�|D�7�q�S)zlReturn the name of all variables in the context.
        
        :return: a list of variable names
        csg|]}|�vr|�qSrr��.0rB��keysrr �
<listcomp>��z Context.keys.<locals>.<listcomp>rD)rrErrQr rR�s
zContext.keyscs�fdd����D�S)z�Return a list of ``(name, value)`` tuples for all variables in the
        context.
        
        :return: a list of variables
        csg|]	}|��|�f�qSrr/rOr-rr rS�sz!Context.items.<locals>.<listcomp>rQr-rr-r rK�sz
Context.itemscCs|jd�|�dS)z-Update the context from the mapping provided.rN)r4�update)r�mappingrrr rU�szContext.updatecC�dS)zwPush a new scope on the stack.
        
        :param data: the data dictionary to push on the context stack.
        Nr)rr<rrr r8��zContext.pushcCrW)z&Pop the top-most scope from the stack.Nrr-rrr r6�rXzContext.popcCs>t�}|j��|j�|j�|j�|j�|j�|j�|S)z%Create a copy of this Context object.)r
r4r6�extendr9r:)r�ctxtrrr �copy�s
zContext.copyr3)r#r$r%r&rr?rC�has_keyrFrIrLrMrAr0rRrKrUr8r6r[rrrr r
bs$	




r
cCs,|r|dt|�|dd�|fi|��}|S)arApply the given directives to the stream.
    
    :param stream: the stream the directives should be applied to
    :param directives: the list of directives to apply
    :param ctxt: the `Context`
    :param vars: additional variables that should be available when Python
                 code is executed
    :return: the stream with the given directives applied
    rr@N)�iter)�stream�
directivesrZ�varsrrr �_apply_directivess
$racCs(|r|�|�|�|�}|r|��|S)aEvaluate the given `Expression` object.
    
    :param expr: the expression to evaluate
    :param ctxt: the `Context`
    :param vars: additional variables that should be available to the
                 expression
    :return: the result of the evaluation
    )r8�evaluater6)�exprrZr`�retvalrrr �
_eval_exprs	

recCsN|r|�|�|�i�|�|�|r%|��}|��|jd�|�dSdS)z�Execute the given `Suite` object.
    
    :param suite: the code suite to execute
    :param ctxt: the `Context`
    :param vars: additional variables that should be available to the
                 code
    rN)r8�executer6r4rU)�suiterZr`�toprrr �_exec_suite(s


�ric@seZdZdZdd�ZdS)�DirectiveFactoryMetaz#Meta class for directive factories.cCs>d|vrt|d�|d<dd�|dD�|d<t�||||�S)Nr_�_dir_by_namecSsg|]}|d�qS)r@r)rP�	directiverrr rS@sz0DirectiveFactoryMeta.__new__.<locals>.<listcomp>�
_dir_order)�dict�type�__new__)�clsr,�bases�drrr rp=szDirectiveFactoryMeta.__new__N)r#r$r%r&rprrrr rj:srjc@s&eZdZdZgZ	dd�Zdd�ZdS)rz]Base for classes that provide a set of template directives.
    
    :since: version 0.6
    cCs|j�|�S)z�Return the directive class for the given name.
        
        :param name: the directive name as used in the template
        :return: the directive class
        :see: `Directive`
        )rkr0)rr,rrr �
get_directiveQszDirectiveFactory.get_directivecCs ||jvr|j�|�St|j�S)aUReturn a key for the given directive class that should be used to
        sort it among other directives on the same `SUB` event.
        
        The default implementation simply returns the index of the directive in
        the `directives` list.
        
        :param dir_cls: the directive class
        :return: the sort key
        )rm�indexrJ)r�dir_clsrrr �get_directive_indexZs


z$DirectiveFactory.get_directive_indexN)r#r$r%r&r_rtrwrrrr rEs	rc@s�eZdZdZed�Z	ed�Z	ed�Z	ed�Z	dZ	e
jZ		d#d	d
�Z
dd�Zd
d�Zdd�Zdd�Zdd�Zedd��Zdd�Zd$dd�Zdd�Zdd�Zdd �Zd!d"�ZdS)%rz�Abstract template base class.
    
    This class implements most of the template processing model, but does not
    specify the syntax of templates.
    �EXEC�EXPR�INCLUDE�SUBN�strictTc	
Cs�|p||_||_||_||_||_|��|��d|_t|t	�s5t
|d�s5t|tj�r1t
|�}nt|�}z
|�||�|_WdStyV}zt|j|j|j|j��d}~ww)a�Initialize a template from either a string, a file-like object, or
        an already parsed markup stream.
        
        :param source: a string, file-like object, or markup stream to read the
                       template from
        :param filepath: the absolute path to the template file
        :param filename: the path to the template file relative to the search
                         path
        :param loader: the `TemplateLoader` to use for loading included
                       templates
        :param encoding: the encoding of the `source`
        :param lookup: the variable lookup mechanism; either "strict" (the
                       default), "lenient", or a custom lookup class
        :param allow_exec: whether Python code blocks in templates should be
                           allowed
        
        :note: Changed in 0.5: Added the `allow_exec` argument
        F�readN)�filepathr�loader�lookup�
allow_exec�
_init_filters�_init_loader�	_preparedr(r�hasattr�six�	text_typerr�_parse�_streamrrrrr)	r�sourcer~rr�encodingr�r��errr r�s$

��zTemplate.__init__cCs|j��}g|d<|S)N�filters)�__dict__r[�r�staterrr �__getstate__�s
zTemplate.__getstate__cCs||_|��dSr3)r�r�r�rrr �__setstate__�szTemplate.__setstate__cCsdt|�j|jfS)Nz	<%s "%s">)ror#rr-rrr r?�szTemplate.__repr__cCs|j|jg|_dSr3)�_flatten�_includer�r-rrr r��szTemplate._init_filterscCs�|jdur>ddlm}|jr0|j|jkr(tj�|j�dttj�|j���}n
tj�	|j�}nd}|tj�
|�g�|_dSdS)Nr)�TemplateLoader�.)r�genshi.template.loaderr�rr~�os�path�normpathrJ�dirname�abspath)rr��basedirrrr r��s
��zTemplate._init_loadercCs|js|��|jSr3)r��
_prepare_selfr�r-rrr r^�szTemplate.streamcCst�)a�Parse the template.
        
        The parsing stage parses the template and constructs a list of
        directives that will be executed in the render stage. The input is
        split up into literal output (text that does not depend on the context
        data) and directives or expressions.
        
        :param source: a file-like object containing the XML source of the
                       template, or an XML event stream
        :param encoding: the encoding of the `source`
        )�NotImplementedError)rr�r�rrr r��szTemplate._parsecCs(|jst|�|j|��|_d|_dSdS)NT)r�r>�_preparer�)r�inlinedrrr r��s
�zTemplate._prepare_selfc	cs��ddlm}|durt|jf�}|D]�\}}}|turbg}|d}t|ddd�d�D]\}	}
}}}|
�|||||�\}
}|
rE|�|
�q,|�||�}|rY||t	|�f|fVq|D]}|Vq[q|t
ur�|\}}
}d}t|tj
�r�t|jd	d
�s�d}z|jj||d|
p�|jd�}Wn|y�|dur��Ynw|dur�|j|vr�|�|j�|�|�|jD]}|Vq�|�|j�d
}n|�||�D]}|Vq�d
}|r�q|r�||
t	|�||��f}|||fVq|||fVqdS)z�Call the `attach` method of every directive found in the template.
        
        :param stream: the event stream of the template
        r��TemplateNotFoundNr@cSs|dS)Nrr)�xrrr �<lambda>�sz#Template._prepare.<locals>.<lambda>)rBF�auto_reloadT��relative_torq)r�r��setr~r{�sorted�attach�appendr�r>rzr(r��string_types�getattrr�load�	__class__�addr�r^�discard)rr^r�r��kindr<�posr_�	substream�_rqrH�
namespacesrl�event�href�fallback�tmpl_inlined�tmplrrr r��sx��
�
��
�
���


�
��zTemplate._preparecOs�i}|r&t|�dksJ�|d}|durtdi|��}n|}t|t�s%J�ntdi|��}|j}|jD]
}|t|�|fi|��}q3t||j�S)aApply the template to the given context data.
        
        Any keyword arguments are made available to the template as context
        data.
        
        Only one positional argument is accepted: if it is provided, it must be
        an instance of the `Context` class, and keyword arguments are ignored.
        This calling style is used for internal processing.
        
        :return: a markup event stream representing the result of applying
                 the template to the context data.
        r@rNr)rJr
r(r^r�r]r�
serializer)r�args�kwargsr`rZr^�filter_rrr �generates

zTemplate.generatecks��|j}g}|j}|j}t|�}	|D]�\}}	}
|tur\|	dr\|	\}}g}
|D](\}}t|�turIdd�|j||fi|��D�}|sDq(d�|�}|
�||f�q(||t	|
�f|
fVq|t
ur�t|	||�}|dur�t|t
j�rwt||
fVqt|t�r�t||�|
fVqt|d�r�||�t|�}n8tt
�|�|
fVq|tur�||�t|	d|	d||�}n|tur�t|	||�q||	|
fVq|s�dS|�}q)Nr@cSs,g|]}|dtur|ddur|d�qS)rr@N)r
)rPr�rrr rSNs
�z%Template._flatten.<locals>.<listcomp>r'�__iter__r)�_number_convr�r6r]r	ror>r��joinrryrer(r�r�r
rr�rr�r{rarxri)rr^rZr`�number_conv�stackr8r6r�r<r��tag�attrs�	new_attrsr,rH�values�resultrrr r�=sZ��


��zTemplate._flattenc	ks$�ddlm}|D]�}|dtur�|d\}}}t|tj�sCg}	|j||fi|��D]\}
}}|
tur8|	�|�q*d�	dd�|	D��}z!|j
j||dd|pQ|jd�}
|
j
|fi|��D]}|Vq]Wq	|y�|d	urp�|jD]
}|t|�|fi|��}qs|D]}|Vq�Yq	w|Vq	d	S)
z[Internal stream filter that performs inclusion of external
        template files.
        rr�r@r'cSsg|]}|dur|�qSr3r)rPr�rrr rS�rTz%Template._include.<locals>.<listcomp>�r�N)r�r�rzr(r�r�r�r
r�r�rr�r�r�r�r])rr^rZr`r�r�r�rqr��parts�subkind�subdata�subposr�r�rrr r�{s@��
���
���zTemplate._include)NNNNr|Tr3)r#r$r%r&rrxryrzr{r�r�r�r�rr�r�r?r�r��propertyr^r�r�r�r�r�r�rrrr ris8
�'

A>rr3)'r&�collectionsrr�r��
genshi.compatrrr�genshi.corerrrr	r
r�genshi.inputr�__all__�
__docformat__rrrrr�objectr
rarerirorj�
add_metaclassrrrxryrzr{rrrr �<module>s8
 '

#4


https://t.me/RX1948 - 2025