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__/eval.cpython-310.pyc
o

!�bYQ�@s�dZddlmZddlmZddlZddlmZddlm	Z	ddl
mZmZm
Z
ddlmZdd	lmZdd
lmZmZmZmZmZmZmZgd�ZdZGd
d�de�ZGdd�de�ZGdd�de�Z e�Z!Gdd�de�Z"Gdd�de�Z#Gdd�de�Z$Gdd�de$�Z%Gdd�de$�Z&d+dd�Z'	 	d,d!d"�Z(d#d$�Z)ej*�+�Z,e,�-e	e#d%��e.gd&��Z/Gd'd(�d(e�Z0Gd)d*�d*e0�Z1dS)-z4Support for "safe" evaluation of Python expressions.�)�dedent)�CodeTypeN)�builtins)�Markup)�ASTTransformer�ASTCodeGenerator�parse)�TemplateRuntimeError)�flatten)�ast�
_ast_Constant�get_code_params�build_code_chunk�isstring�
IS_PYTHON2�_ast_Str)�Code�
Expression�Suite�
LenientLookup�StrictLookup�	Undefined�UndefinedErrorzrestructuredtext enc@sVeZdZdZgd�Z		ddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)rz=Abstract base class for the `Expression` and `Suite` classes.)�source�coder�_globalsN����strictcCs�t|tj�r||_t||jd�}n$t|tj�sJd|��d|_|jdkr-t��}||_	nt�
�}|g|_	||_t||j|j|||d�|_
|durLt}n
t|tj�rYttd�|}|j|_dS)aCreate the code object, either from a string, or from an AST node.
        
        :param source: either a string containing the source code, or an AST
                       node
        :param filename: the (preferably absolute) name of the file containing
                         the code
        :param lineno: the number of the line on which the code was found
        :param lookup: the lookup class that defines how variables are looked
                       up in the context; can be either "strict" (the default),
                       "lenient", or a custom lookup class
        :param xform: the AST transformer that should be applied to the code;
                      if `None`, the appropriate transformation is chosen
                      depending on the mode
        )�modez'Expected string or AST node, but got %r�?�eval)r�filename�lineno�xformN)�lenientr)�
isinstance�six�string_typesr�_parser�_ast�ASTr�body�Moduler�_compilerrr�globalsr)�selfrr!r"�lookupr#�node�r2�6/usr/lib/python3/dist-packages/genshi/template/eval.py�__init__(s*�
�z
Code.__init__cCs@t|jd�r|jj}n|jj}|j|j|d�}t|j�|d<|S)N�__self__)rrr0r)�hasattrrr5�im_selfrrr
r)r/�	lookup_fn�stater2r2r3�__getstate__Os
zCode.__getstate__cCs:|d|_|d|_tdg|d�R�|_|dj|_dS)Nrrrrr0)rrrrr.r)r/r9r2r2r3�__setstate__Ys

zCode.__setstate__cCst|�t|�ko
|j|jkS�N)�typer�r/�otherr2r2r3�__eq___szCode.__eq__cCs
t|j�Sr<)�hashr�r/r2r2r3�__hash__b�
z
Code.__hash__cCs
||kSr<r2r>r2r2r3�__ne__erDzCode.__ne__cC�dt|�j|jfS)Nz%s(%r))r=�__name__rrBr2r2r3�__repr__h�z
Code.__repr__)NrrN)rG�
__module__�__qualname__�__doc__�	__slots__r4r:r;r@rCrErHr2r2r2r3r$s
�'
rc@� eZdZdZgZdZdd�ZdS)ra�Evaluates Python expressions used in templates.

    >>> data = dict(test='Foo', items=[1, 2, 3], dict={'some': 'thing'})
    >>> Expression('test').evaluate(data)
    'Foo'

    >>> Expression('items[0]').evaluate(data)
    1
    >>> Expression('items[-1]').evaluate(data)
    3
    >>> Expression('dict["some"]').evaluate(data)
    'thing'
    
    Similar to e.g. Javascript, expressions in templates can use the dot
    notation for attribute access to access items in mappings:
    
    >>> Expression('dict.some').evaluate(data)
    'thing'
    
    This also works the other way around: item access can be used to access
    any object attribute:
    
    >>> class MyClass(object):
    ...     myattr = 'Bar'
    >>> data = dict(mine=MyClass(), key='myattr')
    >>> Expression('mine.myattr').evaluate(data)
    'Bar'
    >>> Expression('mine["myattr"]').evaluate(data)
    'Bar'
    >>> Expression('mine[key]').evaluate(data)
    'Bar'
    
    All of the standard Python operators are available to template expressions.
    Built-in functions such as ``len()`` are also available in template
    expressions:
    
    >>> data = dict(items=[1, 2, 3])
    >>> Expression('len(items)').evaluate(data)
    3
    r cCs d}|�|�}t|j|d|i�S)z�Evaluate the expression against the given data dictionary.
        
        :param data: a mapping containing the data to evaluate against
        :return: the result of the evaluation
        �before_and_this�__data__)rr r�r/�data�__traceback_hide__rr2r2r3�evaluate�s
