Changeset 485

Show
Ignore:
Timestamp:
Wed Jul 23 14:04:41 2008
Author:
htgoebel
Message:

Reindenting python soucefiles.

Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/bindepend.py

    r484 r485  
    88 88  
    89 89 def getfullnameof(mod, xtrapath = None):  
    90     """Return the full path name of MOD.  
      90     """Return the full path name of MOD.  
    90 90  
    91         MOD is the basename of a dll or pyd.  
    92         XTRAPATH is a path or list of paths to search first.  
    93         Return the full path name of MOD.  
    94         Will search the full Windows search path, as well as sys.path"""  
    95     # Search sys.path first!  
    96     epath = sys.path + getWindowsPath()  
    97     if xtrapath is not None:  
    98       if type(xtrapath) == type(''):  
    99         epath.insert(0, xtrapath)  
    100       else:  
    101         epath = xtrapath + epath  
    102     for p in epath:  
    103       npth = os.path.join(p, mod)  
    104       if os.path.exists(npth):  
    105         return npth  
    106       # second try: lower case filename  
      91         MOD is the basename of a dll or pyd.  
      92         XTRAPATH is a path or list of paths to search first.  
      93         Return the full path name of MOD.  
      94         Will search the full Windows search path, as well as sys.path"""  
      95     # Search sys.path first!  
      96     epath = sys.path + getWindowsPath()  
      97     if xtrapath is not None:  
      98         if type(xtrapath) == type(''):  
      99             epath.insert(0, xtrapath)  
      100         else:  
      101             epath = xtrapath + epath  
    107 102     for p in epath:  
    108           npth = os.path.join(p, string.lower(mod))  
      103         npth = os.path.join(p, mod)  
    108 103         if os.path.exists(npth):  
    109 104             return npth  
    110     return ''  
      105         # second try: lower case filename  
      106         for p in epath:  
      107             npth = os.path.join(p, string.lower(mod))  
      108             if os.path.exists(npth):  
      109                 return npth  
      110     return ''  
    111 111  
    112 112 def _getImports_dumpbin(pth):  
     
    138 138     rslt = []  
    139 139     try:  
    140         f = open(pth, 'rb').read()  
    141         pehdrd = struct.unpack('l', f[60:64])[0]  #after the MSDOS loader is the offset of the peheader  
    142         magic = struct.unpack('l', f[pehdrd:pehdrd+4])[0] # pehdr starts with magic 'PE\000\000' (or 17744)  
    143                                                           # then 20 bytes of COFF header  
    144         numsecs = struct.unpack('h', f[pehdrd+6:pehdrd+8])[0] # whence we get number of sections  
    145         opthdrmagic = struct.unpack('h', f[pehdrd+24:pehdrd+26])[0]  
    146         if opthdrmagic == 0x10b: # PE32 format  
    147             numdictoffset = 116  
    148             importoffset = 128  
    149         elif opthdrmagic == 0x20b: # PE32+ format  
    150             numdictoffset = 132  
    151             importoffset = 148  
    152         else:  
    153             print "E: bindepend cannot analyze %s - unknown header format! %x" % (pth, opthdrmagic)  
    154             return rslt  
    155         numdirs = struct.unpack('l', f[pehdrd+numdictoffset:pehdrd+numdictoffset+4])[0]  
    156         idata = ''  
    157         if magic == 17744:  
    158             importsec, sz = struct.unpack('2l', f[pehdrd+importoffset:pehdrd+importoffset+8])  
    159             if sz == 0:  
    160                 return rslt  
    161             secttbl = pehdrd + numdictoffset + 4 + 8*numdirs  
    162             secttblfmt = '8s7l2h'  
    163             seclist = []  
    164             for i in range(numsecs):  
    165                 seclist.append(struct.unpack(secttblfmt, f[secttbl+i*40:secttbl+(i+1)*40]))  
    166                 #nm, vsz, va, rsz, praw, preloc, plnnums, qrelocs, qlnnums, flags \  
    167                 # = seclist[-1]  
    168             for i in range(len(seclist)-1):  
    169                 if seclist[i][2] <= importsec < seclist[i+1][2]:  
    170                     break  
    171             vbase = seclist[i][2]  
    172             raw = seclist[i][4]  
    173             idatastart = raw + importsec - vbase  
    174             idata = f[idatastart:idatastart+seclist[i][1]]  
    175             i = 0  
    176             while 1:  
    177                 chunk = idata[i*20:(i+1)*20]  
    178                 if len(chunk) != 20:  
    179                     print "E: premature end of import table (chunk is %d, not 20)" % len(chunk)  
    180                     break  
    181                 vsa =  struct.unpack('5l', chunk)[3]  
    182                 if vsa == 0:  
    183                     break  
    184                 sa = raw + vsa - vbase  
    185                 end = string.find(f, '\000', sa)  
    186                 nm = f[sa:end]  
    187                 if nm:  
    188                     rslt.append(nm)  
    189                 i = i + 1  
    190         else:  
    191             print "E: bindepend cannot analyze %s - file is not in PE format!" % pth  
      140         f = open(pth, 'rb').read()  
      141         pehdrd = struct.unpack('l', f[60:64])[0]  #after the MSDOS loader is the offset of the peheader  
      142         magic = struct.unpack('l', f[pehdrd:pehdrd+4])[0] # pehdr starts with magic 'PE\000\000' (or 17744)  
      143                                                           # then 20 bytes of COFF header  
      144         numsecs = struct.unpack('h', f[pehdrd+6:pehdrd+8])[0] # whence we get number of sections  
      145         opthdrmagic = struct.unpack('h', f[pehdrd+24:pehdrd+26])[0]  
      146         if opthdrmagic == 0x10b: # PE32 format  
      147             numdictoffset = 116  
      148             importoffset = 128  
      149         elif opthdrmagic == 0x20b: # PE32+ format  
      150             numdictoffset = 132  
      151             importoffset = 148  
      152         else:  
      153             print "E: bindepend cannot analyze %s - unknown header format! %x" % (pth, opthdrmagic)  
      154             return rslt  
      155         numdirs = struct.unpack('l', f[pehdrd+numdictoffset:pehdrd+numdictoffset+4])[0]  
      156         idata = ''  
      157         if magic == 17744:  
      158             importsec, sz = struct.unpack('2l', f[pehdrd+importoffset:pehdrd+importoffset+8])  
      159             if sz == 0:  
      160                 return rslt  
      161             secttbl = pehdrd + numdictoffset + 4 + 8*numdirs  
      162             secttblfmt = '8s7l2h'  
      163             seclist = []  
      164             for i in range(numsecs):  
      165                 seclist.append(struct.unpack(secttblfmt, f[secttbl+i*40:secttbl+(i+1)*40]))  
      166                 #nm, vsz, va, rsz, praw, preloc, plnnums, qrelocs, qlnnums, flags \  
      167                 # = seclist[-1]  
      168             for i in range(len(seclist)-1):  
      169                 if seclist[i][2] <= importsec < seclist[i+1][2]:  
      170                     break  
      171             vbase = seclist[i][2]  
      172             raw = seclist[i][4]  
      173             idatastart = raw + importsec - vbase  
      174             idata = f[idatastart:idatastart+seclist[i][1]]  
      175             i = 0  
      176             while 1:  
      177                 chunk = idata[i*20:(i+1)*20]  
      178                 if len(chunk) != 20:  
      179                     print "E: premature end of import table (chunk is %d, not 20)" % len(chunk)  
      180                     break  
      181                 vsa =  struct.unpack('5l', chunk)[3]  
      182                 if vsa == 0:  
      183                     break  
      184                 sa = raw + vsa - vbase  
      185                 end = string.find(f, '\000', sa)  
      186                 nm = f[sa:end]  
      187                 if nm:  
      188                     rslt.append(nm)  
      189                 i = i + 1  
      190         else:  
      191             print "E: bindepend cannot analyze %s - file is not in PE format!" % pth  
    192 192     except IOError:  
    193 193         print "E: bindepend cannot analyze %s - file not found!" % pth  
     
    265 265  
    266 266 def Dependencies(lTOC, platform=sys.platform, xtrapath=None):  
    267     """Expand LTOC to include all the closure of binary dependencies.  
      267     """Expand LTOC to include all the closure of binary dependencies.  
    267 267  
    268        LTOC is a logical table of contents, ie, a seq of tuples (name, path).  
    269        Return LTOC expanded by all the binary dependencies of the entries  
    270        in LTOC, except those listed in the module global EXCLUDES"""  
    271     for nm, pth, typ in lTOC:  
    272       fullnm = string.upper(os.path.basename(pth))  
    273       if seen.get(string.upper(nm),0):  
    274         continue  
    275       #print "I: analyzing", pth  
    276       seen[string.upper(nm)] = 1  
    277       for lib, npth in selectImports(pth, platform, xtrapath):  
    278           if seen.get(string.upper(lib),0):  
      268        LTOC is a logical table of contents, ie, a seq of tuples (name, path).  
      269        Return LTOC expanded by all the binary dependencies of the entries  
      270        in LTOC, except those listed in the module global EXCLUDES"""  
      271     for nm, pth, typ in lTOC:  
      272         fullnm = string.upper(os.path.basename(pth))  
      273         if seen.get(string.upper(nm),0):  
    279 274             continue  
    280           lTOC.append((lib, npth, 'BINARY'))  
      275         #print "I: analyzing", pth  
      276         seen[string.upper(nm)] = 1  
      277         for lib, npth in selectImports(pth, platform, xtrapath):  
      278             if seen.get(string.upper(lib),0):  
      279                 continue  
      280             lTOC.append((lib, npth, 'BINARY'))  
    281 281  
    282     return lTOC  
      282     return lTOC  
    282 282  
    283 283 def selectImports(pth, platform=sys.platform, xtrapath=None):  
     
    298 298     for lib in dlls:  
    299 299         if not iswin and not cygwin:  
    300               # plain win case  
      300                 # plain win case  
    300 300             npth = lib  
    301 301             dir, lib = os.path.split(lib)  
     
    306 306             # all other platforms  
    307 307             npth = getfullnameof(lib, xtrapath)  
    308            
      308  
    308 308         # now npth is a candidate lib  
    309 309         # check again for excludes but with regex FIXME: split the list  
     
    317 317                 #print "I: inserting %20s <- %s" % (npth, pth)  
    318 318                 pass  
    319                    
      319  
    319 319         if npth:  
    320 320             rv.append((lib, npth))  
     
    454 454     parser.add_option('--target-platform', default=sys.platform,  
    455 455                       help='Target platform, required for cross-bundling (default: current platform)')  
    456                      
      456  
    456 456     opts, args = parser.parse_args()  
    457 457     if len (args) != 1:  
  • trunk/icon.py

    r43 r485  
    154 154     win32api.FreeLibrary (hsrc)  
    155 155     win32api.EndUpdateResource (hdst, 0)  
    156    
  • trunk/buildtests/test7.py

    r43 r485  
    30 30 t1.join()  
    31 31 t2.join()  
    32    
  • trunk/buildtests/pkg1/__init__.py

    r2 r485  
    6 6 sys.modules[__name__] = pkg2  
    7 7 from pkg2 import *  
    8    
    9    
    10    
  • trunk/buildtests/pkg1/a.py

    r2 r485  
    3 3 print " %s" % __doc__  
    4 4 print " %s %s" % (__name__, __file__)  
    5    
    6        
  • trunk/buildtests/pkg2/a.py

    r2 r485  
    4 4     return "a_func from pkg2.a"  
    5 5 print "pkg2.a imported"  
    6    
  • trunk/buildtests/test14.py

    r449 r485  
    20 20 import sys  
    21 21 if sys.version_info[:2] >= (2, 5):  
    22       import subprocess     
      22     import subprocess  
    22 22     import xml.etree.ElementTree as ET  
    23 23     print "#"*50  
     
    36 36 else:  
    37 37     print "Python 2.5 test14 skipped"  
    38    
  • trunk/buildtests/test16.py

    r449 r485  
    33 33  
    34 34 print "test16 DONE"  
    35    
  • trunk/buildtests/test6.py

    r43 r485  
    27 27 reload(test6x)  
    28 28 print "test6x.x is now", test6x.x  
    29    
  • trunk/buildtests/test13.py

    r449 r485  
    24 24 else:  
    25 25     print "Python 2.5 test13 skipped"  
    26    
  • trunk/buildtests/test15.py

    r449 r485  
    33 33 else:  
    34 34     print "Python 2.5 test14 skipped"  
    35    
  • trunk/buildtests/runtests.py

    r452 r485  
    60 60     print info  
    61 61     print "*"*len(info)  
    62       build_python = open("python_exe.build", "w")                                       
    63       build_python.write(sys.executable)                                                 
      62     build_python = open("python_exe.build", "w")  
      63     build_python.write(sys.executable)  
    64 64     build_python.close()  
    65 65     if not filters:  
     
    97 97     interactive_tests = glob.glob('test*[0-9]i.py')  
    98 98     args = sys.argv[1:]  
    99        
      99  
    99 99     if "-i" in args:  
    100 100         print "Running interactive tests"  
     
    107 107     clean()  
    108 108     runtests(tests)  
    109    
  • trunk/hooks/hook-xml.dom.html.py

    r43 r485  
    32 32           ('SECURE_HTML_ELEMS',0),  
    33 33         ]  
    34    
    35    
  • trunk/hooks/hook-xml.dom.html.HTMLDocument.py

    r43 r485  
    71 71                  'xml.dom.html.HTMLUListElement',  
    72 72         ]  
    73    
    74    
  • trunk/hooks/hook-vtkpython.py

    r43 r485  
    19 19 import os  
    20 20 if os.name == 'posix':  
    21      hiddenimports = ['libvtkCommonPython','libvtkFilteringPython','libvtkIOPython','libvtkImagingPython','libvtkGraphicsPython','libvtkRenderingPython','libvtkHybridPython','libvtkParallelPython','libvtkPatentedPython']  
      21     hiddenimports = ['libvtkCommonPython','libvtkFilteringPython','libvtkIOPython','libvtkImagingPython','libvtkGraphicsPython','libvtkRenderingPython','libvtkHybridPython','libvtkParallelPython','libvtkPatentedPython']  
    21 21 else:  
    22      hiddenimports = ['vtkCommonPython','vtkFilteringPython','vtkIOPython','vtkImagingPython','vtkGraphicsPython','vtkRenderingPython','vtkHybridPython','vtkParallelPython','vtkPatentedPython']  
    23    
      22     hiddenimports = ['vtkCommonPython','vtkFilteringPython','vtkIOPython','vtkImagingPython','vtkGraphicsPython','vtkRenderingPython','vtkHybridPython','vtkParallelPython','vtkPatentedPython']  
  • trunk/hooks/hook-iu.py

    r43 r485  
    37 37             del mod.imports[i]  
    38 38     return mod  
    39    
  • trunk/hooks/hook-xml.etree.cElementTree.py

    r322 r485  
    18 18 # cElementTree has a hidden import (Python >=2.5 stdlib version)  
    19 19 hiddenimports = ['xml.etree.ElementTree']  
    20    
  • trunk/hooks/hook-pythoncom.py

    r43 r485  
    37 37         mod = mf.ExtensionModule(newname, pth)  
    38 38     return mod  
    39    
  • trunk/hooks/hook-os.py

    r43 r485  
    42 42             del mod.imports[i]  
    43 43     return mod  
    44    
  • trunk/hooks/hook-carchive.py

    r43 r485  
    23 23                 del mod.imports[i]  
    24 24     return mod  
    25    
  • trunk/Build.py

    r484 r485  
    201 201         ###################################################  
    202 202         # Scan inputs and prepare:  
    203           dirs = {}  # input directories   
      203         dirs = {}  # input directories  
    203 203         pynms = [] # python filenames with no extension  
    204 204         for script in self.inputs:  
  • trunk/versionInfo.py

    r43 r485  
    529 529         print "Examining", sys.argv[1]  
    530 530         decode(sys.argv[1])  
    531    
  • trunk/mf.py

    r484 r485  
    244 244                 co = loadco(stuff[8:])  
    245 245             return PyModule(nm, fnm, co)  
    246           return None             
      246         return None  
    246 246  
    247 247 class PathImportDirector(ImportDirector):  
  • trunk/ArchiveViewer.py

    r472 r485  
    148 148             we understand.  
    149 149         """  
    150           self.lib.seek(self.start)       #default - magic is at start of file         self.lib.seek(self.start)       #default - magic is at start of file  
      150         self.lib.seek(self.start)       #default - magic is at start of file         self.lib.seek(self.start)       #default - magic is at start of file  
    150 150         if self.lib.read(len(self.MAGIC)) != self.MAGIC:  
    151 151             raise RuntimeError, "%s is not a valid %s archive file" \  
     
    158 158 if __name__ == '__main__':  
    159 159     main()  
    160    
  • trunk/e2etests/win32/NextID.py

    r43 r485  
    77 77         win32com.server.localserver.main()  
    78 78         raw_input("Press any key...")  
    79    
  • trunk/e2etests/win32/testMSOffice.py

    r43 r485  
    35 35 # Test a few of the MSOffice components.  
    36 36 def TestWord():  
    37           # Try and load the object exposed by Word 8  
    38           # Office 97 - _totally_ different object model!  
    39           try:  
    40                   # NOTE - using "client.Dispatch" would return an msword8.py instance!  
    41                   print "Starting Word 8 for dynamic test"  
    42                   word = win32com.client.dynamic.Dispatch("Word.Application")  
    43                   TestWord8(word)  
    44    
    45                   word = None  
    46                   # Now we will test Dispatch without the new "lazy" capabilities  
    47                   print "Starting Word 8 for non-lazy dynamic test"  
    48                   dispatch = win32com.client.dynamic._GetGoodDispatch("Word.Application")  
    49                   typeinfo = dispatch.GetTypeInfo()  
    50                   attr = typeinfo.GetTypeAttr()  
    51                   olerepr = win32com.client.build.DispatchItem(typeinfo, attr, None, 0)  
    52                   word = win32com.client.dynamic.CDispatch(dispatch, olerepr)  
    53                   dispatch = typeinfo = attr = olerepr = None  
    54                   TestWord8(word)  
    55    
    56           except pythoncom.com_error:  
    57                   print "Starting Word 7 for dynamic test"  
    58                   word = win32com.client.Dispatch("Word.Basic")  
    59                   TestWord7(word)  
    60    
    61           try:  
    62                   print "Starting MSWord for generated test"  
    63                   # Typelib, lcid, major and minor for the typelib  
    64                   try:  
    65                           o = gencache.EnsureModule("{00020905-0000-0000-C000-000000000046}", 1033, 8, 0, bForDemand=1)  
    66                   except TypeError:  
    67                           o = gencache.EnsureModule("{00020905-0000-0000-C000-000000000046}", 1033, 8, 0)  
    68                   if o is None :  
    69                           raise ImportError, "Can not load the Word8 typelibrary."  
    70                   word = win32com.client.Dispatch("Word.Application.8")  
    71                   TestWord8(word)  
    72           except ImportError, details:  
    73                   print "Can not test MSWord8 -", details  
      37     # Try and load the object exposed by Word 8  
      38     # Office 97 - _totally_ different object model!  
      39     try:  
      40         # NOTE - using "client.Dispatch" would return an msword8.py instance!  
      41         print "Starting Word 8 for dynamic test"  
      42         word = win32com.client.dynamic.Dispatch("Word.Application")  
      43         TestWord8(word)  
      44  
      45         word = None  
      46         # Now we will test Dispatch without the new "lazy" capabilities  
      47         print "Starting Word 8 for non-lazy dynamic test"  
      48         dispatch = win32com.client.dynamic._GetGoodDispatch("Word.Application")  
      49         typeinfo = dispatch.GetTypeInfo()  
      50         attr = typeinfo.GetTypeAttr()  
      51         olerepr = win32com.client.build.DispatchItem(typeinfo, attr, None, 0)  
      52         word = win32com.client.dynamic.CDispatch(dispatch, olerepr)  
      53         dispatch = typeinfo = attr = olerepr = None  
      54         TestWord8(word)  
      55  
      56     except pythoncom.com_error:  
      57         print "Starting Word 7 for dynamic test"  
      58         word = win32com.client.Dispatch("Word.Basic")  
      59         TestWord7(word)  
      60  
      61     try:  
      62         print "Starting MSWord for generated test"  
      63         # Typelib, lcid, major and minor for the typelib  
      64         try:  
      65             o = gencache.EnsureModule("{00020905-0000-0000-C000-000000000046}", 1033, 8, 0, bForDemand=1)  
      66         except TypeError:  
      67             o = gencache.EnsureModule("{00020905-0000-0000-C000-000000000046}", 1033, 8, 0)  
      68         if o is None :  
      69             raise ImportError, "Can not load the Word8 typelibrary."  
      70         word = win32com.client.Dispatch("Word.Application.8")  
      71         TestWord8(word)  
      72     except ImportError, details:  
      73         print "Can not test MSWord8 -", details  
    74 74  
    75 75 def TestWord7(word):  
    76           word.FileNew()  
    77           # If not shown, show the app.  
    78           if not word.AppShow(): word._proc_("AppShow")  
    79    
    80           for i in xrange(12):  
    81                   word.FormatFont(Color=i+1, Points=i+12)  
    82                   word.Insert("Hello from Python %d\n" % i)  
      76     word.FileNew()  
      77     # If not shown, show the app.  
      78     if not word.AppShow(): word._proc_("AppShow")  
      79  
      80     for i in xrange(12):  
      81         word.FormatFont(Color=i+1, Points=i+12)  
      82         word.Insert("Hello from Python %d\n" % i)  
    83 83  
    84           word.FileClose(2)  
      84     word.FileClose(2)  
    84 84  
    85 85 def TestWord8(word):  
    86           word.Visible = 1  
    87           doc = word.Documents.Add()  
    88           wrange = doc.Range()  
    89           for i in range(10):  
    90                   wrange.InsertAfter("Hello from Python %d\n" % i)  
    91           paras = doc.Paragraphs  
    92           for i in range(len(paras)):  
    93                   paras[i]().Font.ColorIndex = i+1  
    94                   paras[i]().Font.Size = 12 + (4 * i)  
    95           # XXX - note that  
    96           # for para in paras:  
    97           #       para().Font...  
    98           # doesnt seem to work - no error, just doesnt work  
    99           # Should check if it works for VB!  
    100           doc.Close(SaveChanges = 0)  
    101           word.Quit()  
    102           win32api.Sleep(1000) # Wait for word to close, else we  
    103           # may get OA error.  
      86     word.Visible = 1  
      87     doc = word.Documents.Add()  
      88     wrange = doc.Range()  
      89     for i in range(10):  
      90         wrange.InsertAfter("Hello from Python %d\n" % i)  
      91     paras = doc.Paragraphs  
      92     for i in range(len(paras)):  
      93         paras[i]().Font.ColorIndex = i+1  
      94         paras[i]().Font.Size = 12 + (4 * i)  
      95     # XXX - note that  
      96     # for para in paras:  
      97     #       para().Font...  
      98     # doesnt seem to work - no error, just doesnt work  
      99     # Should check if it works for VB!  
      100     doc.Close(SaveChanges = 0)  
      101     word.Quit()  
      102     win32api.Sleep(1000) # Wait for word to close, else we  
      103     # may get OA error.  
    104 104  
    105 105 def TestWord8OldStyle():  
    106           try:  
    107                   import win32com.test.Generated4Test.msword8  
    108           except ImportError:  
    109                   print "Can not do old style test"  
      106     try:  
      107         import win32com.test.Generated4Test.msword8  
      108     except ImportError:  
      109         print "Can not do old style test"  
    110 110  
    111 111  
    112 112 def TextExcel(xl):  
    113           xl.Visible = 0  
    114           if xl.Visible: raise error, "Visible property is true."  
    115           xl.Visible = 1  
    116           if not xl.Visible: raise error, "Visible property not true."  
      113     xl.Visible = 0  
      114     if xl.Visible: raise error, "Visible property is true."  
      115     xl.Visible = 1  
      116     if not xl.Visible: raise error, "Visible property not true."  
    117 117  
    118           if int(xl.Version[0])>=8:  
    119                   xl.Workbooks.Add()  
    120           else:  
    121