HEX
Server: Apache
System: Linux pdx1-shared-a1-29 6.18.39-grsec-noble+ #4 SMP Thu Jul 23 07:53:29 UTC 2026 x86_64
User: dh_bj99yp (22285841)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/genshi/template/__pycache__/base.cpython-312.pyc
�

EMab�^���dZddlmZddlZddlZddlmZmZmZddl	m
Z
mZmZm
Z
mZmZddlmZgd�ZdZGd	�d
e�ZGd�de�ZGd
�de�ZGd�de�ZGd�de�Zd�Zdd�Zdd�ZGd�de�Zej@e�Gd�de��Z!Gd�de!�Z"e"jFZ#e"jHZ$e"jJZ%e"jLZ&y)zBasic templating functionality.�)�dequeN)�
numeric_types�StringIO�BytesIO)�Attrs�Stream�StreamEventKind�START�TEXT�_ensure)�
ParseError)�Context�DirectiveFactory�Template�
TemplateError�TemplateRuntimeError�TemplateSyntaxError�BadDirectiveErrorzrestructuredtext enc��eZdZdZdd�Zy)rz?Base exception class for errors related to template processing.Nc��|�d}||_|dk7s|dk\rd|j||fz}tj||�||_||_||_y)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�messagerrrs     �6/usr/lib/python3/dist-packages/genshi/template/base.pyrzTemplateError.__init__!s^����!�H�����z�!�V�q�[�(�D�H�H�h��+G�G�G����4��)� ��
��������N���r#��__name__�
__module__�__qualname__�__doc__r�r!r rrs
��I�r!rc��eZdZdZdd�Zy)rz|Exception raised when an expression in a template causes a Python syntax
    error, or the template is not well-formed.
    Nc��t|t�r4|j�(t|�j	d|jzd�}t
j
||||�y)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�replacerrrs     r rzTemplateSyntaxError.__init__:sJ���g�{�+����0J��'�l�*�*�<�'�.�.�+H�"�M�G����t�W�h��?r!r"r$r)r!r rr5s
���@r!rc��eZdZdZdd�Zy)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.
    Nc�:�tj|d|z||�y)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�namerrs    r rzBadDirectiveError.__init__Ps!��	�$�$�T�+?�$�+F�%-�v�	7r!)Nr#r$r)r!r rrHs���	7r!rc��eZdZdZy)rzfException raised when an the evaluation of a Python expression in a
    template causes an error.
    N)r%r&r'r(r)r!r rr\s��r!rc�r�eZdZdZd�Zd�Zd�ZeZd�Zd�Z	d�Z
d�Zdd
�Zdd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zy	)rapContainer 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'
    c���t|g��_�jj�_�jj�_g�_g�_�fd�}d�fd�	}|jd|�|jd|�y)zZInitialize the template context with the given keyword arguments as
        data.
        c���|�vS)z]Return whether a variable with the specified name exists in the
            expression scope.r))r3rs �r �definedz!Context.__init__.<locals>.defined�s����4�<�r!Nc�(���j||�S)z�If a variable of the specified name is defined, return its value.
            Otherwise, return the provided default value, or ``None``.)�get)r3�defaultrs  �r �value_ofz"Context.__init__.<locals>.value_of�s����8�8�D�'�*�*r!r8r<�N)	r�frames�popleft�pop�
