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