HEX
Server: LiteSpeed
System: Linux standart9.isimtescil.net 3.10.0-962.3.2.lve1.5.26.7.el7.x86_64 #1 SMP Wed Oct 2 07:53:12 EDT 2019 x86_64
User: karalev (5310)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/tempita/__pycache__/_looper.cpython-37.pyc
B

��]D�@sRdZddlZddlmZdgZGdd�de�ZGdd�de�ZGdd	�d	e�ZdS)
a
Helper for looping over sequences, particular in templates.

Often in a loop in a template it's handy to know what's next up,
previously up, if this is the first or last item in the sequence, etc.
These can be awkward to manage in a normal Python loop, but using the
looper you can get a better sense of the context.  Use like::

    >>> for loop, item in looper(['a', 'b', 'c']):
    ...     print(loop.number, item)
    ...     if not loop.last:
    ...         print('---')
    1 a
    ---
    2 b
    ---
    3 c

�N)�basestring_�looperc@s(eZdZdZdd�Zdd�Zdd�ZdS)	rz�
    Helper for looping (particularly in templates)

    Use this like::

        for loop, item in looper(seq):
            if loop.first:
                ...
    cCs
||_dS)N)�seq)�selfr�r�@/opt/alt/python37/lib/python3.7/site-packages/tempita/_looper.py�__init__&szlooper.__init__cCs
t|j�S)N)�looper_iterr)rrrr�__iter__)szlooper.__iter__cCsd|jj|jfS)Nz<%s for %r>)�	__class__�__name__r)rrrr�__repr__,szlooper.__repr__N)r�
__module__�__qualname__�__doc__rr
r
rrrrrs	c@s2eZdZdd�Zdd�Zdd�Zejdkr.eZdS)	r	cCst|�|_d|_dS)Nr)�listr�pos)rrrrrr3s
zlooper_iter.__init__cCs|S)Nr)rrrrr
7szlooper_iter.__iter__cCs@|jt|j�krt�t|j|j�|j|jf}|jd7_|S)N�)r�lenr�
StopIteration�loop_pos)r�resultrrr�__next__:s
zlooper_iter.__next__�3N)	rrrrr
r�sys�version�nextrrrrr	1s

r	c@s�eZdZdd�Zdd�Zdd�Zee�Zdd�Zee�Zd	d
�Zee�Zdd�Z	ee	�Z	e
jd
krfe	Zdd�Z
ee
�Z
dd�Zee�Zdd�Zee�Zdd�Zee�Zdd�Zee�Zdd�Zee�Zd!dd�Zd"dd�Zdd �ZdS)#rcCs||_||_dS)N)rr)rrrrrrrGszloop_pos.__init__cCsd|j|j|jfS)Nz<loop pos=%r at %r>)rr)rrrrr
Kszloop_pos.__repr__cCs|jS)N)r)rrrr�indexOszloop_pos.indexcCs
|jdS)Nr)r)rrrr�numberSszloop_pos.numbercCs|j|jS)N)rr)rrrr�itemWsz
loop_pos.itemcCs*y|j|jdStk
r$dSXdS)Nr)rr�
IndexError)rrrrr[szloop_pos.__next__rcCs|jdkrdS|j|jdS)Nrr)rr)rrrr�previouses
zloop_pos.previouscCs|jdS)N�)r)rrrr�oddkszloop_pos.oddcCs
|jdS)Nr")r)rrrr�evenosz
loop_pos.evencCs
|jdkS)Nr)r)rrrr�firstsszloop_pos.firstcCs|jt|j�dkS)Nr)rrr)rrrr�lastwsz
loop_pos.lastcCs
t|j�S)N)rr)rrrr�length{szloop_pos.lengthNcCs|jr
dS|�|j|j|�S)a
        Returns true if this item is the start of a new group,
        where groups mean that some attribute has changed.  The getter
        can be None (the item itself changes), an attribute name like
        ``'.attr'``, a function, or a dict key or list index.
        T)r%�_compare_grouprr!)r�getterrrr�first_groupszloop_pos.first_groupcCs|jr
dS|�|j|j|�S)a
        Returns true if this item is the end of a new group,
        where groups mean that some attribute has changed.  The getter
        can be None (the item itself changes), an attribute name like
        ``'.attr'``, a function, or a dict key or list index.
        T)r&r(rr)rr)rrr�
last_group�szloop_pos.last_groupcCs�|dkr||kSt|t�rt|�d�rt|dd�}|�d�r^|dd�}t||��t||��kSt||�t||�kSn*t|d�r�||�||�kS||||kSdS)N�.rz()����__call__)�
isinstancer�
startswith�endswith�getattr�hasattr)rr�otherr)rrrr(�s



zloop_pos._compare_group)N)N)rrrrr
r�propertyrrrrrrr!r#r$r%r&r'r*r+r(rrrrrEs6


r)	rrZtempita.compat3r�__all__�objectrr	rrrrr�<module>s