home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1829 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  13.0 KB  |  456 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4.  
  5. try:
  6.     credits._Printer__data = '\n    Python: %s\n\n    IPython: The IPython Development Team.\n    See http://ipython.scipy.org for more information.' % credits._Printer__data
  7.     copyright._Printer__data += '\n\n    Copyright (c) 2008-2009 The IPython Development Team.\n    Copyright (c) 2001-2007 Fernando Perez, Janko Hauser, Nathan Gray.\n    All Rights Reserved.'
  8. except NameError:
  9.     pass
  10.  
  11. import __main__
  12. import __builtin__
  13. import os
  14. import re
  15. import sys
  16. import types
  17. from pprint import pprint, pformat
  18. from IPython import DPyGetOpt
  19. from IPython import Release
  20. from IPython.ipstruct import Struct
  21. from IPython.OutputTrap import OutputTrap
  22. from IPython.ConfigLoader import ConfigLoader
  23. from IPython.iplib import InteractiveShell
  24. from IPython.usage import cmd_line_usage, interactive_usage
  25. from IPython.genutils import *
  26.  
  27. def force_import(modname, force_reload = False):
  28.     if modname in sys.modules and force_reload:
  29.         info('reloading: %s' % modname)
  30.         reload(sys.modules[modname])
  31.     else:
  32.         __import__(modname)
  33.  
  34.  
  35. def make_IPython(argv = None, user_ns = None, user_global_ns = None, debug = 1, rc_override = None, shell_class = InteractiveShell, embedded = False, **kw):
  36.     DEVDEBUG = False
  37.     if argv is None:
  38.         argv = sys.argv
  39.     
  40.     IP = shell_class('__IP', user_ns = user_ns, user_global_ns = user_global_ns, embedded = embedded, **kw)
  41.     
  42.     try:
  43.         _Helper = _Helper
  44.         import site
  45.         IP.user_ns['help'] = _Helper()
  46.     except ImportError:
  47.         warn('help() not available - check site.py')
  48.  
  49.     if DEVDEBUG:
  50.         ultraTB = ultraTB
  51.         import IPython
  52.         sys.excepthook = ultraTB.VerboseTB(call_pdb = 1)
  53.     
  54.     IP.BANNER_PARTS = [
  55.         'Python %s\nType "copyright", "credits" or "license" for more information.\n' % (sys.version.split('\n')[0],),
  56.         'IPython %s -- An enhanced Interactive Python.' % (Release.version,),
  57.         "?         -> Introduction and overview of IPython's features.\n%quickref -> Quick reference.\nhelp      -> Python's own help system.\nobject?   -> Details about 'object'. ?object also works, ?? prints more.\n"]
  58.     IP.usage = interactive_usage
  59.     if os.name == 'posix':
  60.         rc_suffix = ''
  61.     else:
  62.         rc_suffix = '.ini'
  63.     ipythondir_def = get_ipython_dir()
  64.     sys.path.insert(0, '')
  65.     import IPython
  66.     IPython_dir = os.path.dirname(IPython.__file__)
  67.     del IPython
  68.     cmdline_opts = 'autocall=i autoindent! automagic! banner! cache_size|cs=i c=s classic|cl color_info! colors=s confirm_exit! debug! deep_reload! editor=s log|l messages! nosep object_info_string_level=i pdb! pprint! prompt_in1|pi1=s prompt_in2|pi2=s prompt_out|po=s pydb! pylab_import_all! quick screen_length|sl=i prompts_pad_left=i logfile|lf=s logplay|lp=s profile|p=s readline! readline_merge_completions! readline_omit__names! rcfile=s separate_in|si=s separate_out|so=s separate_out2|so2=s xmode=s wildcards_case_sensitive! magic_docstrings system_verbose! multi_line_specials! term_title! wxversion=s autoedit_syntax!'
  69.     cmdline_only = 'help interact|i ipythondir=s Version upgrade gthread! qthread! q4thread! wthread! tkthread! pylab! tk! '
  70.     opts_names = qw(cmdline_opts) + qw(cmdline_only)
  71.     opts_def = Struct(autocall = 1, autoedit_syntax = 0, autoindent = 0, automagic = 1, autoexec = [], banner = 1, c = '', cache_size = 1000, classic = 0, color_info = 0, colors = 'NoColor', confirm_exit = 1, debug = 0, deep_reload = 0, editor = '0', gthread = 0, help = 0, interact = 0, ipythondir = ipythondir_def, log = 0, logfile = '', logplay = '', messages = 1, multi_line_specials = 1, nosep = 0, object_info_string_level = 0, pdb = 0, pprint = 0, profile = '', prompt_in1 = 'In [\\#]: ', prompt_in2 = '   .\\D.: ', prompt_out = 'Out[\\#]: ', prompts_pad_left = 1, pydb = 0, pylab = 0, pylab_import_all = 1, q4thread = 0, qthread = 0, quick = 0, quiet = 0, rcfile = 'ipythonrc' + rc_suffix, readline = 1, readline_merge_completions = 1, readline_omit__names = 0, screen_length = 0, separate_in = '\n', separate_out = '\n', separate_out2 = '', system_header = 'IPython system call: ', system_verbose = 0, term_title = 1, tk = 0, upgrade = 0, Version = 0, wildcards_case_sensitive = 1, wthread = 0, wxversion = '0', xmode = 'Context', magic_docstrings = 0)
  72.     rcfile_opts = {
  73.         qwflat: 'include import_mod import_all execfile ',
  74.         qw_lol: 'import_some ',
  75.         list_strings: 'execute alias readline_parse_and_bind ',
  76.         None: 'readline_remove_delims ' }
  77.     rc_def = Struct(include = [], import_mod = [], import_all = [], import_some = [
  78.         []], execute = [], execfile = [], alias = [], readline_parse_and_bind = [], readline_remove_delims = '')
  79.     typeconv = rcfile_opts.copy()
  80.     typeconv.update(optstr2types(cmdline_opts))
  81.     typeconv[None] += ' ' + rcfile_opts[None]
  82.     typeconv[unquote_ends] = typeconv[None]
  83.     del typeconv[None]
  84.     opts_all = opts_def.copy()
  85.     opts_all.update(rc_def)
  86.     conflict = {
  87.         'preserve': ' '.join([
  88.             typeconv[int],
  89.             typeconv[unquote_ends]]),
  90.         'add_flip': ' '.join([
  91.             typeconv[qwflat],
  92.             typeconv[qw_lol],
  93.             typeconv[list_strings]]) }
  94.     getopt = DPyGetOpt.DPyGetOpt()
  95.     getopt.setIgnoreCase(0)
  96.     getopt.parseConfiguration(opts_names)
  97.     
  98.     try:
  99.         getopt.processArguments(argv)
  100.     except DPyGetOpt.ArgumentError:
  101.         exc = None
  102.         print cmd_line_usage
  103.         warn('\nError in Arguments: "%s"' % exc)
  104.         sys.exit(1)
  105.  
  106.     opts = Struct(getopt.optionValues)
  107.     args = getopt.freeValues
  108.     opts_all.update(opts)
  109.     if opts_all.help:
  110.         page(cmd_line_usage)
  111.         sys.exit()
  112.     
  113.     if opts_all.Version:
  114.         print Release.version
  115.         sys.exit()
  116.     
  117.     if opts_all.magic_docstrings:
  118.         IP.magic_magic('-latex')
  119.         sys.exit()
  120.     
  121.     sys.path.append(os.path.abspath(opts_all.ipythondir))
  122.     if not os.path.isdir(opts_all.ipythondir):
  123.         IP.user_setup(opts_all.ipythondir, rc_suffix, 'install')
  124.     
  125.     if opts_all.upgrade:
  126.         IP.user_setup(opts_all.ipythondir, rc_suffix, 'upgrade')
  127.     
  128.     mutex_opts(opts, [
  129.         qw('log logfile'),
  130.         qw('rcfile profile'),
  131.         qw('classic profile'),
  132.         qw('classic rcfile')])
  133.     load_logplay = 0
  134.     if opts_all.logplay:
  135.         load_logplay = opts_all.logplay
  136.         opts_debug_save = opts_all.debug
  137.         
  138.         try:
  139.             logplay = open(opts_all.logplay)
  140.         except IOError:
  141.             if opts_all.debug:
  142.                 IP.InteractiveTB()
  143.             
  144.             warn('Could not open logplay file ' + `opts_all.logplay`)
  145.             logplay = None
  146.             load_logplay = 0
  147.             del opts_all.logplay
  148.  
  149.         
  150.         try:
  151.             logplay.readline()
  152.             logplay.readline()
  153.             cmd = logplay.readline()[6:]
  154.             exec cmd
  155.             opts.debug = opts_debug_save
  156.             opts.logplay = load_logplay
  157.             opts_all.update(opts)
  158.             cmd = logplay.readline()[6:]
  159.             exec cmd
  160.             logplay.close()
  161.         logplay.close()
  162.         if opts_all.debug:
  163.             IP.InteractiveTB()
  164.         
  165.  
  166.         warn("Logplay file lacking full configuration information.\nI'll try to read it, but some things may not work.")
  167.     
  168.     opts_all.logplay
  169.     msg_out = 'Output messages. '
  170.     msg_err = 'Error messages. '
  171.     msg_sep = '\n'
  172.     msg = Struct(config = OutputTrap('Configuration Loader', msg_out, msg_err, msg_sep, debug, quiet_out = 1), user_exec = OutputTrap('User File Execution', msg_out, msg_err, msg_sep, debug), logplay = OutputTrap('Log Loader', msg_out, msg_err, msg_sep, debug), summary = '')
  173.     msg.config.trap_all()
  174.     
  175.     try:
  176.         opts_all.rcfile = filefind(opts_all.rcfile, opts_all.ipythondir)
  177.     except IOError:
  178.         if opts_all.debug:
  179.             IP.InteractiveTB()
  180.         
  181.         warn('Configuration file %s not found. Ignoring request.' % opts_all.rcfile)
  182.  
  183.     profile_handled_by_legacy = False
  184.     if opts_all.profile:
  185.         
  186.         try:
  187.             opts_all.rcfile = filefind('ipythonrc-' + opts_all.profile + rc_suffix, opts_all.ipythondir)
  188.             profile_handled_by_legacy = True
  189.         except IOError:
  190.             if opts_all.debug:
  191.                 IP.InteractiveTB()
  192.             
  193.             opts.profile = ''
  194.         except:
  195.             None<EXCEPTION MATCH>IOError
  196.         
  197.  
  198.     None<EXCEPTION MATCH>IOError
  199.     rcfiledata = None
  200.     if opts_all.quick:
  201.         print 'Launching IPython in quick mode. No config file read.'
  202.     elif opts_all.rcfile:
  203.         
  204.         try:
  205.             cfg_loader = ConfigLoader(conflict)
  206.             rcfiledata = cfg_loader.load(opts_all.rcfile, typeconv, 'include', opts_all.ipythondir, purge = 1, unique = conflict['preserve'])
  207.         IP.InteractiveTB()
  208.         warn('Problems loading configuration file ' + `opts_all.rcfile` + '\nStarting with default -bare bones- configuration.')
  209.  
  210.     else:
  211.         warn('No valid configuration file found in either currrent directory\n' + 'or in the IPython config. directory: ' + `opts_all.ipythondir` + '\nProceeding with internal defaults.')
  212.     otrap = OutputTrap(trap_out = 1)
  213.     IP.magic_xmode(opts_all.xmode)
  214.     otrap.release_out()
  215.     IP.rc = rc_def.copy()
  216.     IP_rc = IP.rc
  217.     IP_rc.update(opts_def)
  218.     if rcfiledata:
  219.         IP_rc.update(rcfiledata)
  220.     
  221.     IP_rc.update(opts)
  222.     IP_rc.update(rc_override)
  223.     IP_rc.opts = opts
  224.     IP_rc.args = args
  225.     IP.runtime_rc = Struct()
  226.     if IP_rc.classic:
  227.         IP_rc.quick = 1
  228.         IP_rc.cache_size = 0
  229.         IP_rc.pprint = 0
  230.         IP_rc.prompt_in1 = '>>> '
  231.         IP_rc.prompt_in2 = '... '
  232.         IP_rc.prompt_out = ''
  233.         IP_rc.separate_in = IP_rc.separate_out = IP_rc.separate_out2 = '0'
  234.         IP_rc.colors = 'NoColor'
  235.         IP_rc.xmode = 'Plain'
  236.     
  237.     IP.pre_config_initialization()
  238.     otrap.trap_out()
  239.     IP.magic_xmode(IP_rc.xmode)
  240.     otrap.release_out()
  241.     if IP_rc.logplay:
  242.         IP.magic_logstart(IP_rc.logplay + ' append')
  243.     elif IP_rc.logfile:
  244.         IP.magic_logstart(IP_rc.logfile)
  245.     elif IP_rc.log:
  246.         IP.magic_logstart()
  247.     
  248.     if IP_rc.editor.strip() == '0':
  249.         
  250.         try:
  251.             ed = os.environ['EDITOR']
  252.         except KeyError:
  253.             if os.name == 'posix':
  254.                 ed = 'vi'
  255.             else:
  256.                 ed = 'notepad'
  257.         except:
  258.             os.name == 'posix'
  259.  
  260.         IP_rc.editor = ed
  261.     
  262.     IP_rc.embedded = IP.embedded
  263.     
  264.     try:
  265.         deep_reload = deep_reload
  266.         import IPython
  267.         if IP_rc.deep_reload:
  268.             __builtin__.reload = deep_reload.reload
  269.         else:
  270.             __builtin__.dreload = deep_reload.reload
  271.         del deep_reload
  272.     except ImportError:
  273.         pass
  274.  
  275.     IP.internal_ns.update(__main__.__dict__)
  276.     if IP_rc.debug:
  277.         print 'Trying to execute the following configuration structure:'
  278.         print '(Things listed first are deeper in the inclusion tree and get'
  279.         print 'loaded first).\n'
  280.         pprint(IP_rc.__dict__)
  281.     
  282.     for mod in IP_rc.import_mod:
  283.         
  284.         try:
  285.             exec 'import ' + mod in IP.user_ns
  286.         continue
  287.         IP.InteractiveTB()
  288.         import_fail_info(mod)
  289.         continue
  290.  
  291.     
  292.     for mod_fn in IP_rc.import_some:
  293.         if not mod_fn == []:
  294.             mod = mod_fn[0]
  295.             fn = ','.join(mod_fn[1:])
  296.             
  297.             try:
  298.                 exec 'from ' + mod + ' import ' + fn in IP.user_ns
  299.             IP.InteractiveTB()
  300.             import_fail_info(mod, fn)
  301.  
  302.             continue
  303.     
  304.     for mod in IP_rc.import_all:
  305.         
  306.         try:
  307.             exec 'from ' + mod + ' import *' in IP.user_ns
  308.         continue
  309.         IP.InteractiveTB()
  310.         import_fail_info(mod)
  311.         continue
  312.  
  313.     
  314.     for code in IP_rc.execute:
  315.         
  316.         try:
  317.             exec code in IP.user_ns
  318.         continue
  319.         IP.InteractiveTB()
  320.         warn('Failure executing code: ' + `code`)
  321.         continue
  322.  
  323.     
  324.     for file in IP_rc.execfile:
  325.         
  326.         try:
  327.             file = filefind(file, sys.path + [
  328.                 IPython_dir])
  329.         except IOError:
  330.             warn(itpl('File $file not found. Skipping it.'))
  331.             continue
  332.  
  333.         IP.safe_execfile(os.path.expanduser(file), IP.user_ns)
  334.     
  335.     
  336.     try:
  337.         import ipy_system_conf
  338.     except ImportError:
  339.         if opts_all.debug:
  340.             IP.InteractiveTB()
  341.         
  342.         warn("Could not import 'ipy_system_conf'")
  343.     except:
  344.         IP.InteractiveTB()
  345.         import_fail_info('ipy_system_conf')
  346.  
  347.     if opts_all.profile and not profile_handled_by_legacy:
  348.         profmodname = 'ipy_profile_' + opts_all.profile
  349.         
  350.         try:
  351.             force_import(profmodname)
  352.         except:
  353.             IP.InteractiveTB()
  354.             print 'Error importing', profmodname, '- perhaps you should run %upgrade?'
  355.             import_fail_info(profmodname)
  356.  
  357.         opts.profile = opts_all.profile
  358.     else:
  359.         force_import('ipy_profile_none')
  360.     
  361.     try:
  362.         force_import('ipy_user_conf')
  363.     except:
  364.         conf = opts_all.ipythondir + '/ipy_user_conf.py'
  365.         IP.InteractiveTB()
  366.         if not os.path.isfile(conf):
  367.             warn(conf + ' does not exist, please run %upgrade!')
  368.         
  369.         import_fail_info('ipy_user_conf')
  370.  
  371.     
  372.     try:
  373.         histfname = 'history-%s' % opts.profile
  374.     except AttributeError:
  375.         histfname = 'history'
  376.  
  377.     IP.histfile = os.path.join(opts_all.ipythondir, histfname)
  378.     IP_rc.update(opts)
  379.     msg.config.release_all()
  380.     if IP_rc.messages:
  381.         msg.summary += msg.config.summary_all()
  382.     
  383.     IP.user_config_ns.update(IP.user_ns)
  384.     if load_logplay:
  385.         print 'Replaying log...'
  386.         
  387.         try:
  388.             if IP_rc.debug:
  389.                 logplay_quiet = 0
  390.             else:
  391.                 logplay_quiet = 1
  392.             msg.logplay.trap_all()
  393.             IP.safe_execfile(load_logplay, IP.user_ns, islog = 1, quiet = logplay_quiet)
  394.             msg.logplay.release_all()
  395.             if IP_rc.messages:
  396.                 msg.summary += msg.logplay.summary_all()
  397.         warn('Problems replaying logfile %s.' % load_logplay)
  398.         IP.InteractiveTB()
  399.  
  400.     
  401.     msg.user_exec.trap_all()
  402.     if not embedded and IP_rc.args and not IP_rc.args[0].lower().endswith('.ipy'):
  403.         name_save = IP.user_ns['__name__']
  404.         IP.user_ns['__name__'] = '__main__'
  405.         old_excepthook = sys.excepthook
  406.         sys.excepthook = IP.excepthook
  407.         save_argv = sys.argv[1:]
  408.         sys.argv = args
  409.         
  410.         try:
  411.             IP.safe_execfile(args[0], IP.user_ns)
  412.         finally:
  413.             sys.excepthook = old_excepthook
  414.             sys.argv[:] = save_argv
  415.             IP.user_ns['__name__'] = name_save
  416.  
  417.     
  418.     msg.user_exec.release_all()
  419.     if IP_rc.messages:
  420.         msg.summary += msg.user_exec.summary_all()
  421.     
  422.     if IP_rc.nosep:
  423.         IP_rc.separate_in = IP_rc.separate_out = IP_rc.separate_out2 = '0'
  424.     
  425.     if IP_rc.separate_in == '0':
  426.         IP_rc.separate_in = ''
  427.     
  428.     if IP_rc.separate_out == '0':
  429.         IP_rc.separate_out = ''
  430.     
  431.     if IP_rc.separate_out2 == '0':
  432.         IP_rc.separate_out2 = ''
  433.     
  434.     IP_rc.separate_in = IP_rc.separate_in.replace('\\n', '\n')
  435.     IP_rc.separate_out = IP_rc.separate_out.replace('\\n', '\n')
  436.     IP_rc.separate_out2 = IP_rc.separate_out2.replace('\\n', '\n')
  437.     num_lines_bot = IP_rc.separate_in.count('\n') + 1
  438.     IP_rc.screen_length = IP_rc.screen_length - num_lines_bot
  439.     if IP_rc.c:
  440.         IP_rc.banner = 0
  441.     
  442.     if IP_rc.banner:
  443.         BANN_P = IP.BANNER_PARTS
  444.     else:
  445.         BANN_P = []
  446.     if IP_rc.profile:
  447.         BANN_P.append('IPython profile: %s\n' % IP_rc.profile)
  448.     
  449.     if msg.summary:
  450.         BANN_P.append(msg.summary)
  451.     
  452.     IP.BANNER = '\n'.join(BANN_P)
  453.     IP.post_config_initialization()
  454.     return IP
  455.  
  456.