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