ok

Mini Shell

Direktori : /opt/cloudlinux/venv/lib64/python3.11/site-packages/mako/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/mako/__pycache__/template.cpython-311.pyc

�

�܋f2]��(�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddl	mZddl	mZddl	m
Z
ddl	mZddl	mZdd	lmZGd
�d��ZGd�d
e��ZGd�de��ZGd�d��Zd�Zd�Zd�Zd�Zd�ZdS)z�Provides the Template class, a facade for parsing, generating and executing
template strings, as well as template runtime operations.�N)�cache)�codegen)�compat)�
exceptions)�runtime)�util)�Lexerc�N�eZdZdZeZ																											dd�Zejd	���Z	d
�Z
d�Zed���Z
ed
���Zejd���Zed���Zed���Zed���Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zed���ZdS)�Templatea|Represents a compiled template.

    :class:`.Template` includes a reference to the original
    template source (via the :attr:`.source` attribute)
    as well as the source code of the
    generated Python module (i.e. the :attr:`.code` attribute),
    as well as a reference to an actual Python module.

    :class:`.Template` is constructed using either a literal string
    representing the template text, or a filename representing a filesystem
    path to a source file.

    :param text: textual template source.  This argument is mutually
     exclusive versus the ``filename`` parameter.

    :param filename: filename of the source template.  This argument is
     mutually exclusive versus the ``text`` parameter.

    :param buffer_filters: string list of filters to be applied
     to the output of ``%def``\ s which are buffered, cached, or otherwise
     filtered, after all filters
     defined with the ``%def`` itself have been applied. Allows the
     creation of default expression filters that let the output
     of return-valued ``%def``\ s "opt out" of that filtering via
     passing special attributes or objects.

    :param cache_args: Dictionary of cache configuration arguments that
     will be passed to the :class:`.CacheImpl`.   See :ref:`caching_toplevel`.

    :param cache_dir:

     .. deprecated:: 0.6
        Use the ``'dir'`` argument in the ``cache_args`` dictionary.
        See :ref:`caching_toplevel`.

    :param cache_enabled: Boolean flag which enables caching of this
     template.  See :ref:`caching_toplevel`.

    :param cache_impl: String name of a :class:`.CacheImpl` caching
     implementation to use.   Defaults to ``'beaker'``.

    :param cache_type:

     .. deprecated:: 0.6
        Use the ``'type'`` argument in the ``cache_args`` dictionary.
        See :ref:`caching_toplevel`.

    :param cache_url:

     .. deprecated:: 0.6
        Use the ``'url'`` argument in the ``cache_args`` dictionary.
        See :ref:`caching_toplevel`.

    :param default_filters: List of string filter names that will
     be applied to all expressions.  See :ref:`filtering_default_filters`.

    :param enable_loop: When ``True``, enable the ``loop`` context variable.
     This can be set to ``False`` to support templates that may
     be making usage of the name "``loop``".   Individual templates can
     re-enable the "loop" context by placing the directive
     ``enable_loop="True"`` inside the ``<%page>`` tag -- see
     :ref:`migrating_loop`.

    :param encoding_errors: Error parameter passed to ``encode()`` when
     string encoding is performed. See :ref:`usage_unicode`.

    :param error_handler: Python callable which is called whenever
     compile or runtime exceptions occur. The callable is passed
     the current context as well as the exception. If the
     callable returns ``True``, the exception is considered to
     be handled, else it is re-raised after the function
     completes. Is used to provide custom error-rendering
     functions.

     .. seealso::

        :paramref:`.Template.include_error_handler` - include-specific
        error handler function

    :param format_exceptions: if ``True``, exceptions which occur during
     the render phase of this template will be caught and
     formatted into an HTML error page, which then becomes the
     rendered result of the :meth:`.render` call. Otherwise,
     runtime exceptions are propagated outwards.

    :param imports: String list of Python statements, typically individual
     "import" lines, which will be placed into the module level
     preamble of all generated Python modules. See the example
     in :ref:`filtering_default_filters`.

    :param future_imports: String list of names to import from `__future__`.
     These will be concatenated into a comma-separated string and inserted
     into the beginning of the template, e.g. ``futures_imports=['FOO',
     'BAR']`` results in ``from __future__ import FOO, BAR``.  If you're
     interested in using features like the new division operator, you must
     use future_imports to convey that to the renderer, as otherwise the
     import will not appear as the first executed statement in the generated
     code and will therefore not have the desired effect.

    :param include_error_handler: An error handler that runs when this template
     is included within another one via the ``<%include>`` tag, and raises an
     error.  Compare to the :paramref:`.Template.error_handler` option.

     .. versionadded:: 1.0.6

     .. seealso::

        :paramref:`.Template.error_handler` - top-level error handler function

    :param input_encoding: Encoding of the template's source code.  Can
     be used in lieu of the coding comment. See
     :ref:`usage_unicode` as well as :ref:`unicode_toplevel` for
     details on source encoding.

    :param lookup: a :class:`.TemplateLookup` instance that will be used
     for all file lookups via the ``<%namespace>``,
     ``<%include>``, and ``<%inherit>`` tags. See
     :ref:`usage_templatelookup`.

    :param module_directory: Filesystem location where generated
     Python module files will be placed.

    :param module_filename: Overrides the filename of the generated
     Python module file. For advanced usage only.

    :param module_writer: A callable which overrides how the Python
     module is written entirely.  The callable is passed the
     encoded source content of the module and the destination
     path to be written to.   The default behavior of module writing
     uses a tempfile in conjunction with a file move in order
     to make the operation atomic.   So a user-defined module
     writing function that mimics the default behavior would be:

     .. sourcecode:: python

         import tempfile
         import os
         import shutil

         def module_writer(source, outputpath):
             (dest, name) = \\
                 tempfile.mkstemp(
                     dir=os.path.dirname(outputpath)
                 )

             os.write(dest, source)
             os.close(dest)
             shutil.move(name, outputpath)

         from mako.template import Template
         mytemplate = Template(
                         filename="index.html",
                         module_directory="/path/to/modules",
                         module_writer=module_writer
                     )

     The function is provided for unusual configurations where
     certain platform-specific permissions or other special
     steps are needed.

    :param output_encoding: The encoding to use when :meth:`.render`
     is called.
     See :ref:`usage_unicode` as well as :ref:`unicode_toplevel`.

    :param preprocessor: Python callable which will be passed
     the full template source before it is parsed. The return
     result of the callable will be used as the template source
     code.

    :param lexer_cls: A :class:`.Lexer` class used to parse
     the template.   The :class:`.Lexer` class is used by
     default.

     .. versionadded:: 0.7.4

    :param strict_undefined: Replaces the automatic usage of
     ``UNDEFINED`` for any undeclared variables not located in
     the :class:`.Context` with an immediate raise of
     ``NameError``. The advantage is immediate reporting of
     missing variables which include the name.

     .. versionadded:: 0.3.6

    :param uri: string URI or other identifier for this template.
     If not provided, the ``uri`` is generated from the filesystem
     path, or from the in-memory identity of a non-file-based
     template. The primary usage of the ``uri`` is to provide a key
     within :class:`.TemplateLookup`, as well as to generate the
     file path of the generated Python module file, if
     ``module_directory`` is specified.

    NF�strict�beakerT�c	���|r#tjdd|��|_||_n�|r�tjdd|��|_tj�|��\}}tj�|���tjj	d��}||_n0dtt|����z|_|j|_|j}|�d��r
