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/trac/util/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/trac/util/__pycache__/presentation.cpython-310.pyc
o

��e�7�@s�dZddlmZddlmZddlmZddlZddlmZm	Z	m
Z
ddlmZddl
mZd	d
lmZmZd	dlmZmZmZmZmZmZmZd	dlmZgd
�ZdZdd�Ze
dGdd��ZdHdd�Z dHdd�Z!dHdd�Z"dd�Z#dd�Z$dd�Z%d d!�Z&d"d#�Z'd$d%�Z(d&d'�Z)d(d)�Z*d*d+�Z+d,d-�Z,dHd.d/�Z-e	d0d1��Z.d2d3�Z/d4d�Z0dId6d7�Z1Gd8d9�d9e2�Z3dJd;d<�Z4d=d>�d?D�Z5e�6d@dA�7e5�dB�Z8GdCdD�dDe�Z9dEdF�Z:dS)KzmVarious utility functions and classes that support common presentation
tasks such as grouping or pagination.
�)�JSONEncoder)�datetime)�ceilN)�	Undefined�
contextfilter�evalcontextfilter)�make_attrgetter)�	TracError�)�
to_utimestamp�utc)�Fragment�Markup�classes�html_attribute�soft_unicode�styles�tag)�javascript_quote)�captioned_buttonr�
first_last�group�istext�prepared_paginate�paginate�	PaginatorrcCsT|jjttttttd�|jjt	t
ttt
ttd�|jjtttttttttd�	dS)zgAugment a Jinja2 environment with filters, tests and global functions
    defined in this module.

    )�flatten�	groupattr�htmlattr�max�mix�trim)�greaterthan�greaterthanorequal�lessthan�lessthanorequal�not_equalto�not_in�text)	rrrrr�	separatedrr�to_jsonN)�filters�update�flatten_filter�groupattr_filter�htmlattr_filter�
max_filter�
min_filter�trim_filter�tests�is_greaterthan�is_greaterthanorequal�is_lessthan�is_lessthanorequal�is_not_equalto�	is_not_inr�globalsrrrrr)rrr*)�jenv�r<�8/usr/lib/python3/dist-packages/trac/util/presentation.py�
jinja2_update&s8��	
�r>TcCs�|sdSt|t�r|nt|�}g}t|�D]}||}t|t|t�r$dn|�}|dur4|�d||f�qd�|�}|rB|rBd|}|jrIt|�}|S)a�Create an SGML/XML attribute string based on the items in a dict.

    If the dict itself is `none` or `undefined`, it returns the empty
    string. ``d`` can also be an iterable or a mapping, in which case
    it will be converted to a ``dict``.

    All values that are neither `none` nor `undefined` are
    automatically escaped.

    For HTML attributes like `'checked'` and `'selected'`, a truth
    value will be converted to the key value itself. For others it
    will be `'true'` or `'on'`. For `'class'`, the `classes`
    processing will be applied.

    Example:

    .. sourcecode:: html+jinja

        <ul${{'class': {'my': 1, 'list': True, 'empty': False},
              'missing': none, 'checked': 1, 'selected': False,
              'autocomplete': True, 'id': 'list-%d'|format(variable),
              'style': {'border-radius': '3px' if rounded,
                        'background': '#f7f7f7'}
             }|htmlattr}>
        ...
        </ul>

    Results in something like this:

    .. sourcecode:: html

        <ul class="my list" id="list-42" checked="checked" autocomplete="on"
            style="border-radius: 3px; background: #f7f7f7">
        ...
        </ul>

    As you can see it automatically prepends a space in front of the item
    if the filter returned something unless the second parameter is false.

    Adapted from Jinja2's builtin ``do_xmlattr`` filter.

    �Nz%s="%s"� )	�
isinstance�dict�sortedrr�append�join�
autoescaper)�	_eval_ctx�d�	autospace�attrs�key�val�rvr<r<r=r/Ks ,�
r/cC�t|�rt|�S|S)z(Returns the max value from the sequence.)�lenr��seq�defaultr<r<r=r0��r0cCrN)z(Returns the min value from the sequence.)rO�minrPr<r<r=r1�rSr1cCst|��|�S)z|Strip leading and trailing whitespace or other specified character.

    Adapted from Jinja2's builtin ``trim`` filter.
    )r�strip)�value�whatr<r<r=r2�sr2cCsg}|D]}|�|�q|S)z"Combine incoming sequences in one.)�extend)rVrQ�sr<r<r=r-�sr-cCs||kS�Nr<��a�br<r<r=r8��r8cCs||kSrZr<r[r<r<r=r4�r^r4cCs||kSrZr<r[r<r<r=r5�r^r5cCs||kSrZr<r[r<r<r=r6�r^r6cCs||kSrZr<r[r<r<r=r7�r^r7cCs||vSrZr<r[r<r<r=�is_in�r^r_cCs||vSrZr<r[r<r<r=r9�r^r9cCs|j�d�r|Sd||fS)zEReturn symbol and text or only symbol, according to user preferences.zui.use_symbolsz%s %s)�session�get)�req�symbolr(r<r<r=r�s
