diff --git a/.hgignore b/.hgignore deleted file mode 100644 index ecc75a2..0000000 --- a/.hgignore +++ /dev/null @@ -1,18 +0,0 @@ -syntax: glob - -*~ -*.tmp -*.pyc -*.bak -*.tgz -*.org -*.rej -.svn/ -.bzr/ -.settings/ -.project -*.diff -IPython_crash_report.txt - -syntax: regexp -.*\#.*\#$ diff --git a/IPython/ConfigLoader.py b/IPython/ConfigLoader.py deleted file mode 100644 index d64864d..0000000 --- a/IPython/ConfigLoader.py +++ /dev/null @@ -1,111 +0,0 @@ -# -*- coding: utf-8 -*- -"""Configuration loader -""" - -#***************************************************************************** -# Copyright (C) 2001-2006 Fernando Perez. -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#***************************************************************************** - -import exceptions -import os -from pprint import pprint - -from IPython import ultraTB -from IPython.ipstruct import Struct -from IPython.genutils import * - -class ConfigLoaderError(exceptions.Exception): - """Exception for ConfigLoader class.""" - - def __init__(self,args=None): - self.args = args - -class ConfigLoader: - - """Configuration file loader capable of handling recursive inclusions and - with parametrized conflict resolution for multiply found keys.""" - - def __init__(self,conflict=None,field_sep=None,reclimit=15): - - """The reclimit parameter controls the number of recursive - configuration file inclusions. This way we can stop early on (before - python's own recursion limit is hit) if there is a circular - inclusion. - - - conflict: dictionary for conflict resolutions (see Struct.merge()) - - """ - self.conflict = conflict - self.field_sep = field_sep - self.reset(reclimit) - - def reset(self,reclimit=15): - self.reclimit = reclimit - self.recdepth = 0 - self.included = [] - - def load(self,fname,convert=None,recurse_key='',incpath = '.',**kw): - """Load a configuration file, return the resulting Struct. - - Call: load_config(fname,convert=None,conflict=None,recurse_key='') - - - fname: file to load from. - - convert: dictionary of type conversions (see read_dict()) - - recurse_key: keyword in dictionary to trigger recursive file - inclusions. - """ - - if self.recdepth > self.reclimit: - raise ConfigLoaderError, 'maximum recursive inclusion of rcfiles '+\ - 'exceeded: ' + `self.recdepth` + \ - '.\nMaybe you have a circular chain of inclusions?' - self.recdepth += 1 - fname = filefind(fname,incpath) - data = Struct() - # avoid including the same file more than once - if fname in self.included: - return data - Xinfo = ultraTB.AutoFormattedTB(color_scheme='NoColor') - if convert==None and recurse_key : convert = {qwflat:recurse_key} - # for production, change warn to 0: - data.merge(read_dict(fname,convert,fs=self.field_sep,strip=1, - warn=0,no_empty=0,**kw)) - # keep track of successfully loaded files - self.included.append(fname) - if recurse_key in data: - for incfilename in data[recurse_key]: - found=0 - try: - incfile = filefind(incfilename,incpath) - except IOError: - if os.name in ['nt','dos']: - try: - # Try again with '.ini' extension - incfilename += '.ini' - incfile = filefind(incfilename,incpath) - except IOError: - found = 0 - else: - found = 1 - else: - found = 0 - else: - found = 1 - if found: - try: - data.merge(self.load(incfile,convert,recurse_key, - incpath,**kw), - self.conflict) - except: - Xinfo() - warn('Problem loading included file: '+ - `incfilename` + '. Ignoring it...') - else: - warn('File `%s` not found. Included by %s' % (incfilename,fname)) - - return data - -# end ConfigLoader diff --git a/IPython/CrashHandler.py b/IPython/CrashHandler.py deleted file mode 100644 index b437cac..0000000 --- a/IPython/CrashHandler.py +++ /dev/null @@ -1,230 +0,0 @@ -# -*- coding: utf-8 -*- -"""sys.excepthook for IPython itself, leaves a detailed report on disk. - - -Authors -------- -- Fernando Perez -""" - -#***************************************************************************** -# Copyright (C) 2008-2009 The IPython Development Team -# Copyright (C) 2001-2007 Fernando Perez. -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#***************************************************************************** - -#**************************************************************************** -# Required modules - -# From the standard library -import os -import sys -from pprint import pprint,pformat - -# Our own -from IPython import Release -from IPython import ultraTB -from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names -from IPython.Itpl import Itpl,itpl,printpl - -from IPython.genutils import * - -#**************************************************************************** -class CrashHandler: - """Customizable crash handlers for IPython-based systems. - - Instances of this class provide a __call__ method which can be used as a - sys.excepthook, i.e., the __call__ signature is: - - def __call__(self,etype, evalue, etb) - - """ - - def __init__(self,IP,app_name,contact_name,contact_email, - bug_tracker,crash_report_fname, - show_crash_traceback=True): - """New crash handler. - - Inputs: - - - IP: a running IPython instance, which will be queried at crash time - for internal information. - - - app_name: a string containing the name of your application. - - - contact_name: a string with the name of the person to contact. - - - contact_email: a string with the email address of the contact. - - - bug_tracker: a string with the URL for your project's bug tracker. - - - crash_report_fname: a string with the filename for the crash report - to be saved in. These reports are left in the ipython user directory - as determined by the running IPython instance. - - Optional inputs: - - - show_crash_traceback(True): if false, don't print the crash - traceback on stderr, only generate the on-disk report - - - Non-argument instance attributes: - - These instances contain some non-argument attributes which allow for - further customization of the crash handler's behavior. Please see the - source for further details. - """ - - # apply args into instance - self.IP = IP # IPython instance - self.app_name = app_name - self.contact_name = contact_name - self.contact_email = contact_email - self.bug_tracker = bug_tracker - self.crash_report_fname = crash_report_fname - self.show_crash_traceback = show_crash_traceback - - # Hardcoded defaults, which can be overridden either by subclasses or - # at runtime for the instance. - - # Template for the user message. Subclasses which completely override - # this, or user apps, can modify it to suit their tastes. It gets - # expanded using itpl, so calls of the kind $self.foo are valid. - self.user_message_template = """ -Oops, $self.app_name crashed. We do our best to make it stable, but... - -A crash report was automatically generated with the following information: - - A verbatim copy of the crash traceback. - - A copy of your input history during this session. - - Data on your current $self.app_name configuration. - -It was left in the file named: -\t'$self.crash_report_fname' -If you can email this file to the developers, the information in it will help -them in understanding and correcting the problem. - -You can mail it to: $self.contact_name at $self.contact_email -with the subject '$self.app_name Crash Report'. - -If you want to do it now, the following command will work (under Unix): -mail -s '$self.app_name Crash Report' $self.contact_email < $self.crash_report_fname - -To ensure accurate tracking of this issue, please file a report about it at: -$self.bug_tracker -""" - - def __call__(self,etype, evalue, etb): - """Handle an exception, call for compatible with sys.excepthook""" - - # Report tracebacks shouldn't use color in general (safer for users) - color_scheme = 'NoColor' - - # Use this ONLY for developer debugging (keep commented out for release) - #color_scheme = 'Linux' # dbg - - try: - rptdir = self.IP.rc.ipythondir - except: - rptdir = os.getcwd() - if not os.path.isdir(rptdir): - rptdir = os.getcwd() - report_name = os.path.join(rptdir,self.crash_report_fname) - # write the report filename into the instance dict so it can get - # properly expanded out in the user message template - self.crash_report_fname = report_name - TBhandler = ultraTB.VerboseTB(color_scheme=color_scheme, - long_header=1) - traceback = TBhandler.text(etype,evalue,etb,context=31) - - # print traceback to screen - if self.show_crash_traceback: - print >> sys.stderr, traceback - - # and generate a complete report on disk - try: - report = open(report_name,'w') - except: - print >> sys.stderr, 'Could not create crash report on disk.' - return - - # Inform user on stderr of what happened - msg = itpl('\n'+'*'*70+'\n'+self.user_message_template) - print >> sys.stderr, msg - - # Construct report on disk - report.write(self.make_report(traceback)) - report.close() - raw_input("Press enter to exit:") - - def make_report(self,traceback): - """Return a string containing a crash report.""" - - sec_sep = '\n\n'+'*'*75+'\n\n' - - report = [] - rpt_add = report.append - - rpt_add('*'*75+'\n\n'+'IPython post-mortem report\n\n') - rpt_add('IPython version: %s \n\n' % Release.version) - rpt_add('BZR revision : %s \n\n' % Release.revision) - rpt_add('Platform info : os.name -> %s, sys.platform -> %s' % - (os.name,sys.platform) ) - rpt_add(sec_sep+'Current user configuration structure:\n\n') - rpt_add(pformat(self.IP.rc.dict())) - rpt_add(sec_sep+'Crash traceback:\n\n' + traceback) - try: - rpt_add(sec_sep+"History of session input:") - for line in self.IP.user_ns['_ih']: - rpt_add(line) - rpt_add('\n*** Last line of input (may not be in above history):\n') - rpt_add(self.IP._last_input_line+'\n') - except: - pass - - return ''.join(report) - -class IPythonCrashHandler(CrashHandler): - """sys.excepthook for IPython itself, leaves a detailed report on disk.""" - - def __init__(self,IP): - - # Set here which of the IPython authors should be listed as contact - AUTHOR_CONTACT = 'Ville' - - # Set argument defaults - app_name = 'IPython' - bug_tracker = 'https://bugs.launchpad.net/ipython/+filebug' - contact_name,contact_email = Release.authors[AUTHOR_CONTACT][:2] - crash_report_fname = 'IPython_crash_report.txt' - # Call parent constructor - CrashHandler.__init__(self,IP,app_name,contact_name,contact_email, - bug_tracker,crash_report_fname) - - def make_report(self,traceback): - """Return a string containing a crash report.""" - - sec_sep = '\n\n'+'*'*75+'\n\n' - - report = [] - rpt_add = report.append - - rpt_add('*'*75+'\n\n'+'IPython post-mortem report\n\n') - rpt_add('IPython version: %s \n\n' % Release.version) - rpt_add('BZR revision : %s \n\n' % Release.revision) - rpt_add('Platform info : os.name -> %s, sys.platform -> %s' % - (os.name,sys.platform) ) - rpt_add(sec_sep+'Current user configuration structure:\n\n') - rpt_add(pformat(self.IP.rc.dict())) - rpt_add(sec_sep+'Crash traceback:\n\n' + traceback) - try: - rpt_add(sec_sep+"History of session input:") - for line in self.IP.user_ns['_ih']: - rpt_add(line) - rpt_add('\n*** Last line of input (may not be in above history):\n') - rpt_add(self.IP._last_input_line+'\n') - except: - pass - - return ''.join(report) diff --git a/IPython/DPyGetOpt.py b/IPython/DPyGetOpt.py deleted file mode 100644 index f4b918e..0000000 --- a/IPython/DPyGetOpt.py +++ /dev/null @@ -1,690 +0,0 @@ -# -*- coding: utf-8 -*- -"""DPyGetOpt -- Demiurge Python GetOptions Module - -This module is modeled after perl's Getopt::Long module-- which -is, in turn, modeled after GNU's extended getopt() function. - -Upon instantiation, the option specification should be a sequence -(list) of option definitions. - -Options that take no arguments should simply contain the name of -the option. If a ! is post-pended, the option can be negated by -prepending 'no'; ie 'debug!' specifies that -debug and -nodebug -should be accepted. - -Mandatory arguments to options are specified using a postpended -'=' + a type specifier. '=s' specifies a mandatory string -argument, '=i' specifies a mandatory integer argument, and '=f' -specifies a mandatory real number. In all cases, the '=' can be -substituted with ':' to specify that the argument is optional. - -Dashes '-' in option names are allowed. - -If an option has the character '@' postpended (after the -argumentation specification), it can appear multiple times within -each argument list that is processed. The results will be stored -in a list. - -The option name can actually be a list of names separated by '|' -characters; ie-- 'foo|bar|baz=f@' specifies that all -foo, -bar, -and -baz options that appear on within the parsed argument list -must have a real number argument and that the accumulated list -of values will be available under the name 'foo' -""" - -#***************************************************************************** -# -# Copyright (c) 2001 Bill Bumgarner -# -# -# Published under the terms of the MIT license, hereby reproduced: -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. -# -#***************************************************************************** - -__author__ = 'Bill Bumgarner ' -__license__ = 'MIT' -__version__ = '1.2' - -# Modified to use re instead of regex and regsub modules. -# 2001/5/7, Jonathan Hogg - -import re -import string -import sys -import types - -class Error(Exception): - """Base class for exceptions in the DPyGetOpt module.""" - -class ArgumentError(Error): - """Exception indicating an error in the arguments passed to - DPyGetOpt.processArguments.""" - -class SpecificationError(Error): - """Exception indicating an error with an option specification.""" - -class TerminationError(Error): - """Exception indicating an error with an option processing terminator.""" - -specificationExpr = re.compile('(?P.)(?P.)(?P@?)') - -ArgRequired = 'Requires an Argument' -ArgOptional = 'Argument Optional' - -# The types modules is not used for these identifiers because there -# is no identifier for 'boolean' or 'generic' -StringArgType = 'String Argument Type' -IntegerArgType = 'Integer Argument Type' -RealArgType = 'Real Argument Type' -BooleanArgType = 'Boolean Argument Type' -GenericArgType = 'Generic Argument Type' - -# dictionary of conversion functions-- boolean and generic options -# do not accept arguments and do not need conversion functions; -# the identity function is used purely for convenience. -ConversionFunctions = { - StringArgType : lambda x: x, - IntegerArgType : string.atoi, - RealArgType : string.atof, - BooleanArgType : lambda x: x, - GenericArgType : lambda x: x, - } - -class DPyGetOpt: - - def __init__(self, spec = None, terminators = ['--']): - """ - Declare and intialize instance variables - - Yes, declaration is not necessary... but one of the things - I sorely miss from C/Obj-C is the concept of having an - interface definition that clearly declares all instance - variables and methods without providing any implementation - details. it is a useful reference! - - all instance variables are initialized to 0/Null/None of - the appropriate type-- not even the default value... - """ - -# sys.stderr.write(string.join(spec) + "\n") - - self.allowAbbreviations = 1 # boolean, 1 if abbreviations will - # be expanded - self.freeValues = [] # list, contains free values - self.ignoreCase = 0 # boolean, YES if ignoring case - self.needsParse = 0 # boolean, YES if need to reparse parameter spec - self.optionNames = {} # dict, all option names-- value is index of tuple - self.optionStartExpr = None # regexp defining the start of an option (ie; '-', '--') - self.optionTuples = [] # list o' tuples containing defn of options AND aliases - self.optionValues = {} # dict, option names (after alias expansion) -> option value(s) - self.orderMixed = 0 # boolean, YES if options can be mixed with args - self.posixCompliance = 0 # boolean, YES indicates posix like behaviour - self.spec = [] # list, raw specs (in case it must be reparsed) - self.terminators = terminators # list, strings that terminate argument processing - self.termValues = [] # list, values after terminator - self.terminator = None # full name of terminator that ended - # option processing - - # set up defaults - self.setPosixCompliance() - self.setIgnoreCase() - self.setAllowAbbreviations() - - # parse spec-- if present - if spec: - self.parseConfiguration(spec) - - def setPosixCompliance(self, aFlag = 0): - """ - Enables and disables posix compliance. - - When enabled, '+' can be used as an option prefix and free - values can be mixed with options. - """ - self.posixCompliance = aFlag - self.needsParse = 1 - - if self.posixCompliance: - self.optionStartExpr = re.compile('(--|-)(?P