Commits

Anonymous committed 886be74

Mainlining #24 directly.

  • Participants
  • Parent commits fb32db4

Comments (0)

Files changed (2)

File src/tools/dismantle.py

 #
 """
 
+__usage__ = """Usage:
+    dismantle.py sourcefilename.py
+"""
 
 #### CONSTS ####
 STRINGTOOLONG = 32
 
 #### FXNS ####
 
-def dummy():
-    a = 6
-    b = ((4,5,6))
-
-
-def dismantle(fn):
+def dismantle_file(fn):
     """
     Dismantle the .py file, fn.
     Returns the root code object.
     f = open(fn)
     source = f.read()
     f.close()
+    return dismantle(source, fn)
+
+
+def dismantle(source, fn=""):
+
+    # If no filename given, just dismantle source, skip magic and ignore
+    if fn == "":
+        magic = 0
+        ignore = 0
+        fn = "fn"
+        pyc = ""
+
+    else:
+        #compile the .py file
+        py_compile.compile(fn)
+        #open the .pyc file
+        f = open(fn + 'c','rb')
+        pyc = f.read()
+        f.close()
+
+        #check for magic number
+        magic = int((ord(pyc[0])      ) | (ord(pyc[1]) <<  8) |
+                    (ord(pyc[2]) << 16) | (ord(pyc[3]) << 24))
+
+        #grab the next 4 bytes (don't know what they do)
+        ignore = int((ord(pyc[4])      ) | (ord(pyc[5]) <<  8) |
+                     (ord(pyc[6]) << 16) | (ord(pyc[7]) << 24))
+
     code = compile(source, fn, "exec")
 
-    #compile the .py file
-    py_compile.compile(fn)
-    #open the .pyc file
-    f = open(fn + 'c','rb')
-    pyc = f.read()
-    f.close()
-
-    #check for magic number
-    magic = int((ord(pyc[0])      ) | (ord(pyc[1]) <<  8) |
-                (ord(pyc[2]) << 16) | (ord(pyc[3]) << 24))
-    #different magic numbers for different versions of python
-    #if magic not in [0x0a0dc687,]:
-    #    raise IOError("Did not find .pyc magic number.")
-
-    #grab the next 4 bytes (don't know what they do)
-    ignore = int((ord(pyc[4])      ) | (ord(pyc[5]) <<  8) |
-                 (ord(pyc[6]) << 16) | (ord(pyc[7]) << 24))
-
     #print header
     print "BEGIN DISMANTLE"
     print "date:           \t", time.ctime(time.time())
     Perform a dismantling of the source file, fn.
     """
     if len(sys.argv) == 2:
-        return dismantle(sys.argv[1])
+        return dismantle_file(sys.argv[1])
     else:
-        return dismantle("c:\\dwh\\tech\\cis\\py\\dismantle.py")
-
+        print __usage__
 
 if __name__ == "__main__":
         main()

File src/tools/pmImgCreator.py

 ==========      ==============================================================
 Date            Action
 ==========      ==============================================================
+2006/09/06      #24: Remove consts[0] == docstring assumption
 2006/09/01      #11: Make src/tests/ build module images as C files, not
                 header files
 2006/08/25      #6: Have pmImgCreator append a null terminator to image list
 ################################################################
 
 # remove documentation string from const pool
-REMOVE_DOC_STR = 1
+REMOVE_DOC_STR = 0
 
 # XXX remap bcode values to make parsing easier
 REMAP_BCODE_VALS = 0
                 i += 3
 
         # if the first const is a String,
-        # XXX it's most likely a docstring.
         if (type(consts[0]) == types.StringType):
 
             ## Native code filter
 
             ## Consts filter
             # if want to remove __doc__ string
-            # XXX this assumes a string in the 0th const
-            # is always __doc__.
-            elif REMOVE_DOC_STR:
+            # WARNING: this heuristic is not always accurate
+            elif REMOVE_DOC_STR and co.co_names[0] == "__doc__":
                 consts[0] = None
 
         ## Names filter