1.1 --- a/lib/builtins.py Sun Jun 07 20:04:16 2009 +0200
1.2 +++ b/lib/builtins.py Sun Jun 07 21:17:59 2009 +0200
1.3 @@ -207,9 +207,39 @@
1.4 pass
1.5
1.6 class xrange(object):
1.7 - def __init__(self, start_or_end, end=None, step=1): pass
1.8 - def __iter__(self): pass
1.9 - def next(self): pass
1.10 +
1.11 + "Implementation of xrange."
1.12 +
1.13 + def __init__(self, start_or_end, end=None, step=1):
1.14 +
1.15 + "Initialise the xrange with the given 'start_or_end', 'end' and 'step'."
1.16 +
1.17 + if end is None:
1.18 + self.start = 0
1.19 + self.end = start_or_end
1.20 + else:
1.21 + self.start = start_or_end
1.22 + self.end = end
1.23 +
1.24 + self.step = step
1.25 + self.current = self.start
1.26 +
1.27 + def __iter__(self):
1.28 +
1.29 + "Return an iterator, currently self."
1.30 +
1.31 + return self
1.32 +
1.33 + def next(self):
1.34 +
1.35 + "Return the next item or raise a StopIteration exception."
1.36 +
1.37 + if self.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end:
1.38 + raise StopIteration
1.39 +
1.40 + current = self.current
1.41 + self.current += self.step
1.42 + return current
1.43
1.44 # Exceptions and warnings.
1.45