paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | """ |
paul@0 | 4 | Inspect source files, obtaining details of classes and attributes. |
paul@0 | 5 | |
paul@0 | 6 | Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 7 | |
paul@0 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@0 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@0 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@0 | 11 | version. |
paul@0 | 12 | |
paul@0 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@0 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@0 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@0 | 16 | details. |
paul@0 | 17 | |
paul@0 | 18 | You should have received a copy of the GNU General Public License along with |
paul@0 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@0 | 20 | """ |
paul@0 | 21 | |
paul@0 | 22 | import compiler.ast |
paul@0 | 23 | from compiler.visitor import ASTVisitor |
paul@0 | 24 | try: |
paul@0 | 25 | set |
paul@0 | 26 | except NameError: |
paul@0 | 27 | from sets import Set as set |
paul@0 | 28 | |
paul@0 | 29 | class InspectError(Exception): |
paul@0 | 30 | |
paul@0 | 31 | "An inspection error." |
paul@0 | 32 | |
paul@0 | 33 | pass |
paul@0 | 34 | |
paul@3 | 35 | class NamespaceDict: |
paul@3 | 36 | |
paul@3 | 37 | "A mix-in providing dictionary methods." |
paul@3 | 38 | |
paul@3 | 39 | def __getitem__(self, name): |
paul@3 | 40 | return self.namespace[name] |
paul@3 | 41 | |
paul@3 | 42 | def keys(self): |
paul@3 | 43 | return self.namespace.keys() |
paul@3 | 44 | |
paul@7 | 45 | def values(self): |
paul@7 | 46 | return self.namespace.values() |
paul@7 | 47 | |
paul@7 | 48 | def items(self): |
paul@7 | 49 | return self.namespace.items() |
paul@7 | 50 | |
paul@4 | 51 | class Naming: |
paul@4 | 52 | |
paul@4 | 53 | "A mix-in providing naming conveniences." |
paul@4 | 54 | |
paul@4 | 55 | def full_name(self): |
paul@4 | 56 | if self.name is not None: |
paul@7 | 57 | return self.parent_name + "." + self.name |
paul@4 | 58 | else: |
paul@7 | 59 | return self.parent_name |
paul@4 | 60 | |
paul@4 | 61 | class Class(NamespaceDict, Naming): |
paul@0 | 62 | |
paul@0 | 63 | "An inspected class." |
paul@0 | 64 | |
paul@7 | 65 | def __init__(self, name, parent_name): |
paul@0 | 66 | self.name = name |
paul@7 | 67 | self.parent_name = parent_name |
paul@0 | 68 | self.bases = [] |
paul@0 | 69 | self.namespace = {} |
paul@0 | 70 | self.instattr = set() |
paul@7 | 71 | self.instattr_names = [] # from instattr |
paul@0 | 72 | |
paul@0 | 73 | def add_base(self, base): |
paul@0 | 74 | self.bases.append(base) |
paul@0 | 75 | |
paul@4 | 76 | def __repr__(self): |
paul@7 | 77 | return "Class(%r, %r)" % (self.name, self.parent_name) |
paul@4 | 78 | |
paul@4 | 79 | def class_attributes(self): |
paul@4 | 80 | |
paul@4 | 81 | "Return all class attributes, indicating the class which provides them." |
paul@4 | 82 | |
paul@4 | 83 | attr = {} |
paul@4 | 84 | reversed_bases = self.bases[:] |
paul@4 | 85 | reversed_bases.reverse() |
paul@4 | 86 | for cls in reversed_bases: |
paul@4 | 87 | attr.update(cls.class_attributes()) |
paul@4 | 88 | for name, value in self.namespace.items(): |
paul@4 | 89 | attr[name] = self.full_name() |
paul@4 | 90 | return attr |
paul@4 | 91 | |
paul@7 | 92 | def instance_attribute_names(self): |
paul@7 | 93 | |
paul@7 | 94 | "Return the instance attribute names provided by the class." |
paul@7 | 95 | |
paul@7 | 96 | self.instattr_names = self.instattr_names or list(self.instattr) |
paul@7 | 97 | return self.instattr_names |
paul@7 | 98 | |
paul@4 | 99 | def instance_attributes(self): |
paul@4 | 100 | |
paul@4 | 101 | """ |
paul@4 | 102 | Return all attributes for an instance, indicating either the class which |
paul@4 | 103 | provides them or that the instance itself provides them. |
paul@4 | 104 | """ |
paul@4 | 105 | |
paul@4 | 106 | attr = {} |
paul@4 | 107 | attr.update(self.class_attributes()) |
paul@7 | 108 | for i, name in enumerate(self.instance_attribute_names()): |
paul@4 | 109 | if attr.has_key(name): |
paul@7 | 110 | print "Instance attribute %r in %r overrides class attribute." % (name, self) |
paul@5 | 111 | attr[name] = i |
paul@4 | 112 | return attr |
paul@4 | 113 | |
paul@7 | 114 | class Function(Naming): |
paul@0 | 115 | |
paul@0 | 116 | "An inspected function." |
paul@0 | 117 | |
paul@7 | 118 | def __init__(self, name, parent_name, argnames, has_star, has_dstar): |
paul@3 | 119 | self.name = name |
paul@7 | 120 | self.parent_name = parent_name |
paul@3 | 121 | self.argnames = argnames |
paul@3 | 122 | self.has_star = has_star |
paul@3 | 123 | self.has_dstar = has_dstar |
paul@3 | 124 | |
paul@4 | 125 | def __repr__(self): |
paul@4 | 126 | return "Function(%r, %r, %r, %r, %r)" % ( |
paul@7 | 127 | self.name, self.parent_name, self.argnames, self.has_star, self.has_dstar |
paul@4 | 128 | ) |
paul@4 | 129 | |
paul@7 | 130 | def parameters(self): |
paul@7 | 131 | |
paul@7 | 132 | """ |
paul@7 | 133 | Return a dictionary mapping parameter names to their position in the |
paul@7 | 134 | parameter list. |
paul@7 | 135 | """ |
paul@7 | 136 | |
paul@7 | 137 | parameters = {} |
paul@7 | 138 | for i, name in enumerate(self.argnames): |
paul@7 | 139 | parameters[name] = i |
paul@7 | 140 | return parameters |
paul@7 | 141 | |
paul@4 | 142 | class UnresolvedName(NamespaceDict, Naming): |
paul@3 | 143 | |
paul@3 | 144 | "A module, class or function which was mentioned but could not be imported." |
paul@3 | 145 | |
paul@7 | 146 | def __init__(self, name, parent_name): |
paul@0 | 147 | self.name = name |
paul@7 | 148 | self.parent_name = parent_name |
paul@3 | 149 | self.namespace = {} |
paul@0 | 150 | |
paul@7 | 151 | def class_attributes(self): |
paul@7 | 152 | return {} |
paul@7 | 153 | |
paul@4 | 154 | def __repr__(self): |
paul@7 | 155 | return "UnresolvedName(%r, %r)" % (self.name, self.parent_name) |
paul@4 | 156 | |
paul@3 | 157 | class Module(ASTVisitor, NamespaceDict): |
paul@0 | 158 | |
paul@0 | 159 | "An inspected module." |
paul@0 | 160 | |
paul@1 | 161 | def __init__(self, name, importer=None): |
paul@0 | 162 | ASTVisitor.__init__(self) |
paul@0 | 163 | self.visitor = self |
paul@0 | 164 | |
paul@1 | 165 | self.name = name |
paul@0 | 166 | self.importer = importer |
paul@2 | 167 | self.loaded = 0 |
paul@0 | 168 | |
paul@1 | 169 | # Module namespace. |
paul@1 | 170 | |
paul@0 | 171 | self.namespace = {} |
paul@7 | 172 | self.namespace_names = [] # from namespace |
paul@7 | 173 | |
paul@7 | 174 | # Complete lists of classes and functions. |
paul@7 | 175 | |
paul@7 | 176 | self.all_objects = [] |
paul@0 | 177 | |
paul@1 | 178 | # Current expression state. |
paul@1 | 179 | |
paul@1 | 180 | self.expr = None |
paul@1 | 181 | |
paul@1 | 182 | # Namespace state. |
paul@1 | 183 | |
paul@0 | 184 | self.in_global = 1 |
paul@0 | 185 | self.in_init = 0 |
paul@0 | 186 | self.classes = [] |
paul@0 | 187 | self.module = None |
paul@0 | 188 | |
paul@0 | 189 | def parse(self, filename): |
paul@0 | 190 | module = compiler.parseFile(filename) |
paul@0 | 191 | self.process(module) |
paul@0 | 192 | |
paul@0 | 193 | def process(self, module): |
paul@0 | 194 | self.module = module |
paul@1 | 195 | processed = self.dispatch(module) |
paul@1 | 196 | if self.namespace.has_key("__all__"): |
paul@1 | 197 | all = self.namespace["__all__"] |
paul@1 | 198 | if isinstance(all, compiler.ast.List): |
paul@1 | 199 | for n in all.nodes: |
paul@1 | 200 | self.namespace[n.value] = self.importer.add_module(self.name + "." + n.value) |
paul@1 | 201 | return processed |
paul@0 | 202 | |
paul@3 | 203 | def vacuum(self): |
paul@3 | 204 | for name, value in self.namespace.items(): |
paul@3 | 205 | if isinstance(value, Module) and not value.loaded: |
paul@3 | 206 | del self.namespace[name] |
paul@0 | 207 | |
paul@4 | 208 | def full_name(self): |
paul@4 | 209 | return self.name |
paul@4 | 210 | |
paul@4 | 211 | def __repr__(self): |
paul@4 | 212 | return "Module(%r)" % self.name |
paul@4 | 213 | |
paul@7 | 214 | # Attribute methods. |
paul@7 | 215 | |
paul@7 | 216 | def module_attribute_names(self): |
paul@7 | 217 | |
paul@7 | 218 | "Return the module attribute names provided by the module." |
paul@7 | 219 | |
paul@7 | 220 | self.namespace_names = self.namespace_names or self.namespace.keys() |
paul@7 | 221 | return self.namespace_names |
paul@7 | 222 | |
paul@7 | 223 | def module_attributes(self): |
paul@7 | 224 | |
paul@7 | 225 | """ |
paul@7 | 226 | Return a dictionary mapping module attributes to a position in the |
paul@7 | 227 | module's namespace. |
paul@7 | 228 | """ |
paul@7 | 229 | |
paul@7 | 230 | attributes = {} |
paul@7 | 231 | for i, name in enumerate(self.module_attribute_names()): |
paul@7 | 232 | attributes[name] = i |
paul@7 | 233 | return attributes |
paul@7 | 234 | |
paul@3 | 235 | # Namespace methods. |
paul@0 | 236 | |
paul@0 | 237 | def store(self, name, obj): |
paul@0 | 238 | if self.in_global: |
paul@0 | 239 | if not self.classes: |
paul@0 | 240 | self.namespace[name] = obj |
paul@0 | 241 | else: |
paul@0 | 242 | self.classes[-1].namespace[name] = obj |
paul@7 | 243 | self.all_objects.append(obj) |
paul@0 | 244 | |
paul@0 | 245 | def store_attr(self, name): |
paul@0 | 246 | if self.in_init: |
paul@0 | 247 | self.classes[-1].instattr.add(name) |
paul@0 | 248 | |
paul@7 | 249 | def get_parent(self): |
paul@7 | 250 | return (self.classes[-1:] or [self])[0] |
paul@7 | 251 | |
paul@3 | 252 | # Visitor methods. |
paul@3 | 253 | |
paul@3 | 254 | def default(self, node, *args): |
paul@3 | 255 | raise InspectError, node.__class__ |
paul@3 | 256 | |
paul@3 | 257 | def dispatch(self, node, *args): |
paul@3 | 258 | return ASTVisitor.dispatch(self, node, *args) |
paul@3 | 259 | |
paul@0 | 260 | def NOP(self, node): |
paul@0 | 261 | return node |
paul@0 | 262 | |
paul@1 | 263 | visitAdd = NOP |
paul@1 | 264 | |
paul@0 | 265 | visitAnd = NOP |
paul@0 | 266 | |
paul@4 | 267 | visitAssert = NOP |
paul@4 | 268 | |
paul@0 | 269 | def visitAssign(self, node): |
paul@0 | 270 | self.expr = self.dispatch(node.expr) |
paul@0 | 271 | for n in node.nodes: |
paul@0 | 272 | self.dispatch(n) |
paul@0 | 273 | return None |
paul@0 | 274 | |
paul@0 | 275 | def visitAssAttr(self, node): |
paul@0 | 276 | expr = self.dispatch(node.expr) |
paul@0 | 277 | if expr is not None and isinstance(expr, Self): |
paul@0 | 278 | self.store_attr(node.attrname) |
paul@0 | 279 | return None |
paul@0 | 280 | |
paul@0 | 281 | def visitAssList(self, node): |
paul@0 | 282 | for n in node.nodes: |
paul@0 | 283 | self.dispatch(n) |
paul@0 | 284 | return None |
paul@0 | 285 | |
paul@0 | 286 | def visitAssName(self, node): |
paul@0 | 287 | self.store(node.name, self.expr) |
paul@0 | 288 | return None |
paul@0 | 289 | |
paul@0 | 290 | visitAssTuple = visitAssList |
paul@0 | 291 | |
paul@2 | 292 | visitAugAssign = NOP |
paul@2 | 293 | |
paul@4 | 294 | visitBackquote = NOP |
paul@4 | 295 | |
paul@2 | 296 | visitBitand = NOP |
paul@2 | 297 | |
paul@2 | 298 | visitBitor = NOP |
paul@2 | 299 | |
paul@4 | 300 | visitBitxor = NOP |
paul@4 | 301 | |
paul@4 | 302 | visitBreak = NOP |
paul@4 | 303 | |
paul@0 | 304 | visitCallFunc = NOP |
paul@0 | 305 | |
paul@0 | 306 | def visitClass(self, node): |
paul@0 | 307 | if not self.in_global: |
paul@4 | 308 | print "Class %r in %r is not global: ignored." % (node.name, self) |
paul@0 | 309 | else: |
paul@7 | 310 | cls = Class(node.name, self.get_parent().full_name()) |
paul@0 | 311 | for base in node.bases: |
paul@0 | 312 | base_ref = self.dispatch(base) |
paul@0 | 313 | if base_ref is None: |
paul@4 | 314 | raise InspectError, "Base class %r for class %r in %r is not found: it may be hidden in some way." % (base, self, cls) |
paul@0 | 315 | cls.add_base(base_ref) |
paul@0 | 316 | |
paul@0 | 317 | # Make an entry for the class. |
paul@0 | 318 | |
paul@0 | 319 | self.store(node.name, cls) |
paul@0 | 320 | |
paul@0 | 321 | self.classes.append(cls) |
paul@0 | 322 | self.dispatch(node.code) |
paul@0 | 323 | self.classes.pop() |
paul@0 | 324 | |
paul@0 | 325 | return node |
paul@0 | 326 | |
paul@4 | 327 | visitCompare = NOP |
paul@4 | 328 | |
paul@0 | 329 | visitConst = NOP |
paul@0 | 330 | |
paul@4 | 331 | visitContinue = NOP |
paul@4 | 332 | |
paul@4 | 333 | visitDecorators = NOP |
paul@4 | 334 | |
paul@0 | 335 | visitDict = NOP |
paul@0 | 336 | |
paul@0 | 337 | visitDiscard = NOP |
paul@0 | 338 | |
paul@4 | 339 | visitDiv = NOP |
paul@4 | 340 | |
paul@4 | 341 | visitEllipsis = NOP |
paul@4 | 342 | |
paul@4 | 343 | visitExec = NOP |
paul@4 | 344 | |
paul@4 | 345 | visitExpression = NOP |
paul@4 | 346 | |
paul@4 | 347 | visitFloorDiv = NOP |
paul@4 | 348 | |
paul@0 | 349 | visitFor = NOP |
paul@0 | 350 | |
paul@0 | 351 | def visitFrom(self, node): |
paul@0 | 352 | if self.importer is None: |
paul@0 | 353 | raise InspectError, "Please use the micropython.Importer class for code which uses the 'from' statement." |
paul@0 | 354 | |
paul@0 | 355 | module = self.importer.load(node.modname, 1) |
paul@0 | 356 | |
paul@0 | 357 | if module is None: |
paul@0 | 358 | print "Warning:", node.modname, "not imported." |
paul@0 | 359 | |
paul@0 | 360 | for name, alias in node.names: |
paul@0 | 361 | if name != "*": |
paul@4 | 362 | if module is not None and module.namespace.has_key(name): |
paul@3 | 363 | self.namespace[alias or name] = attr = module.namespace[name] |
paul@2 | 364 | if isinstance(attr, Module) and not attr.loaded: |
paul@2 | 365 | self.importer.load(attr.name) |
paul@3 | 366 | else: |
paul@4 | 367 | self.namespace[alias or name] = UnresolvedName(name, node.modname) |
paul@3 | 368 | else: |
paul@3 | 369 | if module is not None: |
paul@3 | 370 | for n in module.namespace.keys(): |
paul@3 | 371 | self.namespace[n] = attr = module.namespace[n] |
paul@3 | 372 | if isinstance(attr, Module) and not attr.loaded: |
paul@3 | 373 | self.importer.load(attr.name) |
paul@0 | 374 | |
paul@0 | 375 | return None |
paul@0 | 376 | |
paul@0 | 377 | def visitFunction(self, node): |
paul@3 | 378 | function = Function( |
paul@3 | 379 | node.name, |
paul@7 | 380 | self.get_parent().full_name(), |
paul@3 | 381 | node.argnames, |
paul@3 | 382 | has_star=(node.flags & 4 != 0), |
paul@3 | 383 | has_dstar=(node.flags & 8 != 0) |
paul@3 | 384 | ) |
paul@0 | 385 | |
paul@0 | 386 | in_global = self.in_global |
paul@0 | 387 | self.in_global = 0 |
paul@0 | 388 | if node.name == "__init__" and self.classes: |
paul@0 | 389 | self.in_init = 1 |
paul@0 | 390 | self.dispatch(node.code) |
paul@0 | 391 | self.in_init = 0 |
paul@0 | 392 | self.in_global = in_global |
paul@3 | 393 | |
paul@3 | 394 | self.store(node.name, function) |
paul@0 | 395 | return None |
paul@0 | 396 | |
paul@4 | 397 | visitGenExpr = NOP |
paul@4 | 398 | |
paul@4 | 399 | visitGenExprFor = NOP |
paul@4 | 400 | |
paul@4 | 401 | visitGenExprIf = NOP |
paul@4 | 402 | |
paul@4 | 403 | visitGenExprInner = NOP |
paul@4 | 404 | |
paul@0 | 405 | def visitGetattr(self, node): |
paul@0 | 406 | expr = self.dispatch(node.expr) |
paul@4 | 407 | if expr is not None: |
paul@4 | 408 | if isinstance(expr, Module): |
paul@4 | 409 | return expr.namespace.get(node.attrname) |
paul@4 | 410 | elif isinstance(expr, UnresolvedName): |
paul@4 | 411 | return UnresolvedName(node.attrname, expr.full_name()) |
paul@4 | 412 | return builtins_namespace.get(node.attrname) |
paul@4 | 413 | |
paul@4 | 414 | visitGlobal = NOP |
paul@0 | 415 | |
paul@0 | 416 | def visitIf(self, node): |
paul@0 | 417 | for test, body in node.tests: |
paul@0 | 418 | self.dispatch(body) |
paul@0 | 419 | if node.else_ is not None: |
paul@0 | 420 | self.dispatch(node.else_) |
paul@0 | 421 | return None |
paul@0 | 422 | |
paul@0 | 423 | def visitImport(self, node): |
paul@0 | 424 | if self.importer is None: |
paul@0 | 425 | raise InspectError, "Please use the micropython.Importer class for code which uses the 'import' statement." |
paul@0 | 426 | |
paul@0 | 427 | for name, alias in node.names: |
paul@2 | 428 | if alias is not None: |
paul@4 | 429 | self.namespace[alias] = self.importer.load(name, 1) or UnresolvedName(None, name) |
paul@2 | 430 | else: |
paul@4 | 431 | self.namespace[name.split(".")[0]] = self.importer.load(name) or UnresolvedName(None, name.split(".")[0]) |
paul@0 | 432 | |
paul@0 | 433 | return None |
paul@0 | 434 | |
paul@4 | 435 | visitInvert = NOP |
paul@4 | 436 | |
paul@4 | 437 | visitKeyword = NOP |
paul@4 | 438 | |
paul@4 | 439 | visitLambda = NOP |
paul@4 | 440 | |
paul@1 | 441 | visitLeftShift = NOP |
paul@1 | 442 | |
paul@0 | 443 | visitList = NOP |
paul@0 | 444 | |
paul@4 | 445 | visitListComp = NOP |
paul@4 | 446 | |
paul@4 | 447 | visitListCompFor = NOP |
paul@4 | 448 | |
paul@4 | 449 | visitListCompIf = NOP |
paul@4 | 450 | |
paul@4 | 451 | visitMod = NOP |
paul@4 | 452 | |
paul@0 | 453 | def visitModule(self, node): |
paul@0 | 454 | return self.dispatch(node.node) |
paul@0 | 455 | |
paul@2 | 456 | visitMul = NOP |
paul@2 | 457 | |
paul@0 | 458 | def visitName(self, node): |
paul@0 | 459 | name = node.name |
paul@0 | 460 | if name == "self": |
paul@0 | 461 | return Self() |
paul@0 | 462 | elif self.namespace.has_key(name): |
paul@0 | 463 | return self.namespace[name] |
paul@3 | 464 | elif builtins_namespace.has_key(name): |
paul@3 | 465 | return builtins_namespace[name] |
paul@0 | 466 | else: |
paul@0 | 467 | return None |
paul@0 | 468 | |
paul@0 | 469 | visitNot = NOP |
paul@0 | 470 | |
paul@0 | 471 | visitOr = NOP |
paul@0 | 472 | |
paul@0 | 473 | visitPass = NOP |
paul@0 | 474 | |
paul@4 | 475 | visitPower = NOP |
paul@4 | 476 | |
paul@4 | 477 | visitPrint = NOP |
paul@4 | 478 | |
paul@4 | 479 | visitPrintnl = NOP |
paul@4 | 480 | |
paul@0 | 481 | visitRaise = NOP |
paul@0 | 482 | |
paul@4 | 483 | visitReturn = NOP |
paul@4 | 484 | |
paul@1 | 485 | visitRightShift = NOP |
paul@1 | 486 | |
paul@4 | 487 | visitSlice = NOP |
paul@4 | 488 | |
paul@0 | 489 | def visitStmt(self, node): |
paul@0 | 490 | for n in node.nodes: |
paul@0 | 491 | self.dispatch(n) |
paul@0 | 492 | return None |
paul@0 | 493 | |
paul@4 | 494 | visitSub = NOP |
paul@4 | 495 | |
paul@0 | 496 | visitSubscript = NOP |
paul@0 | 497 | |
paul@0 | 498 | def visitTryExcept(self, node): |
paul@0 | 499 | self.dispatch(node.body) |
paul@0 | 500 | for name, var, n in node.handlers: |
paul@0 | 501 | self.dispatch(n) |
paul@0 | 502 | if node.else_ is not None: |
paul@0 | 503 | self.dispatch(node.else_) |
paul@0 | 504 | return None |
paul@0 | 505 | |
paul@4 | 506 | visitTryFinally = NOP |
paul@4 | 507 | |
paul@1 | 508 | visitTuple = NOP |
paul@1 | 509 | |
paul@4 | 510 | visitUnaryAdd = NOP |
paul@4 | 511 | |
paul@4 | 512 | visitUnarySub = NOP |
paul@4 | 513 | |
paul@4 | 514 | visitWhile = NOP |
paul@4 | 515 | |
paul@4 | 516 | visitWith = NOP |
paul@4 | 517 | |
paul@4 | 518 | visitYield = NOP |
paul@4 | 519 | |
paul@0 | 520 | class Self: |
paul@0 | 521 | |
paul@0 | 522 | "A reference to an object within a method." |
paul@0 | 523 | |
paul@0 | 524 | pass |
paul@0 | 525 | |
paul@4 | 526 | # Built-in types initialisation. |
paul@4 | 527 | |
paul@0 | 528 | builtins_namespace = {} |
paul@0 | 529 | for key in ['ArithmeticError', 'AssertionError', 'AttributeError', |
paul@0 | 530 | 'BaseException', 'DeprecationWarning', 'EOFError', 'Ellipsis', |
paul@0 | 531 | 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', |
paul@0 | 532 | 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', |
paul@0 | 533 | 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', |
paul@0 | 534 | 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', |
paul@0 | 535 | 'None', 'NotImplemented', 'NotImplementedError', 'OSError', |
paul@0 | 536 | 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', |
paul@0 | 537 | 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', |
paul@0 | 538 | 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', |
paul@0 | 539 | 'TabError', 'True', 'TypeError', 'UnboundLocalError', |
paul@0 | 540 | 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', |
paul@0 | 541 | 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', |
paul@4 | 542 | 'ValueError', 'Warning', 'ZeroDivisionError', |
paul@4 | 543 | 'bool', 'buffer', 'complex', 'dict', 'file', 'float', 'int', 'list', |
paul@4 | 544 | 'long', 'object', 'slice', 'str', 'tuple', 'type', 'unicode']: |
paul@4 | 545 | builtins_namespace[key] = Class(key, "__builtins__") |
paul@0 | 546 | |
paul@0 | 547 | # vim: tabstop=4 expandtab shiftwidth=4 |