appendleft�push�_match_templates�
_choice_stack�
setdefault)r�datar8r<s`   r rzContext.__init__{sl����T�F�m����;�;�&�&����K�K�*�*��	� "������	 �	+�	
���	�7�+����
�H�-r!c�>�tt|j��Sr=)�repr�listr>�rs r �__repr__zContext.__repr__�s���D����%�&�&r!c�.�|j|�dduS)zuReturn whether a variable exists in any of the scopes.
        
        :param key: the name of the variable
        �N)�_find�r�keys  r �__contains__zContext.__contains__�s��
�z�z�#��q�!��-�-r!c�6�|jD]
}||vs�||=�y)zaRemove a variable from all scopes.
        
        :param key: the name of the variable
        N�r>)rrP�frames   r �__delitem__zContext.__delitem__�s%��
�[�[�	�E��e�|��#�J�	r!c�H�|j|�\}}|�t|��|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
        )rN�KeyError)rrP�valuerTs    r �__getitem__zContext.__getitem__�s)���z�z�#����u��=��3�-���r!c�4�t|j��S)z�Return the number of distinctly named variables in the context.
        
        :return: the number of variables in the context
        )�len�itemsrJs r �__len__zContext.__len__�s��
�4�:�:�<� � r!c�(�||jd|<y)z�Set a variable in the current scope.
        
        :param key: the name of the variable
        :param value: the variable value
        rNrS)rrPrXs   r �__setitem__zContext.__setitem__�s��$����A��s�r!Nc�F�|jD]}||vs�|||fcS|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
        NrS�rrPr;rTs    r rNz
Context._find�s9���[�[�	)�E��e�|��S�z�5�(�(�	)���}�r!c�>�|jD]
}||vs�||cS|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
        rSras    r r:zContext.get�s/���[�[�	"�E��e�|��S�z�!�	"��r!c�f�g}|jD]}||D�cgc]	}||vs�|��c}z
}�|Scc}w)zlReturn the name of all variables in the context.
        
        :return: a list of variable names
        rS)r�keysrTrPs    r rdzContext.keys�sA��
���[�[�	>�E��E�=�S�S��_�S�=�=�D�	>����>s�	.�.c�j�|j�D�cgc]}||j|�f��c}Scc}w)z�Return a list of ``(name, value)`` tuples for all variables in the
        context.
        
        :return: a list of variables
        )rdr:rOs  r r\z
Context.items�s+��15�	�	��<���d�h�h�s�m�$�<�<��<s�0c�@�|jdj|�y)z-Update the context from the mapping provided.rN)r>�update)r�mappings  r rgzContext.update�s�����A����g�&r!c��y)zwPush a new scope on the stack.
        
        :param data: the data dictionary to push on the context stack.
        Nr))rrFs  r rBzContext.push���r!c��y)z&Pop the top-most scope from the stack.Nr)rJs r r@zContext.pop�rjr!c�,�t�}|jj�|jj|j�|jj|j�|j
j|j
�|S)z%Create a copy of this Context object.)rr>r@�extendrCrD)r�ctxts  r �copyzContext.copy�sh��
�y�������������4�;�;�'����$�$�T�%:�%:�;����!�!�$�"4�"4�5��r!r=)r%r&r'r(rrKrQ�has_keyrUrYr]r_rNr:rdr\rgrBr@ror)r!r rrbsY���0.�,'�.��G���!�$����=�'��5�
r!rc�>�|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
    rrMN)�iter)�stream�
directivesrn�varss    r �_apply_directivesrvs/�����A��t�F�|�Z���^�T�J�T�J���Mr!c�r�|r|j|�|j|�}|r|j�|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
    )rB�evaluater@)�exprrnru�retvals    r �
_eval_exprr{s1����	�	�$��
�]�]�4�
 �F�����
��Mr!c���|r"|j|�|ji�|j|�|r?|j�}|j�|jdj	|�yy)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)rB�executer@r>rg)�suiternru�tops    r �_exec_suiter�(s[����	�	�$���	�	�"�
�	�M�M�$����h�h�j�����
����A����c�"�r!c��eZdZdZd�Zy)�DirectiveFactoryMetaz#Meta class for directive factories.c��d|vr*t|d�|d<|dD�cgc]}|d��	c}|d<tj||||�Scc}w)Nrt�_dir_by_namerM�
_dir_order)�dict�type�__new__)�clsr3�bases�d�	directives     r r�zDirectiveFactoryMeta.__new__=sT���1�� $�Q�|�_� 5�A�n��=>�|�_�M�	�y��|�M�A�l�O��|�|�C��u�a�0�0��Ns�AN)r%r&r'r(r�r)r!r r�r�:s
��-�1r!r�c�"�eZdZdZgZ	d�Zd�Zy)rz]Base for classes that provide a set of template directives.
    
    :since: version 0.6
    c�8�|jj|�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`
        )r�r:)rr3s  r �
