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