o
    '[hH  ã                   @   sR   d Z ddlZddlmZ dgZG dd„ deƒZG dd„ deƒZG dd	„ d	eƒZdS )
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(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r   z¤
    Helper for looping (particularly in templates)

    Use this like::

        for loop, item in looper(seq):
            if loop.first:
                ...
    c                 C   s
   || _ d S ©N)Úseq©Úselfr   © r   úK/var/www/vscode/pina/lib/python3.10/site-packages/Cython/Tempita/_looper.pyÚ__init__&   ó   
zlooper.__init__c                 C   ó
   t | jƒS r   )Úlooper_iterr   ©r   r   r   r	   Ú__iter__)   r   zlooper.__iter__c                 C   s   d| j j| jf S )Nz<%s for %r>)Ú	__class__Ú__name__r   r   r   r   r	   Ú__repr__,   s   
ÿzlooper.__repr__N)r   Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   r   r	   r      s
    
c                   @   s6   e Zd Zdd„ Zdd„ Zdd„ Zejdk reZdS dS )	r   c                 C   s   t |ƒ| _d| _d S ©Nr   )Úlistr   Úposr   r   r   r	   r
   3   s   

zlooper_iter.__init__c                 C   s   | S r   r   r   r   r   r	   r   7   s   zlooper_iter.__iter__c                 C   s@   | j t| jƒkr
t‚t| j| j ƒ| j| j  f}|  j d7  _ |S ©Né   )r   Úlenr   ÚStopIterationÚloop_pos)r   Úresultr   r   r	   Ú__next__:   s
   zlooper_iter.__next__Ú3N)	r   r   r   r
   r   r   ÚsysÚversionÚnextr   r   r   r	   r   1   s    
ÿr   c                   @   sæ   e Zd Zdd„ Zdd„ Zdd„ ZeeƒZdd„ ZeeƒZd	d
„ ZeeƒZdd„ Z	ee	ƒZ	e
jdk r3e	Zdd„ ZeeƒZdd„ ZeeƒZdd„ ZeeƒZdd„ ZeeƒZdd„ ZeeƒZdd„ ZeeƒZd!dd„Zd!dd„Zdd „ ZdS )"r   c                 C   s   || _ || _d S r   ©r   r   )r   r   r   r   r   r	   r
   G   s   
zloop_pos.__init__c                 C   s   d| j | j | jf S )Nz<loop pos=%r at %r>r$   r   r   r   r	   r   K   s   ÿzloop_pos.__repr__c                 C   s   | j S r   ©r   r   r   r   r	   ÚindexO   s   zloop_pos.indexc                 C   s
   | j d S r   r%   r   r   r   r	   ÚnumberS   r   zloop_pos.numberc                 C   s   | j | j S r   r$   r   r   r   r	   ÚitemW   ó   zloop_pos.itemc                 C   s(   z	| j | jd  W S  ty   Y d S w r   )r   r   Ú
IndexErrorr   r   r   r	   r   [   s
   ÿzloop_pos.__next__r    c                 C   s   | j dkrd S | j| j d  S )Nr   r   )r   r   r   r   r   r	   Úpreviouse   s   
zloop_pos.previousc                 C   s   | j d  S ©Né   r%   r   r   r   r	   Úoddk   r)   zloop_pos.oddc                 C   s
   | j d S r,   r%   r   r   r   r	   Úeveno   r   zloop_pos.evenc                 C   s
   | j dkS r   r%   r   r   r   r	   Úfirsts   r   zloop_pos.firstc                 C   s   | j t| jƒd kS r   )r   r   r   r   r   r   r	   Úlastw   s   zloop_pos.lastc                 C   r   r   )r   r   r   r   r   r	   Úlength{   r   zloop_pos.lengthNc                 C   ó   | j rdS |  | 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)r0   Ú_compare_groupr(   r+   ©r   Úgetterr   r   r	   Úfirst_group   ó   zloop_pos.first_groupc                 C   r3   )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)r1   r4   r(   r   r5   r   r   r	   Ú
last_groupŠ   r8   zloop_pos.last_groupc                 C   sœ   |d u r||kS t |tƒr9| d¡r9|dd … }| d¡r/|d d… }t||ƒƒ t||ƒƒ kS t||ƒt||ƒkS t|dƒrF||ƒ||ƒkS || || kS )NÚ.r   z()éþÿÿÿÚ__call__)Ú
isinstancer   Ú
startswithÚendswithÚgetattrÚhasattr)r   r(   Úotherr6   r   r   r	   r4   •   s   
ÿ

zloop_pos._compare_groupr   )r   r   r   r
   r   r&   Úpropertyr'   r(   r   r!   r"   r#   r+   r.   r/   r0   r1   r2   r7   r9   r4   r   r   r   r	   r   E   s8    


r   )	r   r!   ÚCython.Tempita.compat3r   Ú__all__Úobjectr   r   r   r   r   r   r	   Ú<module>   s    