<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from collections import Sequence , Iterator <EOL> from itertools import islice <EOL> from future . backports . misc import count <EOL> _count = count <EOL> class newrange ( Sequence ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args ) : <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> start , stop , step = <NUM_LIT:0> , args [ <NUM_LIT:0> ] , <NUM_LIT:1> <EOL> elif len ( args ) == <NUM_LIT:2> : <EOL> start , stop , step = args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> ] , <NUM_LIT:1> <EOL> elif len ( args ) == <NUM_LIT:3> : <EOL> start , stop , step = args <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> try : <EOL> start , stop , step = int ( start ) , int ( stop ) , int ( step ) <EOL> except ValueError : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> if step == <NUM_LIT:0> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> elif step < <NUM_LIT:0> : <EOL> stop = min ( stop , start ) <EOL> else : <EOL> stop = max ( stop , start ) <EOL> self . _start = start <EOL> self . _stop = stop <EOL> self . _step = step <EOL> self . _len = ( stop - start ) // step + bool ( ( stop - start ) % step ) <EOL> @ property <EOL> def start ( self ) : <EOL> return self . _start <EOL> @ property <EOL> def stop ( self ) : <EOL> return self . _stop <EOL> @ property <EOL> def step ( self ) : <EOL> return self . _step <EOL> def __repr__ ( self ) : <EOL> if self . _step == <NUM_LIT:1> : <EOL> return '<STR_LIT>' % ( self . _start , self . _stop ) <EOL> return '<STR_LIT>' % ( self . _start , self . _stop , self . _step ) <EOL> def __eq__ ( self , other ) : <EOL> return ( isinstance ( other , newrange ) and <EOL> ( self . _len == <NUM_LIT:0> == other . _len or <EOL> ( self . _start , self . _step , self . _len ) == <EOL> ( other . _start , other . _step , self . _len ) ) ) <EOL> def __len__ ( self ) : <EOL> return self . _len <EOL> def index ( self , value ) : <EOL> """<STR_LIT>""" <EOL> diff = value - self . _start <EOL> quotient , remainder = divmod ( diff , self . _step ) <EOL> if remainder == <NUM_LIT:0> and <NUM_LIT:0> <= quotient < self . _len : <EOL> return abs ( quotient ) <EOL> raise ValueError ( '<STR_LIT>' % value ) <EOL> def count ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return int ( value in self ) <EOL> def __contains__ ( self , value ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . index ( value ) <EOL> return True <EOL> except ValueError : <EOL> return False <EOL> def __reversed__ ( self ) : <EOL> return iter ( self [ : : - <NUM_LIT:1> ] ) <EOL> def __getitem__ ( self , index ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( index , slice ) : <EOL> return self . __getitem_slice ( index ) <EOL> if index < <NUM_LIT:0> : <EOL> index = self . _len + index <EOL> if index < <NUM_LIT:0> or index >= self . _len : <EOL> raise IndexError ( '<STR_LIT>' ) <EOL> return self . _start + index * self . _step <EOL> def __getitem_slice ( self , slce ) : <EOL> """<STR_LIT>""" <EOL> scaled_indices = ( self . _step * n for n in slce . indices ( self . _len ) ) <EOL> start_offset , stop_offset , new_step = scaled_indices <EOL> return newrange ( self . _start + start_offset , <EOL> self . _start + stop_offset , <EOL> new_step ) <EOL> def __iter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return range_iterator ( self ) <EOL> class range_iterator ( Iterator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , range_ ) : <EOL> self . _stepper = islice ( count ( range_ . start , range_ . step ) , len ( range_ ) ) <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> return next ( self . _stepper ) <EOL> __all__ = [ '<STR_LIT>' ] </s>
