1.1 --- a/lib/builtins.py Sat Jun 12 23:09:30 2010 +0200
1.2 +++ b/lib/builtins.py Sun Jun 13 02:24:35 2010 +0200
1.3 @@ -233,8 +233,7 @@
1.4 class set(object):
1.5 def __init__(self, iterable): pass
1.6
1.7 -class slice(object):
1.8 - def __init__(self, start_or_end, end=None, step=None): pass
1.9 +# See below for slice.
1.10
1.11 class str(basestring):
1.12 pass
1.13 @@ -277,6 +276,7 @@
1.14
1.15 self.step = step
1.16 self.current = self.start
1.17 + self.limited = self.end is not None
1.18
1.19 def __iter__(self):
1.20
1.21 @@ -288,13 +288,24 @@
1.22
1.23 "Return the next item or raise a StopIteration exception."
1.24
1.25 - if self.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end:
1.26 - raise StopIteration()
1.27 + if self.limited:
1.28 + if self.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end:
1.29 + raise StopIteration()
1.30
1.31 current = self.current
1.32 self.current += self.step
1.33 return current
1.34
1.35 +class slice(xrange):
1.36 +
1.37 + "Implementation of slice."
1.38 +
1.39 + def __init__(self, start_or_end=None, end=None, step=1):
1.40 +
1.41 + "Initialise the slice with the given 'start_or_end', 'end' and 'step'."
1.42 +
1.43 + xrange.__init__(self, start_or_end, end, step)
1.44 +
1.45 # Exceptions and warnings.
1.46
1.47 class BaseException(object):
1.48 @@ -402,9 +413,29 @@
1.49 return obj.__len__()
1.50
1.51 def locals(): pass
1.52 +
1.53 def map(function, *args): pass
1.54 -def max(*args): pass
1.55 -def min(*args): pass
1.56 +
1.57 +def max(*args):
1.58 +
1.59 + "Implementation of max."
1.60 +
1.61 + highest = args[0]
1.62 + for arg in args[1:]:
1.63 + if arg > highest:
1.64 + highest = arg
1.65 + return highest
1.66 +
1.67 +def min(*args):
1.68 +
1.69 + "Implementation of min."
1.70 +
1.71 + lowest = args[0]
1.72 + for arg in args[1:]:
1.73 + if arg > lowest:
1.74 + lowest = arg
1.75 + return lowest
1.76 +
1.77 def oct(number): pass
1.78 def open(name, mode=None, buffering=None): pass
1.79 def ord(c): pass