|dd�}tj�|��}|�d��rtjd|jz���||_||_||_||_||_||_|�	dg|_n||_||_||_||_||_|�||_|�8t7|||��\}} ||_||_t=| d|||||��n�|�~|�|}nb|	�^tj�tj� tj�|	��|d	z����}nd}|�!||��} ntj"d
���| |_#||_$|j#j%|_&||_'||_(||_)||_*|	|_+|�,|||
|
||��dS)N�\W�_�/zmemory:�z..zNTemplate uri "%s" is invalid - it cannot be relative outside of the root path.�strz.pyz"Template requires text or filename)-�re�sub�	module_id�uri�os�path�
splitdrive�normpath�replace�sep�hex�id�
startswithr�TemplateLookupException�input_encoding�output_encoding�encoding_errors�enable_loop�strict_undefined�
module_writer�default_filters�buffer_filters�imports�future_imports�preprocessor�	lexer_cls�
_compile_text�_code�_source�
ModuleInfo�abspath�join�_compile_from_file�RuntimeException�module�filename�render_body�	callable_�format_exceptions�
error_handler�include_error_handler�lookup�module_directory�_setup_cache_args)!�self�textr8rr;r<r>r$r%r?�
cache_args�
cache_impl�
cache_enabled�
cache_type�	cache_dir�	cache_url�module_filenamer#r(r)r*r'r+r,r&r-r.r=�driver�u_norm�coder7s!                                 �D/opt/cloudlinux/venv/lib64/python3.11/site-packages/mako/template.py�__init__zTemplate.__init__�s���<�
	&��V�E�3��4�4�D�N��D�H�H�
�	&��V�E�3��9�9�D�N��'�,�,�X�6�6�K�E�4��7�#�#�D�)�)�1�1�"�'�+�s�C�C�D��D�H�H�&��R��X�X���6�D�N��~�D�H�������S�!�!�	 ��A�B�B�Z�F���!�!�&�)�)�����T�"�"�	��4�$�&*�h�/���
�-���.���.���&��� 0���*����"�$)�7�D� � �#2�D� �,������,���(���� �&�D�N���*�4��x�@�@�N�T�6��D�J��D�L��v�t�T�8�T�4��E�E�E�E�
�
!��*�&���!�-��w����G�L�L���(�(�)9�:�:�F�U�N����������,�,�T�8�<�<�F�F��-�4���
���� ��
���0���!2���*���%:��"���� 0������������
	
�	
�	
�	
�	
�c�h�|jrtjStj�dg��S)N�loop)r&r�RESERVED_NAMES�
difference�rAs rM�reserved_nameszTemplate.reserved_namesVs/����	?��)�)��)�4�4�f�X�>�>�>rOc��||_||_|pi|_|r
||jd<|r
||jd<|r||jd<dSdS)N�type�dir�url)rDrErC)rArDrErCrFrGrHs       rMr@zTemplate._setup_cache_args]sk��%���*���$�*�����	1�&0�D�O�F�#��	/�%.�D�O�E�"��	/�%.�D�O�E�"�"�"�	/�	/rOc	�H�|��Stjtj�|����tj|��t
j}tj�|��r(tj|��t
j|kr,tj|��}t|||||j
��tj|j
|��}|jtjkrFtj|��}t|||||j
��tj|j
|��}t#||||ddd��nKtj|��}t%|||��\}}d|_||_t#|d|||dd��|S�N)r�verify_directoryrr�dirname�stat�ST_MTIME�exists�	read_file�_compile_module_filer(r�load_moduler�
_magic_numberr�MAGIC_NUMBERr2r/r1r0)rArr8�	filemtime�datar7rLs       rMr5zTemplate._compile_from_fileqsx�����!�"�'�/�/�$�"7�"7�8�8�8����)�)�$�-�8�I��G�N�N�4�(�(�
��7�4�=�=���/�)�;�;��~�h�/�/��$��$��$��0B�����'����=�=�F��#�w�';�;�;��~�h�/�/��$��$��$��0B���� �+�D�N�D�A�A���v�t�T�8�T�4��F�F�F�F��>�(�+�+�D�(��t�X�>�>�L�D�&��D�L��D�J��v�t�T�8�T�4��F�F�F��
rOc�4�t|j��jS)z<Return the template source code for this :class:`.Template`.)�_get_module_info_from_callabler:�sourcerTs rMrjzTemplate.source�s��.�d�n�=�=�D�DrOc�4�t|j��jS)z:Return the module source code for this :class:`.Template`.)rir:rLrTs rMrLz
Template.code�s��.�d�n�=�=�B�BrOc�*�tj|��Sr[)r�CacherTs rMrzTemplate.cache�s���{�4� � � rOc��|jdS)NrX�rCrTs rMrGzTemplate.cache_dir������u�%�%rOc��|jdS)NrYrorTs rMrHzTemplate.cache_url�rprOc��|jdS)NrWrorTs rMrFzTemplate.cache_type�s����v�&�&rOc�:�tj||j||��S)a�Render the output of this template as a string.

        If the template specifies an output encoding, the string
        will be encoded accordingly, else the output is raw (raw
        output uses `StringIO` and can't handle multibyte
        characters). A :class:`.Context` object is created corresponding
        to the given data. Arguments that are explicitly declared
        by this template's internal rendering method are also
        pulled from the given ``*args``, ``**data`` members.

        �r�_renderr:�rA�argsrgs   rM�renderzTemplate.render�s����t�T�^�T�4�@�@�@rOc�>�tj||j||d���S)z7Render the output of this template as a unicode object.T)�
as_unicodertrvs   rM�render_unicodezTemplate.render_unicode�s*�����$�.�$���
�
�
�	
rOc��t|dd���|�|��tj||j|g|�Ri|��dS)zvRender this :class:`.Template` with the given context.

        The data is written to the context's buffer.

        �_with_templateN)�getattr�_set_with_templater�_render_contextr:)rA�contextrw�kwargss    rM�render_contextzTemplate.render_context�sX���7�,�d�3�3�;��&�&�t�,�,�,����d�n�g�O��O�O�O��O�O�O�O�OrOc�2�t|jd|z��S�N�	render_%s)�hasattrr7�rA�names  rM�has_defzTemplate.has_def�����t�{�K�$�$6�7�7�7rOc�N�t|t|jd|z����S)z9Return a def of this template as a :class:`.DefTemplate`.r�)�DefTemplater~r7r�s  rM�get_defzTemplate.get_def�s%���4����k�D�6H�!I�!I�J�J�JrOc�>�d�t|j��D��S)zQreturn a list of defs in the template.

        .. versionadded:: 1.0.4

        c�>�g|]}|dd�dk�|dd���S)N��render_r)�.0�is  rM�
<listcomp>z&Template.list_defs.<locals>.<listcomp>�s2��F�F�F�!�1�R�a�R�5�I�3E�3E��!�"�"��3E�3E�3ErO)rXr7rTs rM�	list_defszTemplate.list_defs�s#��G�F�s�4�;�/�/�F�F�F�FrOc�2�t|jd|z��Sr�)r~r7r�s  rM�_get_def_callablezTemplate._get_def_callable�r�rOc��|jjSr[)r7�_modified_timerTs rM�
last_modifiedzTemplate.last_modified�s
���{�)�)rO)NNNFNNNrNNr
TNNNNNNNrFNNTNNN)�__name__�
__module__�__qualname__�__doc__r	r.rNr�memoized_propertyrUr@r5�propertyrjrLrrGrHrFrxr{r�r�r�r�r�r�rrOrMrrs
��������B�I�������� �������������������"�9s
�s
�s
�s
�j
��?�?���?�/�/�/�(���<�E�E��X�E�
�C�C��X�C�

��!�!���!��&�&��X�&��&�&��X�&��'�'��X�'�A�A�A�
�
�
�P�P�P�8�8�8�K�K�K�
G�G�G�8�8�8��*�*��X�*�*�*rOrc�<�eZdZdZ																	dd�ZdS)	�ModuleTemplatea-A Template which is constructed given an existing Python module.

    e.g.::

         t = Template("this is a template")
         f = file("mymodule.py", "w")
         f.write(t.code)
         f.close()

         import mymodule

         t = ModuleTemplate(mymodule)
         print(t.render())

    NrFr
Tc	��tjdd|j��|_|j|_|j|_||_||_|j	|_
||_||_t|||||||j��|jj|_|	|_|
|_||_||_|�|
|||||��dS)Nrr)rr�
_template_urirr�_source_encodingr#r$r%�_enable_loopr&r7r8r2r9r:r;r<r=r>r@)rAr7rI�template�template_filename�
module_source�template_sourcer$r%r;r<r>rCrDrErFrGrHr=s                   rMrNzModuleTemplate.__init__�s���*���s�F�,@�A�A����'���$�5���.���.���!�.������)��
��������� �	
�	
�	
���0���!2���*���%:��"�������������
	
�	
�	
�	
�	
rO)NNNNNNrFNNNr
TNNNN)r�r�r�r�rNrrOrMr�r��sg��������&������ ����������"�'4
�4
�4
�4
�4
�4
rOr�c��eZdZdZd�Zd�ZdS)r�zNA :class:`.Template` which represents a callable def in a parent
    template.c���||_||_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j	|_	dSr[)