zExpression.evaluateN)rGrJrKrLrMrrTr2r2r2r3rls
(rc@rN)rz�Executes Python statements used in templates.

    >>> data = dict(test='Foo', items=[1, 2, 3], dict={'some': 'thing'})
    >>> Suite("foo = dict['some']").execute(data)
    >>> data['foo']
    'thing'
    �execcCs"d}|�|�}t�|j||�dS)z�Execute the suite in the given data dictionary.
        
        :param data: a mapping containing the data to execute in
        rON)rr&�exec_rrQr2r2r3�execute�s
z
Suite.executeN)rGrJrKrLrMrrWr2r2r2r3r�s
rc@seZdZdZefdd�ZdS)rz�Exception thrown when a template expression attempts to access a variable
    not defined in the context.
    
    :see: `LenientLookup`, `StrictLookup`
    cCs2|tur
dt|�|f}nd|}t�||�dS)Nz%s has no member named "%s"z"%s" not defined)�	UNDEFINED�reprr	r4)r/�name�owner�messager2r2r3r4�szUndefinedError.__init__N)rGrJrKrLrXr4r2r2r2r3r�src@s`eZdZdZddgZefdd�Zdd�Zdd	�ZeZ	d
d�Z
dd
�Zdd�ZeZ
ZZdZdS)ra�Represents a reference to an undefined variable.
    
    Unlike the Python runtime, template expressions can refer to an undefined
    variable without causing a `NameError` to be raised. The result will be an
    instance of the `Undefined` class, which is treated the same as ``False`` in
    conditions, but raise an exception on any other operation:
    
    >>> foo = Undefined('foo')
    >>> bool(foo)
    False
    >>> list(foo)
    []
    >>> print(foo)
    undefined
    
    However, calling an undefined variable, or trying to access an attribute
    of that variable, will raise an exception that includes the name used to
    reference that undefined variable.
    
    >>> try:
    ...     foo('bar')
    ... except UndefinedError as e:
    ...     print(e.msg)
    "foo" not defined

    >>> try:
    ...     foo.bar
    ... except UndefinedError as e:
    ...     print(e.msg)
    "foo" not defined
    
    :see: `LenientLookup`
    �_name�_ownercCs||_||_dS)z�Initialize the object.
        
        :param name: the name of the reference
        :param owner: the owning object, if the variable is accessed as a member
        N)r]r^)r/rZr[r2r2r3r4�s
zUndefined.__init__cCstg�Sr<)�iterrBr2r2r3�__iter__�szUndefined.__iter__cC�dS)NFr2rBr2r2r3�__bool__��zUndefined.__bool__cCrF)Nz<%s %r>)r=rGr]rBr2r2r3rH�rIzUndefined.__repr__cCra)N�	undefinedr2rBr2r2r3�__str__rczUndefined.__str__cOsd}t|j|j��)zRaise an `UndefinedError`.T)rr]r^)r/�args�kwargsrSr2r2r3�_dieszUndefined._dieN)rGrJrKrLrMrXr4r`rb�__nonzero__rHrerh�__call__�__getattr__�__getitem__�__length_hint__r2r2r2r3r�s!	rc@sPeZdZdZedd��Zedd��Zedd��Zedd	��Zee	fd
d��Z
dS)
�
LookupBasez8Abstract base class for variable lookup implementations.cCs||j|j|jtd�S)znConstruct the globals dictionary to use as the execution context for
        the expression or suite.
        )rP�_lookup_name�_lookup_attr�_lookup_itemr)�lookup_name�lookup_attr�lookup_itemr)�clsrRr2r2r3r.s�zLookupBase.globalscCs:d}|�|t�}|turt�||�}|tur|�|�}|S)NT)�getrX�BUILTINSrd)rurRrZrS�valr2r2r3rrs
