← Back
Editing: newrange.cpython-38.pyc
U ,�]� � @ s� d Z ddlmZ ddlmZ er2ddlmZmZ nddlmZmZ ddl m Z ddlmZ eZ G dd� de�ZG d d � d e�ZdgZdS )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 Zd ZdZdd� Zedd� �Zedd� �Zedd � �Zd d� Z dd � Z dd� Zdd� Zdd� Z dd� Zdd� Zdd� Zdd� Zdd� ZdS )�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 |�dkr"d|d d }}}nFt |�dkrH|d |d d }}}n t |�dkr`|\}}}ntd��z t|�t|�t|� }}}W n tk r� td��Y nX |dkr�td��n|dk r�t||�}n t||�}|| _|| _|| _|| | t || | � | _ d S )N� r � � z"range() requires 1-3 int argumentszan integer is requiredzrange() arg 3 must not be zero)�len� TypeError�int� ValueError�min�max�_start�_stop�_step�bool�_len)�self�args�start�stop�step� r �7/usr/lib/python3/dist-packages/future/types/newrange.py�__init__* s( znewrange.__init__c C s | j S �N)r �r r r r r E s znewrange.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 dkrd| j| jf S d| j| j| j f S )Nr z range(%d, %d)zrange(%d, %d, %d))r r r r r r r �__repr__Q s znewrange.__repr__c C sF t |t�oD| jd ko |jkn pD| j| j| jf|j|j| jfkS )Nr )� isinstancer r r r )r �otherr r r �__eq__V s ��znewrange.__eq__c C s | j S r )r r r r r �__len__\ s znewrange.__len__c C sz z|| j }W n tk r. td| ��Y nX t|| j�\}}|dkrjd| kr^| jk rjn nt|�S td| ��dS )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 �valueZdiffZquotientZ remainderr r r �index_ s "znewrange.indexc C s t || k�S )zaReturn the number of ocurrences of integer `value` in the sequence this range represents.)r �r r) r r r r k s znewrange.countc C s, z| � |� W dS tk r& Y dS X dS )z\Return ``True`` if the integer `value` occurs in the sequence this range represents.TFN)r* r r+ r r r �__contains__q s znewrange.__contains__c C s t | d d d� �S )N���)�iterr r r r �__reversed__z s znewrange.__reversed__c C sP t |t�r| �|�S |dk r&| j| }|dk s8|| jkr@td��| j|| j S )z�Return the element at position ``index`` in the sequence this range represents, or raise :class:`IndexError` if the position is out of range.r zrange object index out of range)r# �slice�_newrange__getitem_slicer � IndexErrorr r )r r* r r r �__getitem__} s znewrange.__getitem__c s<