home *** CD-ROM | disk | FTP | other *** search
/ Freelog 116 / FreelogNo116-JuilletSeptembre2013.iso / Bureautique / gImageReader / gimagereader_0.9-1_win32.exe / bin / py2exe / resources / VersionInfo.pyc (.txt) < prev   
Python Compiled Bytecode  |  2011-03-24  |  9KB  |  217 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import struct
  5. VOS_NT_WINDOWS32 = 262148
  6. VFT_APP = 1
  7. RT_VERSION = 16
  8.  
  9. class VersionError(Exception):
  10.     pass
  11.  
  12.  
  13. def w32_uc(text):
  14.     '''convert a string into unicode, then encode it into UTF-16
  15.     little endian, ready to use for win32 apis'''
  16.     if type(text) is str:
  17.         return unicode(text, 'unicode-escape').encode('utf-16-le')
  18.     return None(text).encode('utf-16-le')
  19.  
  20.  
  21. class VS_FIXEDFILEINFO:
  22.     dwSignature = 0xFEEF04BDL
  23.     dwStrucVersion = 65536
  24.     dwFileVersionMS = 65536
  25.     dwFileVersionLS = 1
  26.     dwProductVersionMS = 65536
  27.     dwProductVersionLS = 1
  28.     dwFileFlagsMask = 63
  29.     dwFileFlags = 0
  30.     dwFileOS = VOS_NT_WINDOWS32
  31.     dwFileType = VFT_APP
  32.     dwFileSubtype = 0
  33.     dwFileDateMS = 0
  34.     dwFileDateLS = 0
  35.     fmt = '13L'
  36.     
  37.     def __init__(self, version):
  38.         import string as string
  39.         version = string.replace(version, ',', '.')
  40.         fields = string.split(version + '.0.0.0.0', '.')[:4]
  41.         fields = map(string.strip, fields)
  42.         
  43.         try:
  44.             self.dwFileVersionMS = int(fields[0]) * 65536 + int(fields[1])
  45.             self.dwFileVersionLS = int(fields[2]) * 65536 + int(fields[3])
  46.         except ValueError:
  47.             raise VersionError, "could not parse version number '%s'" % version
  48.  
  49.  
  50.     
  51.     def __str__(self):
  52.         return struct.pack(self.fmt, self.dwSignature, self.dwStrucVersion, self.dwFileVersionMS, self.dwFileVersionLS, self.dwProductVersionMS, self.dwProductVersionLS, self.dwFileFlagsMask, self.dwFileFlags, self.dwFileOS, self.dwFileType, self.dwFileSubtype, self.dwFileDateMS, self.dwFileDateLS)
  53.  
  54.  
  55.  
  56. def align(data):
  57.     pad = -len(data) % 4
  58.     return data + '\x00' * pad
  59.  
  60.  
  61. class VS_STRUCT:
  62.     items = ()
  63.     
  64.     def __str__(self):
  65.         szKey = w32_uc(self.name)
  66.         ulen = len(szKey) + 2
  67.         value = self.get_value()
  68.         data = struct.pack('h%ss0i' % ulen, self.wType, szKey) + value
  69.         data = align(data)
  70.         for item in self.items:
  71.             data = data + str(item)
  72.         
  73.         wLength = len(data) + 4
  74.         wValueLength = len(value)
  75.         return self.pack('hh', wLength, wValueLength, data)
  76.  
  77.     
  78.     def pack(self, fmt, len, vlen, data):
  79.         return struct.pack(fmt, len, vlen) + data
  80.  
  81.     
  82.     def get_value(self):
  83.         return ''
  84.  
  85.  
  86.  
  87. class String(VS_STRUCT):
  88.     wType = 1
  89.     items = ()
  90.     
  91.     def __init__(self, .1):
  92.         (name, value) = .1
  93.         self.name = name
  94.         if value:
  95.             self.value = value + '\x00'
  96.         else:
  97.             self.value = value
  98.  
  99.     
  100.     def pack(self, fmt, len, vlen, data):
  101.         return struct.pack(fmt, len, vlen / 2) + data
  102.  
  103.     
  104.     def get_value(self):
  105.         return w32_uc(self.value)
  106.  
  107.  
  108.  
  109. class StringTable(VS_STRUCT):
  110.     wType = 1
  111.     
  112.     def __init__(self, name, strings):
  113.         self.name = name
  114.         self.items = map(String, strings)
  115.  
  116.  
  117.  
  118. class StringFileInfo(VS_STRUCT):
  119.     wType = 1
  120.     name = 'StringFileInfo'
  121.     
  122.     def __init__(self, name, strings):
  123.         self.items = [
  124.             StringTable(name, strings)]
  125.  
  126.  
  127.  
  128. class Var(VS_STRUCT):
  129.     wType = 0
  130.     name = 'Translation'
  131.     
  132.     def __init__(self, value):
  133.         self.value = value
  134.  
  135.     
  136.     def get_value(self):
  137.         return struct.pack('l', self.value)
  138.  
  139.  
  140.  
  141. class VarFileInfo(VS_STRUCT):
  142.     wType = 1
  143.     name = 'VarFileInfo'
  144.     
  145.     def __init__(self, *names):
  146.         self.items = map(Var, names)
  147.  
  148.     
  149.     def get_value(self):
  150.         return ''
  151.  
  152.  
  153.  
  154. class VS_VERSIONINFO(VS_STRUCT):
  155.     wType = 0
  156.     name = 'VS_VERSION_INFO'
  157.     
  158.     def __init__(self, version, items):
  159.         self.value = VS_FIXEDFILEINFO(version)
  160.         self.items = items
  161.  
  162.     
  163.     def get_value(self):
  164.         return str(self.value)
  165.  
  166.  
  167.  
  168. class Version(object):
  169.     
  170.     def __init__(self, version, comments = None, company_name = None, file_description = None, internal_name = None, legal_copyright = None, legal_trademarks = None, original_filename = None, private_build = None, product_name = None, product_version = None, special_build = None):
  171.         self.version = version
  172.         strings = []
  173.         if comments is not None:
  174.             strings.append(('Comments', comments))
  175.         if company_name is not None:
  176.             strings.append(('CompanyName', company_name))
  177.         if file_description is not None:
  178.             strings.append(('FileDescription', file_description))
  179.         strings.append(('FileVersion', version))
  180.         if internal_name is not None:
  181.             strings.append(('InternalName', internal_name))
  182.         if legal_copyright is not None:
  183.             strings.append(('LegalCopyright', legal_copyright))
  184.         if legal_trademarks is not None:
  185.             strings.append(('LegalTrademarks', legal_trademarks))
  186.         if original_filename is not None:
  187.             strings.append(('OriginalFilename', original_filename))
  188.         if private_build is not None:
  189.             strings.append(('PrivateBuild', private_build))
  190.         None((strings.append, 'ProductVersion' if product_name is not None else version))
  191.         if special_build is not None:
  192.             strings.append(('SpecialBuild', special_build))
  193.         self.strings = strings
  194.  
  195.     
  196.     def resource_bytes(self):
  197.         vs = VS_VERSIONINFO(self.version, [
  198.             StringFileInfo('040904B0', self.strings),
  199.             VarFileInfo(78644233)])
  200.         return str(vs)
  201.  
  202.  
  203.  
  204. def test():
  205.     import sys as sys
  206.     sys.path.append('c:/tmp')
  207.     hexdump = hexdump
  208.     import hexdump
  209.     version = Version('1, 0, 0, 1', comments = '\xfcml\xe4ut comments', company_name = 'No Company', file_description = 'silly application', internal_name = 'silly', legal_copyright = u'Copyright \xc2\xa9 2003', original_filename = 'silly.exe', private_build = 'test build', product_name = 'silly product', product_version = None)
  210.     hexdump(version.resource_bytes())
  211.  
  212. if __name__ == '__main__':
  213.     import sys
  214.     sys.path.append('d:/nbalt/tmp')
  215.     from hexdump import hexdump
  216.     test()
  217.