zLookupBase.lookup_namecCsld}zt||�}W|Sty5t|j|�r�z||}WY|Sttfy4|j||d�}YY|Sww)NT�r[)�getattr�AttributeErrorr6�	__class__�KeyError�	TypeErrorrd)ru�obj�keyrSrxr2r2r3rs)s	����zLookupBase.lookup_attrcCs�d}t|�dkr|d}z||WSttttfyA}z t|tj�r<t||t	�}|t	ur4|j
||d�}|WYd}~S�d}~ww)NT�rry)�lenr{r}�
IndexErrorr~r%r&r'rzrXrd)rurr�rS�erxr2r2r3rt8s
��zLookupBase.lookup_itemcCst�)z�Can be overridden by subclasses to specify behavior when undefined
        variables are accessed.
        
        :param key: the name of the variable
        :param owner: the owning object, if the variable is accessed as a member
        )�NotImplementedError)rur�r[r2r2r3rdGszLookupBase.undefinedN)rGrJrKrL�classmethodr.rrrsrtrXrdr2r2r2r3rns

	

rnc@� eZdZdZeefdd��ZdS)ra�Default variable lookup mechanism for expressions.
    
    When an undefined variable is referenced using this lookup style, the
    reference evaluates to an instance of the `Undefined` class:
    
    >>> expr = Expression('nothing', lookup='lenient')
    >>> undef = expr.evaluate({})
    >>> undef
    <Undefined 'nothing'>
    
    The same will happen when a non-existing attribute or item is accessed on
    an existing object:
    
    >>> expr = Expression('something.nil', lookup='lenient')
    >>> expr.evaluate({'something': dict()})
    <Undefined 'nil'>
    
    See the documentation of the `Undefined` class for details on the behavior
    of such objects.
    
    :see: `StrictLookup`
    cCsd}t||d�S)zReturn an ``Undefined`` object.Try)r�rur�r[rSr2r2r3rdj�zLenientLookup.undefinedN�rGrJrKrLr�rXrdr2r2r2r3rR�rc@r�)ra�Strict variable lookup mechanism for expressions.
    
    Referencing an undefined variable using this lookup style will immediately
    raise an ``UndefinedError``:
    
    >>> expr = Expression('nothing', lookup='strict')
    >>> try:
    ...     expr.evaluate({})
    ... except UndefinedError as e:
    ...     print(e.msg)
    "nothing" not defined
    
    The same happens when a non-existing attribute or item is accessed on an
    existing object:
    
    >>> expr = Expression('something.nil', lookup='strict')
    >>> try:
    ...     expr.evaluate({'something': dict()})
    ... except UndefinedError as e:
    ...     print(e.msg)
    {} has no member named "nil"
    cCsd}t||d��)z(Raise an ``UndefinedError`` immediately.Try)rr�r2r2r3rd�r�zStrictLookup.undefinedNr�r2r2r2r3rqr�rr cCs�|��}|dkrDdd�|��D�}|rD|d}td�|dd�����}|���d�r=|d��s=d�dd�|��D��}d�||g�}t|tj	�rQd	|�
d
�}t||�S)NrUcSsg|]}|���qSr2)�
expandtabs��.0�liner2r2r3�
<listcomp>��z_parse.<locals>.<listcomp>r�
r��:cSsg|]}d|�qS)z    %sr2r�r2r2r3r��r�u�utf-8)�strip�
splitlinesr�join�rstrip�endswith�isspacer%r&�	text_type�encoder)rr�lines�first�restr2r2r3r(�s
r(rcCs�|sd}trt|tj�r|�dd�}nt|tj�s|�dd�}|dkr%d}|dur1dti�|t�}|��	|�}|dkrBd|p?d}n|�
�}|sKd	}	n|d}	t|�dkrY|	d
7}	d|	}t|�j
}
t|
||�}zt||||�WSty{|YSw)Nz<string>r��replacerr�r z<Expression %r>r�z ...z
<Suite %r>)rr%r&r�r��decode�ExpressionASTTransformerrv�TemplateASTTransformer�visitr�r�rr�compiler�RuntimeError)r1rrr!r"r#�treerZr��extract�
new_sourcerr2r2r3r-�s@���
�r-cOsV|�}t|j|�D]\}}||vrtd��t|||�q	|D]
\}}t|||�q|S)Nz!Field set both in args and kwargs)�zip�_fields�
ValueError�setattr)�class_rfrg�ret�attr�valuer2r2r3�_new�sr�)rr)�False�True�None�NotImplemented�Ellipsisc@steZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZeZ
dd�Zdd�Zdd�ZdS)r��pConcrete AST transformer that implements the AST transformations needed
    for code embedded in templates.
    cCstg|_dSr<)�	CONSTANTS�localsrBr2r2r3r4�szTemplateASTTransformer.__init__cCs�tst|tj�r|�|j�dSt|�r|�|�dSt|tj�r)|�|j�dSt|tj�r:|�|j	p6|j