�rcCst|dk|t|�dkd�S)aYGenerate ``first`` or ``last`` or both, according to the
    position `idx` in sequence `seq`.

    In Jinja2 templates, rather use:

    .. sourcecode:: html+jinja

       <li ${{'class': {'first': loop.first, 'last': loop.last}}|htmlattr}>

    This is less error prone, as the sequence remains implicit and
    therefore can't be wrong.

    rr
)�first�last)rrO)�idxrQr<r<r=r�srccs��g}|D]9}|o
||�}|r'|r'|dg|t|�7}t|�V|dd�=|�|�|s4t|�|kr>t|�V|dd�=q|rS|dg|t|�7}t|�VdSdS)adCombines the elements produced by the given iterable so that every `n`
    items are returned as a tuple.

    >>> items = [1, 2, 3, 4]
    >>> for item in group(items, 2):
    ...     print(item)
    (1, 2)
    (3, 4)

    The last tuple is padded with `None` values if its' length is smaller than
    `num`.

    >>> items = [1, 2, 3, 4, 5]
    >>> for item in group(items, 2):
    ...     print(item)
    (1, 2)
    (3, 4)
    (5, None)

    The optional `predicate` parameter can be used to flag elements that should
    not be packed together with other items. Only those elements where the
    predicate function returns True are grouped with other elements, otherwise
    they are returned as a tuple of length 1:

    >>> items = [1, 2, 3, 4]
    >>> for item in group(items, 2, lambda x: x != 3):
    ...     print(item)
    (1, 2)
    (3,)
    (4, None)
    N)rO�tuplerD)�iterable�num�	predicate�buf�item�flushr<r<r=r�s"� 




��rcsdt�j|��z�d��dd������fdd��Wnty&t�Ynwt||��fdd��S)z/Similar to `group`, but as an attribute filter.rr
Ncs�j��|���SrZ)�environment�	call_test�rl)rG�args�kwargs�namer<r=�<lambda>
s
�z"groupattr_filter.<locals>.<lambda>cs��|��SrZr<rp)�attr_getter�	test_funcr<r=rts)rrn�LookupError�boolr)rGrhri�attrrqrrr<)rGrqrurrrsrvr=r.s�r.cCst|t�o
t|t�S)z>`True` for text (`str` and `bytes`), but `False` for `Markup`.)rA�strr)r(r<r<r=rsrcCs,|dkrd}n
ttt|�|��}|||fS)Nrr
)�intr�float)�items�	num_items�max_per_page�	num_pagesr<r<r=rs
�
c
Cs�|sd}||}||}d}t|d�r+t|�}|r+||kr+ddlm}t|d|d���z|||�}Wn9tylg}d}t|�D]\}}	||krP|krWnn|�|	�|dura||kranqB|durj|d}Ynw||tt	t
|�|��fS)	aSimple generic pagination.

    Given an iterable, this function returns:
     * the slice of objects on the requested page,
     * the total number of items, and
     * the total number of pages.

    The `items` parameter can be a list, tuple, or iterator:

    >>> items = list(range(12))
    >>> items
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
    >>> paginate(items)
    ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 12, 2)
    >>> paginate(items, page=1)
    ([10, 11], 12, 2)
    >>> paginate(iter(items))
    ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 12, 2)
    >>> paginate(iter(items), page=1)
    ([10, 11], 12, 2)

    This function also works with generators:

    >>> def generate():
    ...     for idx in range(12):
    ...         yield idx
    >>> paginate(generate())
    ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 12, 2)
    >>> paginate(generate(), page=1)
    ([10, 11], 12, 2)

    The `max_per_page` parameter can be used to set the number of items that
    should be displayed per page:

    >>> items = list(range(12))
    >>> paginate(items, page=0, max_per_page=6)
    ([0, 1, 2, 3, 4, 5], 12, 2)
    >>> paginate(items, page=1, max_per_page=6)
    ([6, 7, 8, 9, 10, 11], 12, 2)

    :raises TracError: if `page` is out of the range of the paginated
                       results.
    rN�__len__��_zPage %(page)s is out of range.��page���r
)�hasattrrO�trac.util.translationr�r	�	TypeError�	enumeraterDr{rr|)
r}r�r�start�stop�countr��retvalrfrlr<r<r=rs4,

