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