home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) try: 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 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.' except NameError: pass import __main__ import __builtin__ import os import re import sys import types from pprint import pprint, pformat from IPython import DPyGetOpt from IPython import Release from IPython.ipstruct import Struct from IPython.OutputTrap import OutputTrap from IPython.ConfigLoader import ConfigLoader from IPython.iplib import InteractiveShell from IPython.usage import cmd_line_usage, interactive_usage from IPython.genutils import * def force_import(modname, force_reload = False): if modname in sys.modules and force_reload: info('reloading: %s' % modname) reload(sys.modules[modname]) else: __import__(modname) def make_IPython(argv = None, user_ns = None, user_global_ns = None, debug = 1, rc_override = None, shell_class = InteractiveShell, embedded = False, **kw): DEVDEBUG = False if argv is None: argv = sys.argv IP = shell_class('__IP', user_ns = user_ns, user_global_ns = user_global_ns, embedded = embedded, **kw) try: _Helper = _Helper import site IP.user_ns['help'] = _Helper() except ImportError: warn('help() not available - check site.py') if DEVDEBUG: ultraTB = ultraTB import IPython sys.excepthook = ultraTB.VerboseTB(call_pdb = 1) IP.BANNER_PARTS = [ 'Python %s\nType "copyright", "credits" or "license" for more information.\n' % (sys.version.split('\n')[0],), 'IPython %s -- An enhanced Interactive Python.' % (Release.version,), "? -> 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"] IP.usage = interactive_usage if os.name == 'posix': rc_suffix = '' else: rc_suffix = '.ini' ipythondir_def = get_ipython_dir() sys.path.insert(0, '') import IPython IPython_dir = os.path.dirname(IPython.__file__) del IPython 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!' cmdline_only = 'help interact|i ipythondir=s Version upgrade gthread! qthread! q4thread! wthread! tkthread! pylab! tk! ' opts_names = qw(cmdline_opts) + qw(cmdline_only) 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) rcfile_opts = { qwflat: 'include import_mod import_all execfile ', qw_lol: 'import_some ', list_strings: 'execute alias readline_parse_and_bind ', None: 'readline_remove_delims ' } rc_def = Struct(include = [], import_mod = [], import_all = [], import_some = [ []], execute = [], execfile = [], alias = [], readline_parse_and_bind = [], readline_remove_delims = '') typeconv = rcfile_opts.copy() typeconv.update(optstr2types(cmdline_opts)) typeconv[None] += ' ' + rcfile_opts[None] typeconv[unquote_ends] = typeconv[None] del typeconv[None] opts_all = opts_def.copy() opts_all.update(rc_def) conflict = { 'preserve': ' '.join([ typeconv[int], typeconv[unquote_ends]]), 'add_flip': ' '.join([ typeconv[qwflat], typeconv[qw_lol], typeconv[list_strings]]) } getopt = DPyGetOpt.DPyGetOpt() getopt.setIgnoreCase(0) getopt.parseConfiguration(opts_names) try: getopt.processArguments(argv) except DPyGetOpt.ArgumentError: exc = None print cmd_line_usage warn('\nError in Arguments: "%s"' % exc) sys.exit(1) opts = Struct(getopt.optionValues) args = getopt.freeValues opts_all.update(opts) if opts_all.help: page(cmd_line_usage) sys.exit() if opts_all.Version: print Release.version sys.exit() if opts_all.magic_docstrings: IP.magic_magic('-latex') sys.exit() sys.path.append(os.path.abspath(opts_all.ipythondir)) if not os.path.isdir(opts_all.ipythondir): IP.user_setup(opts_all.ipythondir, rc_suffix, 'install') if opts_all.upgrade: IP.user_setup(opts_all.ipythondir, rc_suffix, 'upgrade') mutex_opts(opts, [ qw('log logfile'), qw('rcfile profile'), qw('classic profile'), qw('classic rcfile')]) load_logplay = 0 if opts_all.logplay: load_logplay = opts_all.logplay opts_debug_save = opts_all.debug try: logplay = open(opts_all.logplay) except IOError: if opts_all.debug: IP.InteractiveTB() warn('Could not open logplay file ' + `opts_all.logplay`) logplay = None load_logplay = 0 del opts_all.logplay try: logplay.readline() logplay.readline() cmd = logplay.readline()[6:] exec cmd opts.debug = opts_debug_save opts.logplay = load_logplay opts_all.update(opts) cmd = logplay.readline()[6:] exec cmd logplay.close() logplay.close() if opts_all.debug: IP.InteractiveTB() warn("Logplay file lacking full configuration information.\nI'll try to read it, but some things may not work.") opts_all.logplay msg_out = 'Output messages. ' msg_err = 'Error messages. ' msg_sep = '\n' 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 = '') msg.config.trap_all() try: opts_all.rcfile = filefind(opts_all.rcfile, opts_all.ipythondir) except IOError: if opts_all.debug: IP.InteractiveTB() warn('Configuration file %s not found. Ignoring request.' % opts_all.rcfile) profile_handled_by_legacy = False if opts_all.profile: try: opts_all.rcfile = filefind('ipythonrc-' + opts_all.profile + rc_suffix, opts_all.ipythondir) profile_handled_by_legacy = True except IOError: if opts_all.debug: IP.InteractiveTB() opts.profile = '' except: None<EXCEPTION MATCH>IOError None<EXCEPTION MATCH>IOError rcfiledata = None if opts_all.quick: print 'Launching IPython in quick mode. No config file read.' elif opts_all.rcfile: try: cfg_loader = ConfigLoader(conflict) rcfiledata = cfg_loader.load(opts_all.rcfile, typeconv, 'include', opts_all.ipythondir, purge = 1, unique = conflict['preserve']) IP.InteractiveTB() warn('Problems loading configuration file ' + `opts_all.rcfile` + '\nStarting with default -bare bones- configuration.') else: warn('No valid configuration file found in either currrent directory\n' + 'or in the IPython config. directory: ' + `opts_all.ipythondir` + '\nProceeding with internal defaults.') otrap = OutputTrap(trap_out = 1) IP.magic_xmode(opts_all.xmode) otrap.release_out() IP.rc = rc_def.copy() IP_rc = IP.rc IP_rc.update(opts_def) if rcfiledata: IP_rc.update(rcfiledata) IP_rc.update(opts) IP_rc.update(rc_override) IP_rc.opts = opts IP_rc.args = args IP.runtime_rc = Struct() if IP_rc.classic: IP_rc.quick = 1 IP_rc.cache_size = 0 IP_rc.pprint = 0 IP_rc.prompt_in1 = '>>> ' IP_rc.prompt_in2 = '... ' IP_rc.prompt_out = '' IP_rc.separate_in = IP_rc.separate_out = IP_rc.separate_out2 = '0' IP_rc.colors = 'NoColor' IP_rc.xmode = 'Plain' IP.pre_config_initialization() otrap.trap_out() IP.magic_xmode(IP_rc.xmode) otrap.release_out() if IP_rc.logplay: IP.magic_logstart(IP_rc.logplay + ' append') elif IP_rc.logfile: IP.magic_logstart(IP_rc.logfile) elif IP_rc.log: IP.magic_logstart() if IP_rc.editor.strip() == '0': try: ed = os.environ['EDITOR'] except KeyError: if os.name == 'posix': ed = 'vi' else: ed = 'notepad' except: os.name == 'posix' IP_rc.editor = ed IP_rc.embedded = IP.embedded try: deep_reload = deep_reload import IPython if IP_rc.deep_reload: __builtin__.reload = deep_reload.reload else: __builtin__.dreload = deep_reload.reload del deep_reload except ImportError: pass IP.internal_ns.update(__main__.__dict__) if IP_rc.debug: print 'Trying to execute the following configuration structure:' print '(Things listed first are deeper in the inclusion tree and get' print 'loaded first).\n' pprint(IP_rc.__dict__) for mod in IP_rc.import_mod: try: exec 'import ' + mod in IP.user_ns continue IP.InteractiveTB() import_fail_info(mod) continue for mod_fn in IP_rc.import_some: if not mod_fn == []: mod = mod_fn[0] fn = ','.join(mod_fn[1:]) try: exec 'from ' + mod + ' import ' + fn in IP.user_ns IP.InteractiveTB() import_fail_info(mod, fn) continue for mod in IP_rc.import_all: try: exec 'from ' + mod + ' import *' in IP.user_ns continue IP.InteractiveTB() import_fail_info(mod) continue for code in IP_rc.execute: try: exec code in IP.user_ns continue IP.InteractiveTB() warn('Failure executing code: ' + `code`) continue for file in IP_rc.execfile: try: file = filefind(file, sys.path + [ IPython_dir]) except IOError: warn(itpl('File $file not found. Skipping it.')) continue IP.safe_execfile(os.path.expanduser(file), IP.user_ns) try: import ipy_system_conf except ImportError: if opts_all.debug: IP.InteractiveTB() warn("Could not import 'ipy_system_conf'") except: IP.InteractiveTB() import_fail_info('ipy_system_conf') if opts_all.profile and not profile_handled_by_legacy: profmodname = 'ipy_profile_' + opts_all.profile try: force_import(profmodname) except: IP.InteractiveTB() print 'Error importing', profmodname, '- perhaps you should run %upgrade?' import_fail_info(profmodname) opts.profile = opts_all.profile else: force_import('ipy_profile_none') try: force_import('ipy_user_conf') except: conf = opts_all.ipythondir + '/ipy_user_conf.py' IP.InteractiveTB() if not os.path.isfile(conf): warn(conf + ' does not exist, please run %upgrade!') import_fail_info('ipy_user_conf') try: histfname = 'history-%s' % opts.profile except AttributeError: histfname = 'history' IP.histfile = os.path.join(opts_all.ipythondir, histfname) IP_rc.update(opts) msg.config.release_all() if IP_rc.messages: msg.summary += msg.config.summary_all() IP.user_config_ns.update(IP.user_ns) if load_logplay: print 'Replaying log...' try: if IP_rc.debug: logplay_quiet = 0 else: logplay_quiet = 1 msg.logplay.trap_all() IP.safe_execfile(load_logplay, IP.user_ns, islog = 1, quiet = logplay_quiet) msg.logplay.release_all() if IP_rc.messages: msg.summary += msg.logplay.summary_all() warn('Problems replaying logfile %s.' % load_logplay) IP.InteractiveTB() msg.user_exec.trap_all() if not embedded and IP_rc.args and not IP_rc.args[0].lower().endswith('.ipy'): name_save = IP.user_ns['__name__'] IP.user_ns['__name__'] = '__main__' old_excepthook = sys.excepthook sys.excepthook = IP.excepthook save_argv = sys.argv[1:] sys.argv = args try: IP.safe_execfile(args[0], IP.user_ns) finally: sys.excepthook = old_excepthook sys.argv[:] = save_argv IP.user_ns['__name__'] = name_save msg.user_exec.release_all() if IP_rc.messages: msg.summary += msg.user_exec.summary_all() if IP_rc.nosep: IP_rc.separate_in = IP_rc.separate_out = IP_rc.separate_out2 = '0' if IP_rc.separate_in == '0': IP_rc.separate_in = '' if IP_rc.separate_out == '0': IP_rc.separate_out = '' if IP_rc.separate_out2 == '0': IP_rc.separate_out2 = '' IP_rc.separate_in = IP_rc.separate_in.replace('\\n', '\n') IP_rc.separate_out = IP_rc.separate_out.replace('\\n', '\n') IP_rc.separate_out2 = IP_rc.separate_out2.replace('\\n', '\n') num_lines_bot = IP_rc.separate_in.count('\n') + 1 IP_rc.screen_length = IP_rc.screen_length - num_lines_bot if IP_rc.c: IP_rc.banner = 0 if IP_rc.banner: BANN_P = IP.BANNER_PARTS else: BANN_P = [] if IP_rc.profile: BANN_P.append('IPython profile: %s\n' % IP_rc.profile) if msg.summary: BANN_P.append(msg.summary) IP.BANNER = '\n'.join(BANN_P) IP.post_config_initialization() return IP