diff --git a/IPython/DPyGetOpt.py b/IPython/DPyGetOpt.py index 0dcc7ea..d23f1da 100644 --- a/IPython/DPyGetOpt.py +++ b/IPython/DPyGetOpt.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """DPyGetOpt -- Demiurge Python GetOptions Module - $Id: DPyGetOpt.py 958 2005-12-27 23:17:51Z fperez $ + $Id: DPyGetOpt.py 1980 2006-12-12 21:48:46Z vivainio $ This module is modeled after perl's Getopt::Long module-- which is, in turn, modeled after GNU's extended getopt() function. @@ -33,7 +33,7 @@ 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' -$Id: DPyGetOpt.py 958 2005-12-27 23:17:51Z fperez $""" +$Id: DPyGetOpt.py 1980 2006-12-12 21:48:46Z vivainio $""" #***************************************************************************** # @@ -80,592 +80,592 @@ term_error = 'DPyGetOpt Termination Error' specificationExpr = re.compile('(?P.)(?P.)(?P@?)') -ArgRequired = 'Requires an Argument' -ArgOptional = 'Argument Optional' +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' +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, - } + 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