a
    ,]                     @   s   d Z ddlmZ ddlmZ er2ddlmZmZ nddlmZmZ ddl	m
Z
 ddlmZ eZG dd deZG d	d
 d
eZdgZdS )aw  
Nearly identical to xrange.py, by Dan Crosta, from

    https://github.com/dcrosta/xrange.git

This is included here in the ``future`` package rather than pointed to as
a dependency because there is no package for ``xrange`` on PyPI. It is
also tweaked to appear like a regular Python 3 ``range`` object rather
than a Python 2 xrange.

From Dan Crosta's README:

    "A pure-Python implementation of Python 2.7's xrange built-in, with
    some features backported from the Python 3.x range built-in (which
    replaced xrange) in that version."

    Read more at
        https://late.am/post/2012/06/18/what-the-heck-is-an-xrange
    )absolute_import)PY2)SequenceIterator)islice)countc                   @   s   e Zd ZdZdd Zedd Zedd Zedd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )newrangez
    Pure-Python backport of Python 3's range object.  See `the CPython
    documentation for details:
    <http://docs.python.org/py3k/library/functions.html#range>`_
    c                 G   s  t |dkr"d|d d  }}}nFt |dkrH|d |d d  }}}n t |dkr`|\}}}ntdz t|t|t|  }}}W n ty   tdY n0 |dkrtdn|dk rt||}n
t||}|| _|| _|| _|| | t	|| |  | _
d S )N   r         z"range() requires 1-3 int argumentszan integer is requiredzrange() arg 3 must not be zero)len	TypeErrorint
ValueErrorminmax_start_stop_stepbool_len)selfargsstartstopstep r   f/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python3.9/site-packages/future/types/newrange.py__init__*   s(     

znewrange.__init__c                 C   s   | j S N)r   r   r   r   r   r   E   s    znewrange.startc                 C   s   | j S r   )r   r    r   r   r   r   I   s    znewrange.stopc                 C   s   | j S r   r   r    r   r   r   r   M   s    znewrange.stepc                 C   s.   | j dkrd| j| jf S d| j| j| j f S )Nr	   zrange(%d, %d)zrange(%d, %d, %d))r   r   r   r    r   r   r   __repr__Q   s    
znewrange.__repr__c                 C   sF   t |toD| jd  ko |jkn  pD| j| j| jf|j|j| jfkS )Nr   )
isinstancer   r   r   r   )r   otherr   r   r   __eq__V   s    
znewrange.__eq__c                 C   s   | j S r   )r   r    r   r   r   __len__\   s    znewrange.__len__c                 C   sx   z|| j  }W n ty,   td| Y n0 t|| j\}}|dkrhd|  kr\| jk rhn nt|S td| dS )z]Return the 0-based position of integer `value` in
        the sequence this range represents.z%r is not in ranger   N)r   r   r   divmodr   r   abs)r   valueZdiffZquotient	remainderr   r   r   index_   s    "znewrange.indexc                 C   s   t || v S )zaReturn the number of ocurrences of integer `value`
        in the sequence this range represents.)r   r   r)   r   r   r   r   k   s    znewrange.countc                 C   s*   z|  | W dS  ty$   Y dS 0 dS )z\Return ``True`` if the integer `value` occurs in
        the sequence this range represents.TFN)r+   r   r,   r   r   r   __contains__q   s
    
znewrange.__contains__c                 C   s   t | d d d S )N)iterr    r   r   r   __reversed__z   s    znewrange.__reversed__c                 C   sP   t |tr| |S |dk r&| j| }|dk s8|| jkr@td| j|| j  S )zReturn the element at position ``index`` in the sequence
        this range represents, or raise :class:`IndexError` if the
        position is out of range.r   zrange object index out of range)r#   slice_newrange__getitem_slicer   
IndexErrorr   r   )r   r+   r   r   r   __getitem__}   s    


znewrange.__getitem__c                    s<    fdd|  jD }|\}}}t j|  j| |S )znReturn a range which represents the requested slce
        of the sequence represented by this range.
        c                 3   s   | ]} j | V  qd S r   r!   ).0nr    r   r   	<genexpr>       z+newrange.__getitem_slice.<locals>.<genexpr>)indicesr   r   r   )r   ZslceZscaled_indicesZstart_offsetZstop_offsetZnew_stepr   r    r   Z__getitem_slice   s    

znewrange.__getitem_slicec                 C   s   t | S )z_Return an iterator which enumerates the elements of the
        sequence this range represents.)range_iteratorr    r   r   r   __iter__   s    znewrange.__iter__N)__name__
__module____qualname____doc__r   propertyr   r   r   r"   r%   r&   r+   r   r-   r0   r4   r2   r;   r   r   r   r   r   #   s$   


	
r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )r:   z&An iterator for a :class:`range`.
    c                 C   s   t t|j|jt|| _d S r   )r   r   r   r   r   _stepper)r   Zrange_r   r   r   r      s    zrange_iterator.__init__c                 C   s   | S r   r   r    r   r   r   r;      s    zrange_iterator.__iter__c                 C   s
   t | jS r   nextrA   r    r   r   r   __next__   s    zrange_iterator.__next__c                 C   s
   t | jS r   rB   r    r   r   r   rC      s    zrange_iterator.nextN)r<   r=   r>   r?   r   r;   rD   rC   r   r   r   r   r:      s
   r:   N)r?   
__future__r   Zfuture.utilsr   collectionsr   r   collections.abc	itertoolsr   Zfuture.backports.miscr   _countr   r:   __all__r   r   r   r   <module>   s   w