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 self._elements = None # defined in a native method 161 162 def __getitem__(self, index): pass 163 def __setitem__(self, index, value): pass 164 def __getslice__(self, start, end=None): pass 165 def __setslice__(self, start, end, slice): pass 166 def append(self, value): pass 167 def __len__(self): pass 168 def __add__(self, other): pass 169 def __iadd__(self, other): pass 170 def __str__(self): pass 171 def __bool__(self): pass 172 173 def __iter__(self): 174 175 "Return an iterator." 176 177 return listiterator(self) 178 179 class listiterator(object): 180 181 "Implementation of listiterator." 182 183 def __init__(self, l): 184 185 "Initialise with the given list 'l'." 186 187 self.l = l 188 self.i = 0 189 190 def next(self): 191 192 "Return the next item." 193 194 try: 195 value = self.l[self.i] 196 self.i += 1 197 return value 198 except IndexError: 199 raise StopIteration 200 201 class long(object): 202 def __init__(self, number_or_string=None): pass 203 def __iadd__(self, other): pass 204 def __isub__(self, other): pass 205 def __add__(self, other): pass 206 def __radd__(self, other): pass 207 def __sub__(self, other): pass 208 def __rsub__(self, other): pass 209 def __mul__(self, other): pass 210 def __rmul__(self, other): pass 211 def __div__(self, other): pass 212 def __rdiv__(self, other): pass 213 def __floordiv__(self, other): pass 214 def __rfloordiv__(self, other): pass 215 def __and__(self, other): pass 216 def __rand__(self, other): pass 217 def __or__(self, other): pass 218 def __ror__(self, other): pass 219 def __xor__(self, other): pass 220 def __rxor__(self, other): pass 221 def __lt__(self, other): pass 222 def __gt__(self, other): pass 223 def __le__(self, other): pass 224 def __ge__(self, other): pass 225 def __eq__(self, other): pass 226 def __ne__(self, other): pass 227 def __neg__(self): pass 228 def __pos__(self): pass 229 def __str__(self): pass 230 def __bool__(self): pass 231 232 class set(object): 233 def __init__(self, iterable): pass 234 235 class slice(object): 236 def __init__(self, start_or_end, end=None, step=None): pass 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 __iter__(self): pass 252 def __bool__(self): pass 253 254 class unicode(basestring): 255 pass 256 257 class xrange(object): 258 259 "Implementation of xrange." 260 261 def __init__(self, start_or_end, end=None, step=1): 262 263 "Initialise the xrange with the given 'start_or_end', 'end' and 'step'." 264 265 if end is None: 266 self.start = 0 267 self.end = start_or_end 268 else: 269 self.start = start_or_end 270 self.end = end 271 272 self.step = step 273 self.current = self.start 274 275 def __iter__(self): 276 277 "Return an iterator, currently self." 278 279 return self 280 281 def next(self): 282 283 "Return the next item or raise a StopIteration exception." 284 285 if self.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end: 286 raise StopIteration() 287 288 current = self.current 289 self.current += self.step 290 return current 291 292 # Exceptions and warnings. 293 294 class BaseException(object): 295 296 "Implementation of BaseException." 297 298 def __init__(self, *args): 299 self.args = args 300 301 class Exception(BaseException): pass 302 class Warning(object): pass 303 304 class ArithmeticError(Exception): pass 305 class AssertionError(Exception): pass 306 class AttributeError(Exception): pass 307 class DeprecationWarning(Exception): pass 308 class EOFError(Exception): pass 309 class EnvironmentError(Exception): pass 310 class FloatingPointError(Exception): pass 311 class FutureWarning(Warning): pass 312 class GeneratorExit(Exception): pass 313 class ImportError(Exception): pass 314 class ImportWarning(Warning): pass 315 class IndentationError(Exception): pass 316 class IndexError(Exception): pass 317 class IOError(Exception): pass 318 class KeyError(Exception): pass 319 class KeyboardInterrupt(Exception): pass 320 class LookupError(Exception): pass 321 class MemoryError(Exception): pass 322 class NameError(Exception): pass 323 class NotImplementedError(Exception): pass 324 class OSError(Exception): pass 325 class OverflowError(Exception): pass 326 class PendingDeprecationWarning(Warning): pass 327 class ReferenceError(Exception): pass 328 class RuntimeError(Exception): pass 329 class RuntimeWarning(Warning): pass 330 class StandardError(Exception): pass 331 class StopIteration(Exception): "Implementation of StopIteration." 332 class SyntaxError(Exception): pass 333 class SyntaxWarning(Warning): pass 334 class SystemError(Exception): pass 335 class SystemExit(Exception): pass 336 class TabError(Exception): pass 337 class TypeError(Exception): pass 338 class UnboundLocalError(Exception): pass 339 class UnicodeDecodeError(Exception): pass 340 class UnicodeEncodeError(Exception): pass 341 class UnicodeError(Exception): pass 342 class UnicodeTranslateError(Exception): pass 343 class UnicodeWarning(Warning): pass 344 class UserWarning(Warning): pass 345 class ValueError(Exception): pass 346 class ZeroDivisionError(Exception): pass 347 348 # Various types. 349 350 #class ellipsis: pass 351 class NoneType: pass 352 class NotImplementedType: pass 353 354 # General functions. 355 # NOTE: Some of these are actually provided by classes in CPython. 356 # NOTE: We may refuse to support some of these in practice, such as... 357 # NOTE: super, reload. 358 359 def __import__(name, globals=None, locals=None, fromlist=None, level=-1): pass 360 def abs(number): pass 361 def all(iterable): pass 362 def any(iterable): pass 363 def callable(obj): pass 364 def chr(i): pass 365 def classmethod(function): pass 366 def cmp(x, y): pass 367 def compile(source, filename, mode, flags=None, dont_inherit=None): pass 368 def delattr(obj, name): pass 369 def dir(obj=None): pass 370 def divmod(x, y): pass 371 def enumerate(iterable): pass 372 def eval(source, globals=None, locals=None): pass 373 def execfile(filename, globals=None, locals=None): pass 374 def filter(function, sequence): pass 375 def getattr(obj, name, default=None): pass 376 def globals(): pass 377 def hasattr(obj, name): pass 378 def hash(obj): pass 379 def help(*args): pass 380 def hex(number): pass 381 def id(obj): pass 382 def input(prompt=None): pass 383 def isinstance(obj, cls_or_tuple): pass 384 def issubclass(obj, cls_or_tuple): pass 385 386 def iter(collection): 387 388 "Implementation of iter without callable plus sentinel support." 389 390 return collection.__iter__() 391 392 def len(obj): 393 394 "Implementation of len." 395 396 return obj.__len__() 397 398 def locals(): pass 399 def map(function, *args): pass 400 def max(*args): pass 401 def min(*args): pass 402 def oct(number): pass 403 def open(name, mode=None, buffering=None): pass 404 def ord(c): pass 405 def pow(x, y, z=None): pass 406 def property(fget=None, fset=None, fdel=None, doc=None): pass 407 408 def range(start_or_end, end=None, step=1): 409 410 "Implementation of range." 411 412 l = [] 413 for i in xrange(start_or_end, end, step): 414 l.append(i) 415 return l 416 417 def raw_input(prompt=None): pass 418 def reduce(function, sequence, initial=None): pass 419 def reload(module): pass 420 def repr(obj): pass 421 def reversed(sequence): pass 422 def round(number, ndigits=None): pass 423 def setattr(obj, name, value): pass 424 def sorted(iterable, cmp=None, key=None, reverse=False): pass 425 def staticmethod(function): pass 426 def sum(sequence, start=0): pass 427 def super(*args): pass 428 def unichr(i): pass 429 def vars(obj=None): pass 430 def zip(*args): pass 431 432 # Reference some names to ensure their existence. This should be everything 433 # mentioned in a get_builtin or load_builtin call. Instances from this module 434 # should be predefined constants. 435 436 function 437 AttributeError 438 StopIteration 439 TypeError 440 IndexError 441 442 list 443 tuple 444 #xrange 445 #ellipsis 446 #bool 447 448 # vim: tabstop=4 expandtab shiftwidth=4