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