�parentr:r$r7r%r;r<r=r&r>)rAr�r:s   rMrNzDefTemplate.__init__0sh�����"���%�5����m���%�5���!'�!9���#�1���%+�%A��"�!�-����m����rOc�6�|j�|��Sr[)r�r�r�s  rMr�zDefTemplate.get_def<s���{�"�"�4�(�(�(rON)r�r�r�r�rNr�rrOrMr�r�+s<��������
$�
$�
$�)�)�)�)�)rOr�c�z�eZdZdZej��Zd�Zedd���Z	e
d���Ze
d���ZdS)	r2z�Stores information about a module currently loaded into
    memory, provides reverse lookups of template source, module
    source code based on a module's identifier.

    c��||_||_||_||_||_||_|x|j|j<|_|r||j|<dSdSr[)	r7rIr�r�r��template_uri�_modulesr��_mmarker)rAr7rIr�r�r�r�r�s        rMrNzModuleInfo.__init__Jsm�����.���!2���*���.���(���=A�A��
�f�o�&��):��	2�-1�D�M�/�*�*�*�	2�	2rOFc��tjd|tj���d��}t	j|��}d�|d���D��|d<|rRgx}|d<|d}d}tdt|����D]#}||vr||}|�	|���$|S)Nz'__M_BEGIN_METADATA(.+?)__M_END_METADATArc�N�i|]"\}}t|��t|����#Sr)�int)r��k�vs   rM�
<dictcomp>z9ModuleInfo.get_module_source_metadata.<locals>.<dictcomp>ds7��"
�"
�"
�#�q�!�C��F�F�C��F�F�"
�"
�"
rO�line_map�
full_line_map)
r�search�S�group�json�loads�items�range�max�append)�clsr�r��
source_map�
f_line_mapr��curr_templ_line�mod_lines        rM�get_module_source_metadataz%ModuleInfo.get_module_source_metadata^s����Y�6�
�r�t�
�
�
�%��(�(�	��Z�
�+�+�
�"
�"
�'1�*�'=�'C�'C�'E�'E�"
�"
�"
�
�:���	3�79�9�J��O�4�!�*�-�H��O�!�!�S��]�]�3�3�
3�
3���x�'�'�&.�x�&8�O��!�!�/�2�2�2�2��rOc�P�|j�|jStj|j��Sr[)r�r�read_python_filerIrTs rMrLzModuleInfo.coders(����)��%�%��(��)=�>�>�>rOc�>�|j�Ftj|j��}|jjr|�|jj��S|S|jjr>t|jt��s$|j�|jj��S|jSr[)	r�rrar�r7r��decode�
isinstancer)rArgs  rMrjzModuleInfo.sourceys�����'��>�$�"8�9�9�D��{�+�
��{�{�4�;�#?�@�@�@���
�[�
)�	(�*�� �#�3
�3
�	(��'�.�.�t�{�/K�L�L�L��'�'rON)F)
r�r�r�r��weakref�WeakValueDictionaryr�rN�classmethodr�r�rLrjrrOrMr2r2@s���������+�w�*�,�,�H�2�2�2�(�����[��&�?�?��X�?��
(�
(��X�
(�
(�
(rOr2c��|�|||j|j���}|���}t	j||j||j|j|j	|j
|j||j|j
|j���}||fS)N)r#r-)	r)r*r+r,�source_encoding�generate_magic_commentr'r&rU)r.r#r-�parser�compilerr)r*r+r,�encodingr'r&rU)r�rBr8r��lexer�noderjs       rM�_compiler��s���������.��*�	
�
�
�E��;�;�=�=�D�
�_����� �0��.�� ��.���5�!�2��(��.�
�
�
�F��5�=�rOc���|j}t|||d���\}}|}tj|��}t	||d��}t||j|j��||fS)NF�r��exec)rr��types�
ModuleTyper�r��__dict__)	r�rBr8�
identifierrjr��cidr7rLs	         rMr/r/�sv���#�J���$������M�F�E��C�
�
�c�
"�
"�F��6�3��'�'�D�	��v����0�0�0��F��rOc��t|||d���\}}t|t��r|�|jpd��}|r|||��dStjtj�	|�����\}}tj
||��tj|��tj
||��dS)NTr��ascii)rX)r�r�r�encoder��tempfile�mkstemprrr]�write�close�shutil�move)	r�rBr8�
outputpathr(rjr��destr�s	         rMrbrb�s�����$������M�F�E��&�#���:����u�~�8��9�9���
&��
�f�j�)�)�)�)�)�
 �'�B�G�O�O�J�,G�,G�H�H�H���t�
���v����
��������D�*�%�%�%�%�%rOc�6�t|jd��S)Nr�)�_get_module_info�__globals__)r:s rMriri�s���I�1�*�=�>�>�>rOc�&�tj|Sr[)r2r�)r8s rMr�r��s����x�(�(rO)r�r�rrr�r^r�r�r��makorrrrrr�
mako.lexerr	rr�r�r2r�r/rbrir�rrOrM�<module>r�s���=�=�����	�	�	�	�	�	�	�	�
�
�
�
�����������������������������������������������������������C*�C*�C*�C*�C*�C*�C*�C*�LF
�F
�F
�F
�F
�X�F
�F
�F
�R)�)�)�)�)�(�)�)�)�*G(�G(�G(�G(�G(�G(�G(�G(�T���2���&�&�&�*?�?�?�)�)�)�)�)rO

Zerion Mini Shell 1.0