get_directivezDirectiveFactory.get_directiveQs��� � �$�$�T�*�*r!c�~�||jvr|jj|�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
        )r��indexr[)r�dir_clss  r �get_directive_indexz$DirectiveFactory.get_directive_indexZs4���d�o�o�%��?�?�(�(��1�1��4�?�?�#�#r!N)r%r&r'r(rtr�r�r)r!r rrEs���
�J��+�$r!rc���eZdZdZed�Z	ed�Z	ed�Z	ed�Z	dZ	e
jZ		dd�Z
d�Zd	�Zd
�Zd�Zd�Zed
��Zd�Zdd�Zd�Zd�Zd�Zd�Zy)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�SUBNc��|xs||_||_||_||_||_|j�|j
�d|_t|t�s=t|d�s1t|tj�rt|�}nt|�}	|j||�|_y#t"$r;}t%|j&|j|j(|j*��d}~wwxYw)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��es	         r rzTemplate.__init__�s���(!�,�H��
� ��
�������$���������������&�&�)�'�&�&�2I��&�#�-�-�0�!�&�)�� ����	P��;�;�v�x�8�D�L���	P�%�a�e�e�T�]�]�A�H�H�a�h�h�O�O��	P�s�B5�5	C9�>6C4�4C9c�D�|jj�}g|d<|S)N�filters)�__dict__ro�r�states  r �__getstate__zTemplate.__getstate__�s#���
�
�"�"�$����i���r!c�2�||_|j�yr=)r�r�r�s  r �__setstate__zTemplate.__setstate__�s����
����r!c�N�dt|�j�d|j�d�S)N�<z "z">)r�r%rrJs r rKzTemplate.__repr__�s��"�4�j�1�1�4�=�=�A�Ar!c�>�|j|jg|_yr=)�_flatten�_includer�rJs r r�zTemplate._init_filters�s���
�
�t�}�}�5��r!c���|j��ddlm}|jr�|j|jk7r^t
jj|j�dtt
jj|j��}n,t
jj|j�}nd}|t
jj|�g�|_yy)Nr)�TemplateLoader�.)r��genshi.template.loaderr�rr��os�path�normpathr[�dirname�abspath)rr��basedirs   r r�zTemplate._init_loader�s����;�;��=��}�}��=�=�D�M�M�1� �g�g�.�.�t�}�}�=�?9�����(�(����7�A9�@9��G�!�g�g�o�o�d�m�m�<�G���(�"�'�'�/�/�'�*B�)C�D�D�K�r!c�R�|js|j�|jSr=)r��
_prepare_selfr�rJs r rszTemplate.stream�s���~�~���� ��|�|�r!c��t�)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�s   r r�zTemplate._parse�s
��"�!r!c��|js2t|j|j|��|_d|_yy)NT)r�rI�_preparer�)r�inlineds  r r�zTemplate._prepare_self�s0���~�~���
�
�d�l�l�G� D�E�D�L�!�D�N�r!c	#�K�ddlm}|�t|jf�}|D�]�\}}}|tur�g}|d}t|dd���D]4\}	}
}}}|
j
|||||�\}
}|
s�$|j|
��6|j||�}|r||t|�f|f����|D]}|�����|tu�r$|\}}
}d}t|tj�r�t|jdd	�s�d}	|jj!||d|
xs|j"�
�}|�m|j|vr||j%|j�|j'|�|j(D]}|���|j+|j�d	}n|j||�D]}|���d	}|r���|r||
t|j||��f}|||f�����|||f�����y#|$r|��Y��wxYw�w)z�Call the `attach` method of every directive found in the template.
        
        :param stream: the event stream of the template
        r��TemplateNotFoundNrMc��|dS)Nrr))�xs r �<lambda>z#Template._prepare.<locals>.<lambda>�s
