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 class slice(object): 237 def __init__(self, start_or_end, end=None, step=None): pass 238 239 class str(basestring): 240 pass 241 242 class type(object): 243 pass 244 245 class tuple(object): 246 def __init__(self, args): pass 247 def __getitem__(self, index): pass 248 def __getslice__(self, start, end=None): pass 249 def __len__(self): pass 250 def __add__(self, other): pass 251 def __str__(self): pass 252 def __bool__(self): pass 253 254 def __iter__(self): 255 256 "Return an iterator." 257 258 return listiterator(self) 259 260 class unicode(basestring): 261 pass 262 263 class xrange(object): 264 265 "Implementation of xrange." 266 267 def __init__(self, start_or_end, end=None, step=1): 268 269 "Initialise the xrange with the given 'start_or_end', 'end' and 'step'." 270 271 if end is None: 272 self.start = 0 273 self.end = start_or_end 274 else: 275 self.start = start_or_end 276 self.end = end 277 278 self.step = step 279 self.current = self.start 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.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end: 292 raise StopIteration() 293 294 current = self.current 295 self.current += self.step 296 return current 297 298 # Exceptions and warnings. 299 300 class BaseException(object): 301 302 "Implementation of BaseException." 303 304 def __init__(self, *args): 305 self.args = args 306 307 class Exception(BaseException): pass 308 class Warning(object): pass 309 310 class ArithmeticError(Exception): pass 311 class AssertionError(Exception): pass 312 class AttributeError(Exception): pass 313 class DeprecationWarning(Exception): pass 314 class EOFError(Exception): pass 315 class EnvironmentError(Exception): pass 316 class FloatingPointError(Exception): pass 317 class FutureWarning(Warning): pass 318 class GeneratorExit(Exception): pass 319 class ImportError(Exception): pass 320 class ImportWarning(Warning): pass 321 class IndentationError(Exception): pass 322 class IndexError(Exception): pass 323 class IOError(Exception): pass 324 class KeyError(Exception): pass 325 class KeyboardInterrupt(Exception): pass 326 class LookupError(Exception): pass 327 class MemoryError(Exception): pass 328 class NameError(Exception): pass 329 class NotImplementedError(Exception): pass 330 class OSError(Exception): pass 331 class OverflowError(Exception): pass 332 class PendingDeprecationWarning(Warning): pass 333 class ReferenceError(Exception): pass 334 class RuntimeError(Exception): pass 335 class RuntimeWarning(Warning): pass 336 class StandardError(Exception): pass 337 class StopIteration(Exception): "Implementation of StopIteration." 338 class SyntaxError(Exception): pass 339 class SyntaxWarning(Warning): pass 340 class SystemError(Exception): pass 341 class SystemExit(Exception): pass 342 class TabError(Exception): pass 343 class TypeError(Exception): pass 344 class UnboundLocalError(Exception): pass 345 class UnicodeDecodeError(Exception): pass 346 class UnicodeEncodeError(Exception): pass 347 class UnicodeError(Exception): pass 348 class UnicodeTranslateError(Exception): pass 349 class UnicodeWarning(Warning): pass 350 class UserWarning(Warning): pass 351 class ValueError(Exception): pass 352 class ZeroDivisionError(Exception): pass 353 354 # Various types. 355 356 #class ellipsis: pass 357 class NoneType: pass 358 class NotImplementedType: pass 359 360 # General functions. 361 # NOTE: Some of these are actually provided by classes in CPython. 362 # NOTE: We may refuse to support some of these in practice, such as... 363 # NOTE: super, reload. 364 365 def __import__(name, globals=None, locals=None, fromlist=None, level=-1): pass 366 def abs(number): pass 367 def all(iterable): pass 368 def any(iterable): pass 369 def callable(obj): pass 370 def chr(i): pass 371 def classmethod(function): pass 372 def cmp(x, y): pass 373 def compile(source, filename, mode, flags=None, dont_inherit=None): pass 374 def delattr(obj, name): pass 375 def dir(obj=None): pass 376 def divmod(x, y): pass 377 def enumerate(iterable): pass 378 def eval(source, globals=None, locals=None): pass 379 def execfile(filename, globals=None, locals=None): pass 380 def filter(function, sequence): pass 381 def getattr(obj, name, default=None): pass 382 def globals(): pass 383 def hasattr(obj, name): pass 384 def hash(obj): pass 385 def help(*args): pass 386 def hex(number): pass 387 def id(obj): pass 388 def input(prompt=None): pass 389 def isinstance(obj, cls_or_tuple): pass 390 def issubclass(obj, cls_or_tuple): pass 391 392 def iter(collection): 393 394 "Implementation of iter without callable plus sentinel support." 395 396 return collection.__iter__() 397 398 def len(obj): 399 400 "Implementation of len." 401 402 return obj.__len__() 403 404 def locals(): pass 405 def map(function, *args): pass 406 def max(*args): pass 407 def min(*args): pass 408 def oct(number): pass 409 def open(name, mode=None, buffering=None): pass 410 def ord(c): pass 411 def pow(x, y, z=None): pass 412 def property(fget=None, fset=None, fdel=None, doc=None): pass 413 414 def range(start_or_end, end=None, step=1): 415 416 "Implementation of range." 417 418 l = [] 419 for i in xrange(start_or_end, end, step): 420 l.append(i) 421 return l 422 423 def raw_input(prompt=None): pass 424 def reduce(function, sequence, initial=None): pass 425 def reload(module): pass 426 def repr(obj): pass 427 def reversed(sequence): pass 428 def round(number, ndigits=None): pass 429 def setattr(obj, name, value): pass 430 def sorted(iterable, cmp=None, key=None, reverse=False): pass 431 def staticmethod(function): pass 432 def sum(sequence, start=0): pass 433 def super(*args): pass 434 def unichr(i): pass 435 def vars(obj=None): pass 436 def zip(*args): pass 437 438 # Reference some names to ensure their existence. This should be everything 439 # mentioned in a get_builtin or load_builtin call. Instances from this module 440 # should be predefined constants. 441 442 function 443 AttributeError 444 StopIteration 445 TypeError 446 IndexError 447 448 list 449 tuple 450 #xrange 451 #ellipsis 452 #bool 453 454 # vim: tabstop=4 expandtab shiftwidth=4