�dSt|tj�rL|jD]
}|�
||�qCdSdSr<)rr%r)�arg�addr�Name�id�alias�asnamerZ�Tuple�elts�_process)r/�namesr1�eltr2r2r3r��s
�zTemplateASTTransformer._processcCs�t�}t|d�r?|jD]}|�||�qt|d�r%|jD]}|�||�qt|d�r1|�||j�t|d�r=|�||j�|St|d�rP|jD]}|�||�qG|S)Nrf�
kwonlyargs�vararg�kwargr�)�setr6rfr�r�r�r�r�)r/r1r�r�r�r2r2r3�_extract_names�s 






�
z%TemplateASTTransformer._extract_namescCsJt|jtj�s#z	|j�d�W|Sty"tt|j�d��YSw|S)N�asciir�)r%�sr&r�r�r�r�r�r/r1r2r2r3�	visit_Strs��z TemplateASTTransformer.visit_StrcCsTt|j�dkr|jd�|j�|j�t��zt�||�W|j��S|j��w�Nr�r)	r�r�r�rZ�appendr�r�visit_ClassDef�popr�r2r2r3r�sz%TemplateASTTransformer.visit_ClassDefcCs0t|j�dkr|jd�|�|��t�||�Sr�)r�r��updater�r�visit_Importr�r2r2r3r�sz#TemplateASTTransformer.visit_ImportcCsJdd�|jD�dgkr
|St|j�dkr|jd�|�|��t�||�S)NcSsg|]}|j�qSr2)rZ)r��ar2r2r3r�sz;TemplateASTTransformer.visit_ImportFrom.<locals>.<listcomp>�*r�r)r�r�r�r�r�r�visit_ImportFromr�r2r2r3r�s
z'TemplateASTTransformer.visit_ImportFromcCsZt|j�dkr|jd�|j�|j�|�|j��zt�||�W|j�	�S|j�	�wr�)
r�r�r�rZr�r�rfr�visit_FunctionDefr�r�r2r2r3r�sz(TemplateASTTransformer.visit_FunctionDefcs�g}|jD]&}�j�t��ttj��|j���|j	��fdd�|j
D��}|�|�qt|j��|j�|�}�jt
|j�d�=|S)Ncsg|]}��|��qSr2)r�)r��if_rBr2r3r�/sz=TemplateASTTransformer.visit_GeneratorExp.<locals>.<listcomp>)�
generatorsr�r�r�r�r)�
comprehensionr��targetr_�ifsr|r�r�)r/r1�gens�	generator�genr�r2rBr3�visit_GeneratorExp(s

�z)TemplateASTTransformer.visit_GeneratorExpcCs:|j�|�|j��zt�||�W|j��S|j��wr<)r�r�r�rfr�visit_Lambdar�r�r2r2r3r�;sz#TemplateASTTransformer.visit_LambdacCs|�|j�|_|Sr<)r�r�r�r2r2r3�
visit_StarredCsz$TemplateASTTransformer.visit_StarredcCs�t|jtj�r3|jt|j�vr3ttjdt���}ttjdt���}tt	|j�}ttj
|||gg�}|St|jtj�rJt|j�dkrJ|jd�
|j�|S)NrorPr�r)r%�ctxr)�Loadr�r
r�r�r�r�Call�Storer�r�)r/r1rZ�namearg�strargr2r2r3�
visit_NameGs�z!TemplateASTTransformer.visit_NameN)rGrJrKrLr4r�r�r�r�r�r�r�r��visit_ListCompr�r�r�r2r2r2r3r��s
	r�c@s eZdZdZdd�Zdd�ZdS)r�r�cCsTt|jtj�s
t�||�Sttjdt���}|�|j	�tt
|j�g}ttj||g�S)Nrp)
r%r�r)r�r�visit_Attributer�r�r�r�rr�r�)r/r1�funcrfr2r2r3r�]s
z(ExpressionASTTransformer.visit_AttributecCs�t|jtj�rt|jtjttjtjf�st	�
||�St|jtjtjf�r(|j}n|jj}ttjdt���}|�
|j�ttj|�
|�ft���g}ttj||g�S)Nrq)r%r�r)r��slice�Indexrr�r�r�visit_Subscriptr�r�r�r�)r/r1�slice_valuer�rfr2r2r3r�es�
�z(ExpressionASTTransformer.visit_SubscriptN)rGrJrKrLr�r�r2r2r2r3r�Xsr�)r )Nr NrN)2rL�textwrapr�typesrr&�	six.movesr�genshi.corer�genshi.template.astutilrrr�genshi.template.baser	�genshi.utilr
�
genshi.compatrr)rr
rrrr�__all__�
__docformat__�objectrrrrXrrrnrrr(r-r��__dict__�copyrwr��	frozensetr�r�r�r2r2r2r3�<module>s>
$H7FC

�+
~

https://t.me/RX1948 - 2025