home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_2376 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  7.3 KB  |  265 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. MODULES = {
  5.     'basic': [
  6.         '_G',
  7.         '_VERSION',
  8.         'assert',
  9.         'collectgarbage',
  10.         'dofile',
  11.         'error',
  12.         'getfenv',
  13.         'getmetatable',
  14.         'ipairs',
  15.         'load',
  16.         'loadfile',
  17.         'loadstring',
  18.         'next',
  19.         'pairs',
  20.         'pcall',
  21.         'print',
  22.         'rawequal',
  23.         'rawget',
  24.         'rawset',
  25.         'select',
  26.         'setfenv',
  27.         'setmetatable',
  28.         'tonumber',
  29.         'tostring',
  30.         'type',
  31.         'unpack',
  32.         'xpcall'],
  33.     'coroutine': [
  34.         'coroutine.create',
  35.         'coroutine.resume',
  36.         'coroutine.running',
  37.         'coroutine.status',
  38.         'coroutine.wrap',
  39.         'coroutine.yield'],
  40.     'debug': [
  41.         'debug.debug',
  42.         'debug.getfenv',
  43.         'debug.gethook',
  44.         'debug.getinfo',
  45.         'debug.getlocal',
  46.         'debug.getmetatable',
  47.         'debug.getregistry',
  48.         'debug.getupvalue',
  49.         'debug.setfenv',
  50.         'debug.sethook',
  51.         'debug.setlocal',
  52.         'debug.setmetatable',
  53.         'debug.setupvalue',
  54.         'debug.traceback'],
  55.     'io': [
  56.         'file:close',
  57.         'file:flush',
  58.         'file:lines',
  59.         'file:read',
  60.         'file:seek',
  61.         'file:setvbuf',
  62.         'file:write',
  63.         'io.close',
  64.         'io.flush',
  65.         'io.input',
  66.         'io.lines',
  67.         'io.open',
  68.         'io.output',
  69.         'io.popen',
  70.         'io.read',
  71.         'io.tmpfile',
  72.         'io.type',
  73.         'io.write'],
  74.     'math': [
  75.         'math.abs',
  76.         'math.acos',
  77.         'math.asin',
  78.         'math.atan2',
  79.         'math.atan',
  80.         'math.ceil',
  81.         'math.cosh',
  82.         'math.cos',
  83.         'math.deg',
  84.         'math.exp',
  85.         'math.floor',
  86.         'math.fmod',
  87.         'math.frexp',
  88.         'math.huge',
  89.         'math.ldexp',
  90.         'math.log10',
  91.         'math.log',
  92.         'math.max',
  93.         'math.min',
  94.         'math.modf',
  95.         'math.pi',
  96.         'math.pow',
  97.         'math.rad',
  98.         'math.random',
  99.         'math.randomseed',
  100.         'math.sinh',
  101.         'math.sin',
  102.         'math.sqrt',
  103.         'math.tanh',
  104.         'math.tan'],
  105.     'modules': [
  106.         'module',
  107.         'require',
  108.         'package.cpath',
  109.         'package.loaded',
  110.         'package.loadlib',
  111.         'package.path',
  112.         'package.preload',
  113.         'package.seeall'],
  114.     'os': [
  115.         'os.clock',
  116.         'os.date',
  117.         'os.difftime',
  118.         'os.execute',
  119.         'os.exit',
  120.         'os.getenv',
  121.         'os.remove',
  122.         'os.rename',
  123.         'os.setlocale',
  124.         'os.time',
  125.         'os.tmpname'],
  126.     'string': [
  127.         'string.byte',
  128.         'string.char',
  129.         'string.dump',
  130.         'string.find',
  131.         'string.format',
  132.         'string.gmatch',
  133.         'string.gsub',
  134.         'string.len',
  135.         'string.lower',
  136.         'string.match',
  137.         'string.rep',
  138.         'string.reverse',
  139.         'string.sub',
  140.         'string.upper'],
  141.     'table': [
  142.         'table.concat',
  143.         'table.insert',
  144.         'table.maxn',
  145.         'table.remove',
  146.         'table.sort'] }
  147. if __name__ == '__main__':
  148.     import re
  149.     import urllib
  150.     import pprint
  151.     
  152.     def module_callbacks():
  153.         
  154.         def is_in_coroutine_module(name):
  155.             return name.startswith('coroutine.')
  156.  
  157.         
  158.         def is_in_modules_module(name):
  159.             if name in ('require', 'module') or name.startswith('package'):
  160.                 return True
  161.             return False
  162.  
  163.         
  164.         def is_in_string_module(name):
  165.             return name.startswith('string.')
  166.  
  167.         
  168.         def is_in_table_module(name):
  169.             return name.startswith('table.')
  170.  
  171.         
  172.         def is_in_math_module(name):
  173.             return name.startswith('math')
  174.  
  175.         
  176.         def is_in_io_module(name):
  177.             if not name.startswith('io.'):
  178.                 pass
  179.             return name.startswith('file:')
  180.  
  181.         
  182.         def is_in_os_module(name):
  183.             return name.startswith('os.')
  184.  
  185.         
  186.         def is_in_debug_module(name):
  187.             return name.startswith('debug.')
  188.  
  189.         return {
  190.             'coroutine': is_in_coroutine_module,
  191.             'modules': is_in_modules_module,
  192.             'string': is_in_string_module,
  193.             'table': is_in_table_module,
  194.             'math': is_in_math_module,
  195.             'io': is_in_io_module,
  196.             'os': is_in_os_module,
  197.             'debug': is_in_debug_module }
  198.  
  199.     
  200.     def get_newest_version():
  201.         f = urllib.urlopen('http://www.lua.org/manual/')
  202.         r = re.compile('^<A HREF="(\\d\\.\\d)/">Lua \\1</A>')
  203.         for line in f:
  204.             m = r.match(line)
  205.             if m is not None:
  206.                 return m.groups()[0]
  207.         
  208.  
  209.     
  210.     def get_lua_functions(version):
  211.         f = urllib.urlopen('http://www.lua.org/manual/%s/' % version)
  212.         r = re.compile('^<A HREF="manual.html#pdf-(.+)">\\1</A>')
  213.         functions = []
  214.         for line in f:
  215.             m = r.match(line)
  216.             if m is not None:
  217.                 functions.append(m.groups()[0])
  218.                 continue
  219.         
  220.         return functions
  221.  
  222.     
  223.     def get_function_module(name):
  224.         for mod, cb in module_callbacks().iteritems():
  225.             if cb(name):
  226.                 return mod
  227.         
  228.         if '.' in name:
  229.             return name.split('.')[0]
  230.         return 'basic'
  231.  
  232.     
  233.     def regenerate(filename, modules):
  234.         f = open(filename)
  235.         
  236.         try:
  237.             content = f.read()
  238.         finally:
  239.             f.close()
  240.  
  241.         header = content[:content.find('MODULES = {')]
  242.         footer = content[content.find("if __name__ == '__main__':"):]
  243.         f = open(filename, 'w')
  244.         f.write(header)
  245.         f.write('MODULES = %s\n\n' % pprint.pformat(modules))
  246.         f.write(footer)
  247.         f.close()
  248.  
  249.     
  250.     def run():
  251.         version = get_newest_version()
  252.         print '> Downloading function index for Lua %s' % version
  253.         functions = get_lua_functions(version)
  254.         print '> %d functions found:' % len(functions)
  255.         modules = { }
  256.         for full_function_name in functions:
  257.             print '>> %s' % full_function_name
  258.             m = get_function_module(full_function_name)
  259.             modules.setdefault(m, []).append(full_function_name)
  260.         
  261.         regenerate(__file__, modules)
  262.  
  263.     run()
  264.  
  265.