home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd2.bin / convert / eJayMp3Pro / mp3pro_demo.exe / IMGHDR.PYC (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-05  |  4.8 KB  |  152 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4.  
  5. def what(file, h = None):
  6.     if h is None:
  7.         if type(file) == type(''):
  8.             f = open(file, 'rb')
  9.             h = f.read(32)
  10.         else:
  11.             location = file.tell()
  12.             h = file.read(32)
  13.             file.seek(location)
  14.             f = None
  15.     else:
  16.         f = None
  17.     
  18.     try:
  19.         for tf in tests:
  20.             res = tf(h, f)
  21.     finally:
  22.         if f:
  23.             f.close()
  24.         
  25.  
  26.     return None
  27.  
  28. tests = []
  29.  
  30. def test_rgb(h, f):
  31.     if h[:2] == '\x01\xda':
  32.         return 'rgb'
  33.     
  34.  
  35. tests.append(test_rgb)
  36.  
  37. def test_gif(h, f):
  38.     if h[:6] in ('GIF87a', 'GIF89a'):
  39.         return 'gif'
  40.     
  41.  
  42. tests.append(test_gif)
  43.  
  44. def test_pbm(h, f):
  45.     if len(h) >= 3 and h[0] == 'P' and h[1] in '14' and h[2] in ' \t\n\r':
  46.         return 'pbm'
  47.     
  48.  
  49. tests.append(test_pbm)
  50.  
  51. def test_pgm(h, f):
  52.     if len(h) >= 3 and h[0] == 'P' and h[1] in '25' and h[2] in ' \t\n\r':
  53.         return 'pgm'
  54.     
  55.  
  56. tests.append(test_pgm)
  57.  
  58. def test_ppm(h, f):
  59.     if len(h) >= 3 and h[0] == 'P' and h[1] in '36' and h[2] in ' \t\n\r':
  60.         return 'ppm'
  61.     
  62.  
  63. tests.append(test_ppm)
  64.  
  65. def test_tiff(h, f):
  66.     if h[:2] in ('MM', 'II'):
  67.         return 'tiff'
  68.     
  69.  
  70. tests.append(test_tiff)
  71.  
  72. def test_rast(h, f):
  73.     if h[:4] == 'Y\xa6j\x95':
  74.         return 'rast'
  75.     
  76.  
  77. tests.append(test_rast)
  78.  
  79. def test_xbm(h, f):
  80.     s = '#define '
  81.     if h[:len(s)] == s:
  82.         return 'xbm'
  83.     
  84.  
  85. tests.append(test_xbm)
  86.  
  87. def test_jpeg(h, f):
  88.     if h[6:10] == 'JFIF':
  89.         return 'jpeg'
  90.     
  91.  
  92. tests.append(test_jpeg)
  93.  
  94. def test_bmp(h, f):
  95.     if h[:2] == 'BM':
  96.         return 'bmp'
  97.     
  98.  
  99. tests.append(test_bmp)
  100.  
  101. def test_png(h, f):
  102.     if h[:8] == '\x89PNG\r\n\x1a\n':
  103.         return 'png'
  104.     
  105.  
  106. tests.append(test_png)
  107.  
  108. def test():
  109.     import sys
  110.     recursive = 0
  111.     if sys.argv[1:] and sys.argv[1] == '-r':
  112.         del sys.argv[1:2]
  113.         recursive = 1
  114.     
  115.     
  116.     try:
  117.         if sys.argv[1:]:
  118.             testall(sys.argv[1:], recursive, 1)
  119.         else:
  120.             testall([
  121.                 '.'], recursive, 1)
  122.     except KeyboardInterrupt:
  123.         sys.stderr.write('\n[Interrupted]\n')
  124.         sys.exit(1)
  125.  
  126.  
  127.  
  128. def testall(list, recursive, toplevel):
  129.     import sys
  130.     import os
  131.     for filename in list:
  132.         if os.path.isdir(filename):
  133.             print filename + '/:',
  134.             if recursive or toplevel:
  135.                 print 'recursing down:'
  136.                 import glob
  137.                 names = glob.glob(os.path.join(filename, '*'))
  138.                 testall(names, recursive, 0)
  139.             else:
  140.                 print '*** directory (use -r) ***'
  141.         else:
  142.             print filename + ':',
  143.             sys.stdout.flush()
  144.             
  145.             try:
  146.                 print what(filename)
  147.             except IOError:
  148.                 print '*** not found ***'
  149.  
  150.     
  151.  
  152.