���rc@speZdZdZddd�Zdd�Zd	d
�Zdd�Zd
d�Ze	dd��Z
e	dd��Ze	dd��Zddd�Z
dd�ZdS)rzPagination controllerrr�NcCsx|sd}|durt|||�\}}}n	t|||�\}}}||}||_||_||_||_||_||t|�f|_d|_	dS)NrT)
rrr�rr}r~r�rO�span�
show_index)�selfr}r�rr~r��offsetr<r<r=�__init__ms
�
zPaginator.__init__cC�
t|j�SrZ)�iterr}�r�r<r<r=�__iter__�
zPaginator.__iter__cCr�rZ�rOr}r�r<r<r=r��r�zPaginator.__len__cCst|j�dkS�Nrr�r�r<r<r=�__nonzero__��zPaginator.__nonzero__cCs||j|<dSrZ)r})r�rfrVr<r<r=�__setitem__�r�zPaginator.__setitem__cC�
|jdkS�Nr
)r�r�r<r<r=�has_more_pages��
zPaginator.has_more_pagescCs|jd|jkSr�)r�r�r�r<r<r=�
has_next_page�szPaginator.has_next_pagecCr�r�r�r�r<r<r=�has_previous_page�r�zPaginator.has_previous_page�cCs�|js
ttdd��Sd}ttt|j�|j��}|jd}||d}||d|dd}||kr5|}||kr;|}tt||d��S)Nr
�)	r��list�ranger{rr|r~rr�)r��page_index_count�min_page�max_page�current_page�
start_page�end_pager<r<r=�get_shown_pages�s


�zPaginator.get_shown_pagescCsVddlm}|j\}}|j}|d|kr|d||d�S|d|jdd|jd|d�S)Nrr�r
z%(last)d of %(total)d)re�totalz!%(start)d - %(stop)d of %(total)d)r�r�r�)r�r�r�r~)r�r�r�r�r�r<r<r=�displayed_items�s
�zPaginator.displayed_items)rr�N)r�)�__name__�
__module__�__qualname__�__doc__r�r�r�r�r��propertyr�r�r�r�r�r<r<r<r=rjs




r�,ccsR�t|�}zt|�}Wn
tyYdSw|D]	}||fV|}q||fVdS)a�Yield `(item, sep)` tuples, one for each element in `items`.

    The separator after the last item is specified by the `last` parameter,
    which defaults to `None`. (Since 1.1.3)

    >>> list(separated([1, 2]))
    [(1, ','), (2, None)]

    >>> list(separated([1]))
    [(1, None)]

    >>> list(separated('abc', ':'))
    [('a', ':'), ('b', ':'), ('c', None)]

    >>> list(separated((1, 2, 3), sep=';', last='.'))
    [(1, ';'), (2, ';'), (3, '.')]
    N)r��next�
StopIteration)r}�sepre�nextval�ir<r<r=r)�s��
r)cCsi|]	}|dt|��qS)z\u%04x)�ord)�.0�cr<r<r=�
<dictcomp>�sr�z&<>�[r?�]c@seZdZdd�ZdS)�TracJSONEncodercCsZt|t�rdSt|t�rt|jr|�S|jtd��St|t�r'dtt	|��St
�||�S)Nr?)�tzinfoz"%s")rArrrr��replacerr
rrzrrR)r��or<r<r=rR�s


zTracJSONEncoder.defaultN)r�r�r�rRr<r<r<r=r��sr�cCs&dd�}tddd��|�}t�||�S)zEncode `value` to JSON.cSst|�d�Sr�)�	_js_quoter)�matchr<r<r=r��r�zto_json.<locals>.replaceT)r��:)�	sort_keys�
separators)r��encode�_js_quote_re�sub)rVr�r(r<r<r=r*�sr*)TrZ)rr�)r�N);r��jsonrr�mathr�re�jinja2rrr�jinja2.filtersr�	trac.corer	�datefmtrr�htmlr
rrrrrrr(r�__all__�
__no_apidoc__r>r/r0r1r2r-r8r4r5r6r7r_r9rrrr.rrr�objectrr)r��compilerEr�r�r*r<r<r<r=�<module>sR$%
>



0


K
J

https://t.me/RX1948 - 2025