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, 2010 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 NO_END = object() 296 297 def __init__(self, start_or_end, end=NO_END, step=1): 298 299 "Initialise the xrange with the given 'start_or_end', 'end' and 'step'." 300 301 if end is xrange.NO_END: 302 self.start = 0 303 self.end = start_or_end 304 else: 305 self.start = start_or_end 306 self.end = end 307 308 self.step = step 309 self.current = self.start 310 self.limited = self.end is not xrange.NO_END 311 312 def __iter__(self): 313 314 "Return an iterator, currently self." 315 316 return self 317 318 def next(self): 319 320 "Return the next item or raise a StopIteration exception." 321 322 if self.limited: 323 if self.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end: 324 raise StopIteration() 325 326 current = self.current 327 self.current += self.step 328 return current 329 330 class slice(xrange): 331 332 "Implementation of slice." 333 334 def __init__(self, start_or_end=None, end=xrange.NO_END, step=1): 335 336 "Initialise the slice with the given 'start_or_end', 'end' and 'step'." 337 338 xrange.__init__(self, start_or_end, end, step) 339 340 # Exceptions and warnings. 341 342 class BaseException(object): 343 344 "Implementation of BaseException." 345 346 def __init__(self, *args): 347 self.args = args 348 349 class Exception(BaseException): pass 350 class Warning(object): pass 351 352 class ArithmeticError(Exception): pass 353 class AssertionError(Exception): pass 354 class AttributeError(Exception): pass 355 class DeprecationWarning(Exception): pass 356 class EOFError(Exception): pass 357 class EnvironmentError(Exception): pass 358 class FloatingPointError(Exception): pass 359 class FutureWarning(Warning): pass 360 class GeneratorExit(Exception): pass 361 class ImportError(Exception): pass 362 class ImportWarning(Warning): pass 363 class IndentationError(Exception): pass 364 class IndexError(Exception): pass 365 class IOError(Exception): pass 366 class KeyError(Exception): pass 367 class KeyboardInterrupt(Exception): pass 368 class LookupError(Exception): pass 369 class MemoryError(Exception): pass 370 class NameError(Exception): pass 371 class NotImplementedError(Exception): pass 372 class OSError(Exception): pass 373 class OverflowError(Exception): pass 374 class PendingDeprecationWarning(Warning): pass 375 class ReferenceError(Exception): pass 376 class RuntimeError(Exception): pass 377 class RuntimeWarning(Warning): pass 378 class StandardError(Exception): pass 379 class StopIteration(Exception): "Implementation of StopIteration." 380 class SyntaxError(Exception): pass 381 class SyntaxWarning(Warning): pass 382 class SystemError(Exception): pass 383 class SystemExit(Exception): pass 384 class TabError(Exception): pass 385 class TypeError(Exception): pass 386 class UnboundLocalError(Exception): pass 387 class UnicodeDecodeError(Exception): pass 388 class UnicodeEncodeError(Exception): pass 389 class UnicodeError(Exception): pass 390 class UnicodeTranslateError(Exception): pass 391 class UnicodeWarning(Warning): pass 392 class UserWarning(Warning): pass 393 class ValueError(Exception): pass 394 class ZeroDivisionError(Exception): pass 395 396 # Various types. 397 398 #class ellipsis: pass 399 class NoneType: pass 400 class NotImplementedType: pass 401 402 # General functions. 403 # NOTE: Some of these are actually provided by classes in CPython. 404 # NOTE: We may refuse to support some of these in practice, such as... 405 # NOTE: __import__, super, reload. 406 407 def abs(number): pass 408 def all(iterable): pass 409 def any(iterable): pass 410 def callable(obj): pass 411 def chr(i): pass 412 def classmethod(function): pass 413 def cmp(x, y): pass 414 def compile(source, filename, mode, flags=None, dont_inherit=None): pass 415 def delattr(obj, name): pass 416 def dir(obj=None): pass 417 def divmod(x, y): pass 418 def enumerate(iterable): pass 419 def eval(source, globals=None, locals=None): pass 420 def execfile(filename, globals=None, locals=None): pass 421 def filter(function, sequence): pass 422 def getattr(obj, name, default=None): pass 423 def globals(): pass 424 def hasattr(obj, name): pass 425 def hash(obj): pass 426 def help(*args): pass 427 def hex(number): pass 428 def id(obj): pass 429 def input(prompt=None): pass 430 def isinstance(obj, cls_or_tuple): pass 431 def issubclass(obj, cls_or_tuple): pass 432 433 def iter(collection): 434 435 "Implementation of iter without callable plus sentinel support." 436 437 return collection.__iter__() 438 439 def len(obj): 440 441 "Implementation of len." 442 443 return obj.__len__() 444 445 def locals(): pass 446 447 def map(function, *args): pass 448 449 def max(*args): 450 451 "Implementation of max." 452 453 highest = args[0] 454 for arg in args[1:]: 455 if arg > highest: 456 highest = arg 457 return highest 458 459 def min(*args): 460 461 "Implementation of min." 462 463 lowest = args[0] 464 for arg in args[1:]: 465 if arg > lowest: 466 lowest = arg 467 return lowest 468 469 def oct(number): pass 470 def open(name, mode=None, buffering=None): pass 471 def ord(c): pass 472 def pow(x, y, z=None): pass 473 def property(fget=None, fset=None, fdel=None, doc=None): pass 474 475 def range(start_or_end, end=None, step=1): 476 477 "Implementation of range." 478 479 return list(xrange(start_or_end, end, step)) 480 481 def raw_input(prompt=None): pass 482 def reduce(function, sequence, initial=None): pass 483 def reload(module): pass 484 def repr(obj): pass 485 def reversed(sequence): pass 486 def round(number, ndigits=None): pass 487 def setattr(obj, name, value): pass 488 def sorted(iterable, cmp=None, key=None, reverse=False): pass 489 def staticmethod(function): pass 490 def sum(sequence, start=0): pass 491 def super(*args): pass 492 def unichr(i): pass 493 def vars(obj=None): pass 494 def zip(*args): pass 495 496 # Reference some names to ensure their existence. This should be everything 497 # mentioned in a get_builtin or load_builtin call. Instances from this module 498 # should be predefined constants. 499 500 function 501 AttributeError 502 #StopIteration 503 TypeError 504 #IndexError 505 506 #list 507 tuple 508 #xrange 509 #ellipsis 510 #bool 511 512 # vim: tabstop=4 expandtab shiftwidth=4