1 #!/usr/bin/env python 2 3 """ 4 Simple built-in classes and functions. Objects which provide code that shall 5 always be compiled should provide docstrings. 6 7 Copyright (C) 2005, 2006, 2007, 2008, 2009 Paul Boddie <paul@boddie.org.uk> 8 9 This program is free software; you can redistribute it and/or modify it under 10 the terms of the GNU General Public License as published by the Free Software 11 Foundation; either version 3 of the License, or (at your option) any later 12 version. 13 14 This program is distributed in the hope that it will be useful, but WITHOUT 15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 details. 18 19 You should have received a copy of the GNU General Public License along with 20 this program. If not, see <http://www.gnu.org/licenses/>. 21 """ 22 23 class object: 24 def __init__(self): pass 25 def __bool__(self): pass 26 27 class basestring(object): 28 def __init__(self, x=None): pass 29 def __getitem__(self, index): pass 30 def __getslice__(self, start, end=None): pass 31 def __iadd__(self, other): pass 32 def __add__(self, other): pass 33 def __radd__(self, other): pass 34 def __mul__(self, other): pass 35 def __rmul__(self, other): pass 36 def __mod__(self, other): pass 37 def __rmod__(self, other): pass 38 def __lt__(self, other): pass 39 def __gt__(self, other): pass 40 def __le__(self, other): pass 41 def __ge__(self, other): pass 42 def __eq__(self, other): pass 43 def __ne__(self, other): pass 44 def __len__(self): pass 45 def __str__(self): pass 46 def __bool__(self): pass 47 def join(self, l): pass 48 49 class bool(object): 50 def __bool__(self): pass 51 def __str__(self): pass 52 53 class buffer(object): 54 def __init__(self, size): pass 55 def append(self, s): pass 56 def __str__(self): pass 57 58 class complex(object): 59 def __init__(self, real, imag=None): pass 60 61 class dict(object): 62 def __init__(self, *args): pass 63 def __setitem__(self, key, value): pass 64 def __getitem__(self, key): pass 65 66 class file(object): 67 def write(self, s): pass 68 69 class float(object): 70 def __init__(self, number_or_string=None): pass 71 def __iadd__(self, other): pass 72 def __isub__(self, other): pass 73 def __add__(self, other): pass 74 def __radd__(self, other): pass 75 def __sub__(self, other): pass 76 def __rsub__(self, other): pass 77 def __mul__(self, other): pass 78 def __rmul__(self, other): pass 79 def __div__(self, other): pass 80 def __rdiv__(self, other): pass 81 def __floordiv__(self, other): pass 82 def __rfloordiv__(self, other): pass 83 def __mod__(self, other): pass 84 def __rmod__(self, other): pass 85 def __pow__(self, other): pass 86 def __rpow__(self, other): pass 87 def __lt__(self, other): pass 88 def __gt__(self, other): pass 89 def __le__(self, other): pass 90 def __ge__(self, other): pass 91 def __eq__(self, other): pass 92 def __ne__(self, other): pass 93 def __neg__(self): pass 94 def __pos__(self): pass 95 def __str__(self): pass 96 def __bool__(self): pass 97 98 class frozenset(object): 99 def __init__(self, iterable): pass 100 101 class function(object): 102 pass 103 104 class int(object): 105 def __init__(self, number_or_string=None): pass 106 def __iadd__(self, other): pass 107 def __isub__(self, other): pass 108 def __iand__(self, other): pass 109 def __ior__(self, other): pass 110 def __add__(self, other): pass 111 def __radd__(self, other): pass 112 def __sub__(self, other): pass 113 def __rsub__(self, other): pass 114 def __mul__(self, other): pass 115 def __rmul__(self, other): pass 116 def __div__(self, other): pass 117 def __rdiv__(self, other): pass 118 def __floordiv__(self, other): pass 119 def __rfloordiv__(self, other): pass 120 def __mod__(self, other): pass 121 def __rmod__(self, other): pass 122 def __pow__(self, other): pass 123 def __rpow__(self, other): pass 124 def __and__(self, other): pass 125 def __rand__(self, other): pass 126 def __or__(self, other): pass 127 def __ror__(self, other): pass 128 def __xor__(self, other): pass 129 def __rxor__(self, other): pass 130 def __lt__(self, other): pass 131 def __gt__(self, other): pass 132 def __le__(self, other): pass 133 def __ge__(self, other): pass 134 def __eq__(self, other): pass 135 def __ne__(self, other): pass 136 def __neg__(self): pass 137 def __pos__(self): pass 138 def __str__(self): pass 139 def __bool__(self): pass 140 def __lshift__(self): pass 141 def __rlshift__(self): pass 142 def __rshift__(self): pass 143 def __rrshift__(self): pass 144 145 class list(object): 146 147 "Implementation of list." 148 149 def __init__(self, args=None): 150 151 "Initialise the list." 152 153 self.__new__() 154 155 if args is not None: 156 for arg in args: 157 self.append(arg) 158 159 def __new__(self): 160 # Reserve space for a fragment reference. 161 self._elements = None 162 163 def __getitem__(self, index): pass 164 def __setitem__(self, index, value): pass 165 def __getslice__(self, start, end=None): pass 166 def __setslice__(self, start, end, slice): pass 167 def append(self, value): pass 168 def __len__(self): pass 169 def __add__(self, other): pass 170 def __iadd__(self, other): pass 171 def __str__(self): pass 172 def __bool__(self): pass 173 174 def __iter__(self): 175 176 "Return an iterator." 177 178 return listiterator(self) 179 180 class listiterator(object): 181 182 "Implementation of listiterator." 183 184 def __init__(self, l): 185 186 "Initialise with the given list 'l'." 187 188 self.l = l 189 self.i = 0 190 191 def next(self): 192 193 "Return the next item." 194 195 try: 196 value = self.l[self.i] 197 self.i += 1 198 return value 199 except IndexError: 200 raise StopIteration() 201 202 class long(object): 203 def __init__(self, number_or_string=None): pass 204 def __iadd__(self, other): pass 205 def __isub__(self, other): pass 206 def __add__(self, other): pass 207 def __radd__(self, other): pass 208 def __sub__(self, other): pass 209 def __rsub__(self, other): pass 210 def __mul__(self, other): pass 211 def __rmul__(self, other): pass 212 def __div__(self, other): pass 213 def __rdiv__(self, other): pass 214 def __floordiv__(self, other): pass 215 def __rfloordiv__(self, other): pass 216 def __and__(self, other): pass 217 def __rand__(self, other): pass 218 def __or__(self, other): pass 219 def __ror__(self, other): pass 220 def __xor__(self, other): pass 221 def __rxor__(self, other): pass 222 def __lt__(self, other): pass 223 def __gt__(self, other): pass 224 def __le__(self, other): pass 225 def __ge__(self, other): pass 226 def __eq__(self, other): pass 227 def __ne__(self, other): pass 228 def __neg__(self): pass 229 def __pos__(self): pass 230 def __str__(self): pass 231 def __bool__(self): pass 232 233 class set(object): 234 def __init__(self, iterable): pass 235 236 # See below for slice. 237 238 class str(basestring): 239 pass 240 241 class type(object): 242 pass 243 244 class tuple(object): 245 def __init__(self, args): pass 246 def __getitem__(self, index): pass 247 def __getslice__(self, start, end=None): pass 248 def __len__(self): pass 249 def __add__(self, other): pass 250 def __str__(self): pass 251 def __bool__(self): pass 252 253 def __iter__(self): 254 255 "Return an iterator." 256 257 return listiterator(self) 258 259 class unicode(basestring): 260 pass 261 262 class xrange(object): 263 264 "Implementation of xrange." 265 266 def __init__(self, start_or_end, end=None, step=1): 267 268 "Initialise the xrange with the given 'start_or_end', 'end' and 'step'." 269 270 if end is None: 271 self.start = 0 272 self.end = start_or_end 273 else: 274 self.start = start_or_end 275 self.end = end 276 277 self.step = step 278 self.current = self.start 279 self.limited = self.end is not None 280 281 def __iter__(self): 282 283 "Return an iterator, currently self." 284 285 return self 286 287 def next(self): 288 289 "Return the next item or raise a StopIteration exception." 290 291 if self.limited: 292 if self.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end: 293 raise StopIteration() 294 295 current = self.current 296 self.current += self.step 297 return current 298 299 class slice(xrange): 300 301 "Implementation of slice." 302 303 def __init__(self, start_or_end=None, end=None, step=1): 304 305 "Initialise the slice with the given 'start_or_end', 'end' and 'step'." 306 307 xrange.__init__(self, start_or_end, end, step) 308 309 # Exceptions and warnings. 310 311 class BaseException(object): 312 313 "Implementation of BaseException." 314 315 def __init__(self, *args): 316 self.args = args 317 318 class Exception(BaseException): pass 319 class Warning(object): pass 320 321 class ArithmeticError(Exception): pass 322 class AssertionError(Exception): pass 323 class AttributeError(Exception): pass 324 class DeprecationWarning(Exception): pass 325 class EOFError(Exception): pass 326 class EnvironmentError(Exception): pass 327 class FloatingPointError(Exception): pass 328 class FutureWarning(Warning): pass 329 class GeneratorExit(Exception): pass 330 class ImportError(Exception): pass 331 class ImportWarning(Warning): pass 332 class IndentationError(Exception): pass 333 class IndexError(Exception): pass 334 class IOError(Exception): pass 335 class KeyError(Exception): pass 336 class KeyboardInterrupt(Exception): pass 337 class LookupError(Exception): pass 338 class MemoryError(Exception): pass 339 class NameError(Exception): pass 340 class NotImplementedError(Exception): pass 341 class OSError(Exception): pass 342 class OverflowError(Exception): pass 343 class PendingDeprecationWarning(Warning): pass 344 class ReferenceError(Exception): pass 345 class RuntimeError(Exception): pass 346 class RuntimeWarning(Warning): pass 347 class StandardError(Exception): pass 348 class StopIteration(Exception): "Implementation of StopIteration." 349 class SyntaxError(Exception): pass 350 class SyntaxWarning(Warning): pass 351 class SystemError(Exception): pass 352 class SystemExit(Exception): pass 353 class TabError(Exception): pass 354 class TypeError(Exception): pass 355 class UnboundLocalError(Exception): pass 356 class UnicodeDecodeError(Exception): pass 357 class UnicodeEncodeError(Exception): pass 358 class UnicodeError(Exception): pass 359 class UnicodeTranslateError(Exception): pass 360 class UnicodeWarning(Warning): pass 361 class UserWarning(Warning): pass 362 class ValueError(Exception): pass 363 class ZeroDivisionError(Exception): pass 364 365 # Various types. 366 367 #class ellipsis: pass 368 class NoneType: pass 369 class NotImplementedType: pass 370 371 # General functions. 372 # NOTE: Some of these are actually provided by classes in CPython. 373 # NOTE: We may refuse to support some of these in practice, such as... 374 # NOTE: super, reload. 375 376 def __import__(name, globals=None, locals=None, fromlist=None, level=-1): pass 377 def abs(number): pass 378 def all(iterable): pass 379 def any(iterable): pass 380 def callable(obj): pass 381 def chr(i): pass 382 def classmethod(function): pass 383 def cmp(x, y): pass 384 def compile(source, filename, mode, flags=None, dont_inherit=None): pass 385 def delattr(obj, name): pass 386 def dir(obj=None): pass 387 def divmod(x, y): pass 388 def enumerate(iterable): pass 389 def eval(source, globals=None, locals=None): pass 390 def execfile(filename, globals=None, locals=None): pass 391 def filter(function, sequence): pass 392 def getattr(obj, name, default=None): pass 393 def globals(): pass 394 def hasattr(obj, name): pass 395 def hash(obj): pass 396 def help(*args): pass 397 def hex(number): pass 398 def id(obj): pass 399 def input(prompt=None): pass 400 def isinstance(obj, cls_or_tuple): pass 401 def issubclass(obj, cls_or_tuple): pass 402 403 def iter(collection): 404 405 "Implementation of iter without callable plus sentinel support." 406 407 return collection.__iter__() 408 409 def len(obj): 410 411 "Implementation of len." 412 413 return obj.__len__() 414 415 def locals(): pass 416 417 def map(function, *args): pass 418 419 def max(*args): 420 421 "Implementation of max." 422 423 highest = args[0] 424 for arg in args[1:]: 425 if arg > highest: 426 highest = arg 427 return highest 428 429 def min(*args): 430 431 "Implementation of min." 432 433 lowest = args[0] 434 for arg in args[1:]: 435 if arg > lowest: 436 lowest = arg 437 return lowest 438 439 def oct(number): pass 440 def open(name, mode=None, buffering=None): pass 441 def ord(c): pass 442 def pow(x, y, z=None): pass 443 def property(fget=None, fset=None, fdel=None, doc=None): pass 444 445 def range(start_or_end, end=None, step=1): 446 447 "Implementation of range." 448 449 l = [] 450 for i in xrange(start_or_end, end, step): 451 l.append(i) 452 return l 453 454 def raw_input(prompt=None): pass 455 def reduce(function, sequence, initial=None): pass 456 def reload(module): pass 457 def repr(obj): pass 458 def reversed(sequence): pass 459 def round(number, ndigits=None): pass 460 def setattr(obj, name, value): pass 461 def sorted(iterable, cmp=None, key=None, reverse=False): pass 462 def staticmethod(function): pass 463 def sum(sequence, start=0): pass 464 def super(*args): pass 465 def unichr(i): pass 466 def vars(obj=None): pass 467 def zip(*args): pass 468 469 # Reference some names to ensure their existence. This should be everything 470 # mentioned in a get_builtin or load_builtin call. Instances from this module 471 # should be predefined constants. 472 473 function 474 AttributeError 475 #StopIteration 476 TypeError 477 IndexError 478 479 list 480 tuple 481 #xrange 482 #ellipsis 483 #bool 484 485 # vim: tabstop=4 expandtab shiftwidth=4