1 #!/usr/bin/env python 2 3 """ 4 Inspect source files, obtaining details of classes and attributes. 5 6 Copyright (C) 2007, 2008 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free Software 10 Foundation; either version 3 of the License, or (at your option) any later 11 version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 details. 17 18 You should have received a copy of the GNU General Public License along with 19 this program. If not, see <http://www.gnu.org/licenses/>. 20 21 -------- 22 23 The central classes in this module are the following: 24 25 * Class 26 * Function 27 * Module 28 * InspectedModule (derived from Module) 29 30 All of the above support the Naming interface either explicitly or through 31 general conformance, meaning that all can be asked to provide their 'full_name' 32 using the method of that name. 33 34 Additionally, all of the above also support a dictionary interface in order to 35 access names within their defined scopes. Specific methods also exist in order 36 to distinguish between certain kinds of attributes: 37 38 * Class: (class|all_class|instance|all)_attributes 39 * Function: parameters, locals, all_locals 40 * Module: module_attributes 41 42 These specific methods are useful in certain situations. 43 44 The above classes also provide a 'node' attribute, indicating the AST node where 45 each such object is defined. 46 """ 47 48 from micropython.common import * 49 import compiler.ast 50 from compiler.visitor import ASTVisitor 51 try: 52 set 53 except NameError: 54 from sets import Set as set 55 56 class InspectError(ProcessingError): pass 57 58 class AtLeast: 59 60 "A special representation for numbers of a given value or greater." 61 62 def __init__(self, count): 63 self.count = count 64 65 def __eq__(self, other): 66 return 0 67 68 __lt__ = __le__ = __eq__ 69 70 def __ne__(self, other): 71 return 1 72 73 def __gt__(self, other): 74 if isinstance(other, AtLeast): 75 return 0 76 else: 77 return self.count > other 78 79 def __ge__(self, other): 80 if isinstance(other, AtLeast): 81 return 0 82 else: 83 return self.count >= other 84 85 def __iadd__(self, other): 86 if isinstance(other, AtLeast): 87 self.count += other.count 88 else: 89 self.count += other 90 return self 91 92 def __radd__(self, other): 93 if isinstance(other, AtLeast): 94 return AtLeast(self.count + other.count) 95 else: 96 return AtLeast(self.count + other) 97 98 def __repr__(self): 99 return "AtLeast(%r)" % self.count 100 101 # Mix-ins and abstract classes. 102 103 class NamespaceDict: 104 105 "A mix-in providing dictionary methods." 106 107 def __init__(self, global_namespace=None): 108 self.namespace = {} 109 self.globals = set() 110 self.global_namespace = global_namespace 111 self.attr_position = 0 112 113 def __getitem__(self, name): 114 return self.namespace[name] 115 116 def get(self, name, default=None): 117 return self.namespace.get(name, default) 118 119 def __setitem__(self, name, value): 120 self.set(name, value) 121 122 def set(self, name, value, single_assignment=1): 123 if name in self.globals: 124 self.global_namespace.set(name, value, 0) 125 else: 126 attr = self._set(name, value) 127 128 # NOTE: Insist on assignments with known values. 129 130 if value is not None: 131 attr.update(value, single_assignment) 132 133 def set_module(self, name, value): 134 attr = self._set(name, value) 135 if attr.assignments is None: 136 attr.assignments = 1 137 attr.assignment_values.add(value) 138 139 def _set(self, name, value): 140 if not self.namespace.has_key(name): 141 self.namespace[name] = Attr(self.attr_position, self, name, value) 142 self.attr_position += 1 143 return self.namespace[name] 144 145 def __delitem__(self, name): 146 del self.namespace[name] 147 148 def has_key(self, name): 149 return self.namespace.has_key(name) 150 151 def keys(self): 152 return self.namespace.keys() 153 154 def values(self): 155 return self.namespace.values() 156 157 def items(self): 158 return self.namespace.items() 159 160 def make_global(self, name): 161 if not self.namespace.has_key(name): 162 self.globals.add(name) 163 else: 164 raise InspectError(self.full_name(), self.node, "Name %r is global and local in %r" % (name, self.full_name())) 165 166 def get_assignments(self, name): 167 if self.assignments.has_key(name): 168 return max(self.assignments[name], len(self.assignment_values[name])) 169 else: 170 return None 171 172 def to_list(self, d): 173 l = [None] * len(d.keys()) 174 for attr in d.values(): 175 l[attr.position] = attr 176 return l 177 178 class Naming: 179 180 "A mix-in providing naming conveniences." 181 182 def full_name(self): 183 if self.name is not None: 184 return self.parent_name + "." + self.name 185 else: 186 return self.parent_name 187 188 # Program data structures. 189 190 class Attr: 191 192 "An attribute entry." 193 194 def __init__(self, position, parent, name, value=None, assignments=None): 195 self.position = position 196 self.parent = parent 197 self.name = name 198 self.value = value 199 200 # Number of assignments per name. 201 202 self.assignments = assignments 203 self.assignment_values = set() 204 205 def update(self, value, single_assignment): 206 if self.assignments is None: 207 if single_assignment: 208 self.assignments = 1 209 else: 210 self.assignments = AtLeast(1) 211 else: 212 if single_assignment: 213 self.assignments += 1 214 else: 215 self.assignments += AtLeast(1) 216 self.assignment_values.add(value) 217 218 def __repr__(self): 219 return "Attr(%r, %r, %r, %r, %r)" % (self.position, self.parent, self.name, self.value, self.assignments) 220 221 class Const: 222 223 "A constant object." 224 225 def __init__(self, value): 226 self.value = value 227 228 # Image generation details. 229 230 self.location = None 231 232 def __repr__(self): 233 if self.location is not None: 234 return "Const(%r, location=%r)" % (self.value, self.location) 235 else: 236 return "Const(%r)" % self.value 237 238 def __eq__(self, other): 239 return self.value == other.value 240 241 def __hash__(self): 242 return hash(self.value) 243 244 class Class(NamespaceDict, Naming): 245 246 "An inspected class." 247 248 def __init__(self, name, parent_name, global_namespace=None, node=None): 249 NamespaceDict.__init__(self, global_namespace) 250 self.name = name 251 self.parent_name = parent_name 252 self.node = node 253 254 self.bases = [] 255 self.instattr = set() # instance attributes 256 257 self.all_instattr = None # cache for instance_attributes 258 self.all_instattr_names = None # from all_instattr 259 self.all_classattr = None # cache for all_class_attributes 260 self.all_classattr_names = None # from all_classattr 261 self.allattr = None # cache for all_attributes 262 self.allattr_names = None # from allattr 263 264 # Image generation details. 265 266 self.location = None 267 self.code_location = None 268 269 def __repr__(self): 270 if self.location is not None: 271 return "Class(%r, %r, location=%r)" % (self.name, self.parent_name, self.location) 272 else: 273 return "Class(%r, %r)" % (self.name, self.parent_name) 274 275 def add_base(self, base): 276 self.bases.append(base) 277 278 def add_instance_attribute(self, name): 279 self.instattr.add(name) 280 281 "Return the attribute names provided by this class only." 282 283 class_attribute_names = NamespaceDict.keys 284 285 def class_attributes(self): 286 287 "Return class attributes provided by this class only." 288 289 return self 290 291 def all_class_attribute_names(self): 292 293 "Return the attribute names provided by classes in this hierarchy." 294 295 if self.all_classattr_names is None: 296 self.all_class_attributes() 297 return self.all_classattr_names 298 299 def all_class_attributes(self): 300 301 "Return all class attributes, indicating the class which provides them." 302 303 if self.all_classattr is None: 304 self.all_classattr = {} 305 306 reversed_bases = self.bases[:] 307 reversed_bases.reverse() 308 for cls in reversed_bases: 309 self.all_classattr.update(cls.all_class_attributes()) 310 311 # Record attributes provided by this class, along with their 312 # positions. 313 314 self.all_classattr.update(self.class_attributes()) 315 316 return self.all_classattr 317 318 def instance_attribute_names(self): 319 320 "Return the instance attribute names provided by the class." 321 322 if self.all_instattr_names is None: 323 self.instance_attributes() 324 return self.all_instattr_names 325 326 def instance_attributes(self): 327 328 "Return instance-only attributes for instances of this class." 329 330 if self.all_instattr is None: 331 self.all_instattr = {} 332 instattr = set() 333 334 reversed_bases = self.bases[:] 335 reversed_bases.reverse() 336 for cls in reversed_bases: 337 instattr.update(cls.instance_attributes().keys()) 338 339 # Record instance attributes provided by this class and its bases, 340 # along with their positions. 341 342 instattr.update(self.instattr) 343 344 for i, name in enumerate(instattr): 345 self.all_instattr[name] = Attr(i, None, name) 346 347 self.all_instattr_names = self.all_instattr.keys() 348 349 return self.all_instattr 350 351 def all_attribute_names(self): 352 353 """ 354 Return the names of all attributes provided by instances of this class. 355 """ 356 357 self.allattr_names = self.allattr_names or self.all_attributes().keys() 358 return self.allattr_names 359 360 def all_attributes(self): 361 362 """ 363 Return all attributes for an instance, indicating either the class which 364 provides them or that the instance itself provides them. 365 """ 366 367 if self.allattr is None: 368 self.allattr = {} 369 self.allattr.update(self.all_class_attributes()) 370 for i, name in enumerate(self.instance_attribute_names()): 371 if self.allattr.has_key(name): 372 print "Instance attribute %r in %r overrides class attribute." % (name, self) 373 self.allattr[name] = Attr(i, None, name) 374 return self.allattr 375 376 class Function(NamespaceDict, Naming): 377 378 "An inspected function." 379 380 def __init__(self, name, parent_name, argnames, has_star, has_dstar, global_namespace=None, node=None): 381 NamespaceDict.__init__(self, global_namespace) 382 self.name = name 383 self.parent_name = parent_name 384 self.argnames = argnames 385 self.has_star = has_star 386 self.has_dstar = has_dstar 387 self.node = node 388 389 # Caches. 390 391 self.localnames = None # cache for locals 392 393 # Add parameters to the namespace. 394 395 self._add_parameters(argnames) 396 397 # Image generation details. 398 399 self.location = None 400 self.code_location = None 401 402 def _add_parameters(self, argnames): 403 for name in argnames: 404 if isinstance(name, tuple): 405 self._add_parameters(name) 406 else: 407 self[name] = None 408 409 def __repr__(self): 410 if self.location is not None: 411 return "Function(%r, %r, %r, %r, %r, location=%r)" % ( 412 self.name, self.parent_name, self.argnames, self.has_star, self.has_dstar, self.location 413 ) 414 else: 415 return "Function(%r, %r, %r, %r, %r)" % ( 416 self.name, self.parent_name, self.argnames, self.has_star, self.has_dstar 417 ) 418 419 def make_global(self, name): 420 if name not in self.argnames and not self.has_key(name): 421 self.globals.add(name) 422 else: 423 raise InspectError(self.full_name(), self.node, "Name %r is global and local in %r" % (name, self.full_name())) 424 425 def parameters(self): 426 427 """ 428 Return a dictionary mapping parameter names to their position in the 429 parameter list. 430 """ 431 432 parameters = {} 433 for i, name in enumerate(self.argnames): 434 parameters[name] = i 435 return parameters 436 437 def all_locals(self): 438 439 "Return a dictionary mapping names to local and parameter details." 440 441 return self 442 443 def locals(self): 444 445 "Return a dictionary mapping names to local details." 446 447 if self.localnames is None: 448 self.localnames = {} 449 self.localnames.update(self.all_locals()) 450 for name in self.argnames: 451 del self.localnames[name] 452 return self.localnames 453 454 class UnresolvedName(NamespaceDict, Naming): 455 456 "A module, class or function which was mentioned but could not be imported." 457 458 def __init__(self, name, parent_name, global_namespace=None): 459 NamespaceDict.__init__(self, global_namespace) 460 self.name = name 461 self.parent_name = parent_name 462 463 def all_class_attributes(self): 464 return {} 465 466 def instance_attributes(self): 467 return {} 468 469 def __repr__(self): 470 return "UnresolvedName(%r, %r)" % (self.name, self.parent_name) 471 472 class Module(NamespaceDict): 473 474 "An inspected module's core details." 475 476 def __init__(self, name): 477 NamespaceDict.__init__(self, self) 478 self.name = name 479 480 # Complete lists of classes and functions. 481 482 self.all_objects = set() 483 484 # Constant records. 485 486 self.constant_values = {} 487 self.constant_list = None # cache for constants 488 489 # Image generation details. 490 491 self.location = None 492 self.code_location = None 493 494 # Original location details. 495 496 self.node = None 497 498 def full_name(self): 499 return self.name 500 501 def __repr__(self): 502 if self.location is not None: 503 return "Module(%r, location=%r)" % (self.name, self.location) 504 else: 505 return "Module(%r)" % self.name 506 507 # Attribute methods. 508 509 "Return the module attribute names provided by the module." 510 511 module_attribute_names = NamespaceDict.keys 512 513 def module_attributes(self): 514 515 "Return a dictionary mapping names to module attributes." 516 517 return self 518 519 def constants(self): 520 521 "Return a list of constants." 522 523 if self.constant_list is None: 524 self.constant_list = list(self.constant_values.values()) 525 526 return self.constant_list 527 528 # Program visitors. 529 530 class InspectedModule(ASTVisitor, Module): 531 532 """ 533 An inspected module, providing core details via the Module superclass, but 534 capable of being used as an AST visitor. 535 """ 536 537 def __init__(self, name, importer=None): 538 ASTVisitor.__init__(self) 539 Module.__init__(self, name) 540 self.visitor = self 541 542 self.importer = importer 543 self.loaded = 0 544 545 # Current expression state. 546 547 self.expr = None 548 549 # Namespace state. 550 551 self.in_init = 0 # Find instance attributes in __init__ methods. 552 self.in_loop = 0 # Note loop "membership", affecting assignments. 553 self.namespaces = [] 554 self.module = None 555 556 def parse(self, filename): 557 558 "Parse the file having the given 'filename'." 559 560 module = compiler.parseFile(filename) 561 self.process(module) 562 563 def process(self, module): 564 565 "Process the given 'module'." 566 567 self.node = self.module = module 568 processed = self.dispatch(module) 569 if self.has_key("__all__"): 570 all = self["__all__"] 571 if isinstance(all, compiler.ast.List): 572 for n in all.nodes: 573 self[n.value] = self.importer.add_module(self.name + "." + n.value) 574 return processed 575 576 def vacuum(self): 577 578 "Vacuum the module namespace, removing unloaded module references." 579 580 for name, value in self.items(): 581 if isinstance(value, Module) and not value.loaded: 582 del self[name] 583 584 # Complain about globals not initialised at the module level. 585 586 if isinstance(value, Global): 587 print "Warning: global %r in module %r not initialised at the module level." % (name, self.name) 588 589 # Namespace methods. 590 591 def store(self, name, obj): 592 593 "Record attribute or local 'name', storing 'obj'." 594 595 if not self.namespaces: 596 self.set(name, obj, not self.in_loop) 597 else: 598 self.namespaces[-1].set(name, obj, not self.in_loop) 599 600 # Record all non-local objects. 601 602 if not (self.namespaces and isinstance(self.namespaces[-1], Function)): 603 self.all_objects.add(obj) 604 605 def store_instance_attr(self, name): 606 607 "Record instance attribute 'name' in the current class." 608 609 if self.in_init: 610 611 # Current namespace is the function. 612 # Previous namespace is the class. 613 614 self.namespaces[-2].add_instance_attribute(name) 615 616 def get_parent(self): 617 return (self.namespaces[-1:] or [self])[0] 618 619 # Visitor methods. 620 621 def default(self, node, *args): 622 raise InspectError(self.full_name(), node, "Node class %r is not supported." % node.__class__) 623 624 def dispatch(self, node, *args): 625 return ASTVisitor.dispatch(self, node, *args) 626 627 def NOP(self, node): 628 for n in node.getChildNodes(): 629 self.dispatch(n) 630 return None 631 632 visitAdd = NOP 633 634 visitAnd = NOP 635 636 visitAssert = NOP 637 638 def visitAssign(self, node): 639 self.expr = self.dispatch(node.expr) 640 for n in node.nodes: 641 self.dispatch(n) 642 return None 643 644 def visitAssAttr(self, node): 645 expr = self.dispatch(node.expr) 646 if isinstance(expr, Attr) and expr.name == "self": 647 self.store_instance_attr(node.attrname) 648 return None 649 650 def visitAssList(self, node): 651 for n in node.nodes: 652 self.dispatch(n) 653 return None 654 655 def visitAssName(self, node): 656 if isinstance(self.expr, Attr): 657 self.store(node.name, self.expr.value) 658 else: 659 self.store(node.name, self.expr) 660 return None 661 662 visitAssTuple = visitAssList 663 664 visitAugAssign = NOP 665 666 visitBackquote = NOP 667 668 visitBitand = NOP 669 670 visitBitor = NOP 671 672 visitBitxor = NOP 673 674 visitBreak = NOP 675 676 visitCallFunc = NOP 677 678 def visitClass(self, node): 679 if self.namespaces: 680 print "Class %r in %r is not global: ignored." % (node.name, self.namespaces[-1].full_name()) 681 else: 682 cls = Class(node.name, self.get_parent().full_name(), self, node) 683 684 # Visit the base class expressions, attempting to find concrete 685 # definitions of classes. 686 687 for base in node.bases: 688 expr = self.dispatch(base) 689 if isinstance(expr, Attr): 690 if expr.assignments != 1: 691 raise InspectError(self.full_name(), node, 692 "Base class %r for %r is not constant." % (base, cls.full_name())) 693 else: 694 cls.add_base(expr.value) 695 else: # if expr is None: 696 raise InspectError(self.full_name(), node, 697 "Base class %r for %r is not found: it may be hidden in some way." % (base, cls.full_name())) 698 699 # Make a back reference from the node for code generation. 700 701 node.unit = cls 702 703 # Make an entry for the class. 704 705 self.store(node.name, cls) 706 707 self.namespaces.append(cls) 708 self.dispatch(node.code) 709 self.namespaces.pop() 710 711 return None 712 713 visitCompare = NOP 714 715 def visitConst(self, node): 716 const = Const(node.value) 717 self.constant_values[node.value] = const 718 return const 719 720 visitContinue = NOP 721 722 visitDecorators = NOP 723 724 visitDict = NOP 725 726 visitDiscard = NOP 727 728 visitDiv = NOP 729 730 visitEllipsis = NOP 731 732 visitExec = NOP 733 734 visitExpression = NOP 735 736 visitFloorDiv = NOP 737 738 def visitFor(self, node): 739 self.in_loop = 1 740 self.NOP(node) 741 self.in_loop = 0 742 743 def visitFrom(self, node): 744 if self.importer is None: 745 raise InspectError(self.full_name(), node, 746 "Please use the micropython.Importer class for code which uses the 'from' statement.") 747 748 module = self.importer.load(node.modname, 1) 749 750 #if module is None: 751 # print "Warning:", node.modname, "not imported." 752 753 for name, alias in node.names: 754 if name != "*": 755 if module is not None and module.namespace.has_key(name): 756 attr = module[name] 757 self.store(alias or name, attr.value) 758 if isinstance(attr, Module) and not attr.loaded: 759 self.importer.load(attr.name) 760 761 # Support the import of names from missing modules. 762 763 else: 764 self.store(alias or name, UnresolvedName(name, node.modname, self)) 765 else: 766 if module is not None: 767 for n in module.namespace.keys(): 768 attr = module[n] 769 self.store(n, attr.value) 770 if isinstance(attr, Module) and not attr.loaded: 771 self.importer.load(attr.name) 772 773 return None 774 775 def visitFunction(self, node): 776 function = Function( 777 node.name, 778 self.get_parent().full_name(), 779 node.argnames, 780 (node.flags & 4 != 0), 781 (node.flags & 8 != 0), 782 self, 783 node 784 ) 785 786 # Make a back reference from the node for code generation. 787 788 node.unit = function 789 790 self.namespaces.append(function) 791 792 # Current namespace is the function. 793 # Previous namespace is the class. 794 795 if node.name == "__init__" and isinstance(self.namespaces[-2], Class): 796 self.in_init = 1 797 798 self.dispatch(node.code) 799 self.in_init = 0 800 self.namespaces.pop() 801 802 self.store(node.name, function) 803 return None 804 805 visitGenExpr = NOP 806 807 visitGenExprFor = NOP 808 809 visitGenExprIf = NOP 810 811 visitGenExprInner = NOP 812 813 def visitGetattr(self, node): 814 expr = self.dispatch(node.expr) 815 if isinstance(expr, Attr): 816 value = expr.value 817 if isinstance(value, Module): 818 return value.namespace.get(node.attrname) 819 elif isinstance(value, UnresolvedName): 820 return UnresolvedName(node.attrname, value.full_name(), self) 821 return builtins.get(node.attrname) 822 823 def visitGlobal(self, node): 824 if self.namespaces: 825 for name in node.names: 826 self.namespaces[-1].make_global(name) 827 828 # Record a global entry for the name in the module. 829 830 if not self.has_key(name): 831 self[name] = Global() 832 833 def visitIf(self, node): 834 for test, body in node.tests: 835 self.dispatch(body) 836 if node.else_ is not None: 837 self.dispatch(node.else_) 838 return None 839 840 visitIfExp = NOP 841 842 def visitImport(self, node): 843 if self.importer is None: 844 raise InspectError(self.full_name(), node, 845 "Please use the micropython.Importer class for code which uses the 'import' statement.") 846 847 for name, alias in node.names: 848 if alias is not None: 849 self.store(alias, self.importer.load(name, 1) or UnresolvedName(None, name, self)) 850 else: 851 self.store(name.split(".")[0], self.importer.load(name) or UnresolvedName(None, name.split(".")[0], self)) 852 853 return None 854 855 visitInvert = NOP 856 857 visitKeyword = NOP 858 859 visitLambda = NOP 860 861 visitLeftShift = NOP 862 863 visitList = NOP 864 865 visitListComp = NOP 866 867 visitListCompFor = NOP 868 869 visitListCompIf = NOP 870 871 visitMod = NOP 872 873 def visitModule(self, node): 874 return self.dispatch(node.node) 875 876 visitMul = NOP 877 878 def visitName(self, node): 879 name = node.name 880 if self.namespaces and self.namespaces[-1].has_key(name): 881 return self.namespaces[-1][name] 882 elif self.has_key(name): 883 return self[name] 884 elif builtins.has_key(name): 885 return builtins[name] 886 else: 887 return None 888 889 visitNot = NOP 890 891 visitOr = NOP 892 893 visitPass = NOP 894 895 visitPower = NOP 896 897 visitPrint = NOP 898 899 visitPrintnl = NOP 900 901 visitRaise = NOP 902 903 visitReturn = NOP 904 905 visitRightShift = NOP 906 907 visitSlice = NOP 908 909 visitSliceobj = NOP 910 911 def visitStmt(self, node): 912 for n in node.nodes: 913 self.dispatch(n) 914 return None 915 916 visitSub = NOP 917 918 visitSubscript = NOP 919 920 def visitTryExcept(self, node): 921 self.dispatch(node.body) 922 for name, var, n in node.handlers: 923 self.dispatch(n) 924 if node.else_ is not None: 925 self.dispatch(node.else_) 926 return None 927 928 visitTryFinally = NOP 929 930 visitTuple = NOP 931 932 visitUnaryAdd = NOP 933 934 visitUnarySub = NOP 935 936 def visitWhile(self, node): 937 self.in_loop = 1 938 self.NOP(node) 939 self.in_loop = 0 940 941 visitWith = NOP 942 943 visitYield = NOP 944 945 class Global: 946 947 """ 948 A reference to an object assigned to a global from outside the module 949 top-level. 950 """ 951 952 pass 953 954 # Built-in types initialisation. 955 956 class Builtins(Module): 957 958 "The special built-in types module." 959 960 def __init__(self): 961 Module.__init__(self, "__builtins__") 962 963 for key in ['ArithmeticError', 'AssertionError', 'AttributeError', 964 'BaseException', 'DeprecationWarning', 'EOFError', 'Ellipsis', 965 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 966 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 967 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 968 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 969 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 970 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 971 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 972 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 973 'TabError', 'True', 'TypeError', 'UnboundLocalError', 974 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 975 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 976 'ValueError', 'Warning', 'ZeroDivisionError', 977 'basestring', 'bool', 'buffer', 'complex', 'dict', 'file', 'float', 978 'frozenset', 'int', 'list', 'long', 'object', 'set', 'slice', 'str', 979 'tuple', 'type', 'unicode', 'xrange']: 980 self[key] = Class(key, self.full_name(), self) 981 982 # NOTE: Incomplete: some functions have more than one parameter. 983 984 for key in ['__import__', 'abs', 'all', 'any', 'callable', 'chr', 985 'classmethod', 'cmp', 'compile', 'delattr', 'dir', 'divmod', 986 'enumerate', 'eval', 'execfile', 'filter', 'getattr', 'globals', 987 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'isinstance', 988 'issubclass', 'iter', 'len', 'locals', 'map', 'max', 'min', 'oct', 989 'open', 'ord', 'pow', 'property', 'range', 'raw_input', 'reduce', 990 'reload', 'repr', 'reversed', 'round', 'setattr', 'sorted', 991 'staticmethod', 'sum', 'super', 'unichr', 'vars', 'zip']: 992 self[key] = Function(key, self.full_name(), ['arg'], 0, 0, self) 993 994 builtins = Builtins() 995 996 # vim: tabstop=4 expandtab shiftwidth=4