��q��t�r!)rPF�auto_reloadT��relative_tor�)r�r��setr�r��sorted�attach�appendr�rIr�r-r��string_types�getattrr��load�	__class__�addr�rs�discard)rrsr�r��kindrF�posrt�	substream�_r�rX�
namespacesr��event�href�fallback�tmpl_inlined�tmpls                   r r�zTemplate._prepare�s:����
	<��?��4�=�=�*�+�G�%�6	*�O�D�$���s�{��
� ��G�	�6<��Q��^�75�5�2�A�s�E�:�s�+.�:�:�d�I�u�6@�#�,G�(�I�y� �"�)�)�)�4�5�!�M�M�)�W�=�	����T�)�_� =�s�B�B�!*�$��#��$��7�?�*.�'�D�#�x�#(�L�"�4��)9�)9�:� '����]�D� I� $��&�#'�;�;�#3�#3�D�c�!�f�8;�8M�t�~�~�$4�$O�D�
 �+�#�}�}�G�;� '���D�M�M� :� $� 2� 2�7� ;�-1�[�[�!0�E�*/�K�!0� '����
�
� >�/3��)-���x��)I�,��&+��,�+/�L�#� ��#�S�$� �M�M�(�G�<�+>� >����c�/�)���c�/�)�m6	*��> 0�&�'�/� %� 0�&�s2�A,G;�/B
G;�:/G-�)CG;�-G8�5G;�7G8�8G;c��i}|r7t|�dk(sJ�|d}|�tdi|��}n|}t|t�s
J�tdi|��}|j}|jD]}|t|�|fi|��}�t
||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.
        rMrr))r[rr-rsr�rrr�
serializer)r�args�kwargsrurnrs�filter_s       r �generatezTemplate.generates�������t�9��>�!�>���7�D��|��(��(�����d�G�,�,�,��$�V�$�D������|�|�	9�G��T�&�\�4�8�4�8�F�	9��f�d�o�o�.�.r!c+�K�|j}g}|j}|j}t|�}	|D�]�\}}	}
|tur�|	dr�|	\}}g}
|D]q\}}t|�turH|j||fi|��D�cgc]}|dtur
|d�|d��}}|s�Ndj|�}|
j||f��s||t|
�f|
f����|tur�t|	||�}|���t|tj�rt||
f����t|t �rt||�|
f����t#|d�r||�t%|�}nqttj&|�|
f����G|t(ur||�t+|	d|	d||�}n+|t,urt/|	||����||	|
f�����|sy|�}���cc}w�w)NrMrr,�__iter__)�_number_convr�r@rrr
r�rIr�r�joinrr�r{r-r�r�rr�rr�r�rvr�r�)rrsrnru�number_conv�stackrBr@r�rFr��tag�attrs�	new_attrsr3rXr��values�results                   r r�zTemplate._flatten=s������'�'�����|�|���i�i���f����#)�4
���d�C��5�=�T�!�W�"&�J�C�� "�I�',�	8���e���;�$�.�-:�T�]�]�5�$�-O�$�-O�&�$)�#(��8�t�#3��a��8L�',�A�h�&�F�&�$*� (�$&�G�G�F�O�E�!�(�(�$���7�	8���e�I�&6� 7��<�<��T�\�'��d�D�9�F��)�&�f�c�.>�.>�?�"&���"3�3�'��
�>�"&��F�(;�S�"@�@�$�V�Z�8� ��L�%,�V�_�F�!�"&��
�
�f�(=�s�"B�B��S�[���L�.�t�A�w��Q���t�L�F���T�\���d�D�1���c�/�)�_4
�d�����k��&�s�BG�G�AG�4C"Gc+�fK�ddlm}|D]�}|dtur�|d\}}}t|tj
�s[g}	|j||fi|��D] \}
}}|
tus�|	j|��"dj|	D�
cgc]}
|
��|
��	c}
�}	|jj||dd|xs|j��}|j|fi|��D]}|�����|����ycc}
w#|$r6|��|jD]}|t|�|fi|��}�|D]}|���Y��"wxYw�w)z[Internal stream filter that performs inclusion of external
        template files.
        rr�rMr,N�r�)r�r�r�r-r�r�r�rr�r�r�r�r�r�r�rr)rrsrnrur�r�r�r�r��parts�subkind�subdata�subposr�r�r�s                r r�zTemplate._include{sk����	<��	�E��Q�x�7�"�&+�A�h�#��c�8�!�$��(8�(8�9��E�4A�D�M�M�$��5J�DH�5J�2�0���&�"�d�?�!�L�L��1�2��7�7�u�#F�!��
�A�#F�G�D�$��;�;�+�+�D�e�A�h�q�k�03�0E�t�~�~�,�G�D�!.����t�!<�t�!<�$��#��$���/	��$G��(�$��'��#'�<�<�I��#*�4��>�4�#H�4�#H��I�!)�$��#��$�$�sC�AD1�""D1�C.
�C.
�D1�AC3�&
D1�37D.�*D1�-D.�.D1)NNNN�strictTr=)r%r&r'r(r	r�r�r�r�r�r�r�r�rr�r�rKr�r��propertyrsr�r�r�r�r�r�r)r!r rris�����6�"�D�H��6�"�D�=��i�(�G�K�
�%�
 �C���J��=�=�L�DH�<@�%P�N�
�B�6�E�����
"�"�
?*�B/�<<�|r!rr=)'r(�collectionsrr�r��
genshi.compatrrr�genshi.corerrr	r
rr�genshi.inputr
�__all__�
__docformat__rrrrr�objectrrvr{r�r�r��
add_metaclassrrr�r�r�r�r)r!r �<module>rs���&��	�
�:�:�L�L�#�O��%�
��I��.@�-�@�&7�+�7�(�=��c�f�c�L��"#�$1�4�1�����'�(� $�v� $�)� $�Fo��o�d	�}�}���}�}��
�
�
���l�l�r!