# Path: OpenTrader/deps/cmd2plus.py
# def remaining_args(oldArgs, newArgList):
#     '''
#     Preserves the spacing originally in the argument after
#     the removal of options.
# 
#     >>> remaining_args('-f bar   bar   cow', ['bar', 'cow'])
#     'bar   cow'
#     '''
#     pattern = '\s+'.join(re.escape(a) for a in newArgList) + '\s*$'
#     matchObj = re.search(pattern, oldArgs)
#     return oldArgs[matchObj.start():]
# 
# class ParsedString(str):
#     def full_parsed_statement(self):
#         new = ParsedString('%s %s' % (self.parsed.command, self.parsed.args))
#         new.parsed = self.parsed
#         new.parser = self.parser
#         return new
#     def with_args_replaced(self, newargs):
#         new = ParsedString(newargs)
#         new.parsed = self.parsed
#         new.parser = self.parser
#         new.parsed['args'] = newargs
#         new.parsed.statement['args'] = newargs
#         return new


import sys
    import optparse
    import pyparsing
from optparse import OptionParser, make_option
from OpenTrader.deps.cmd2plus import remaining_args, ParsedString
        optionParser._func = func

        def oUpdateOptionParser(instance):
            if func.__name__.startswith('do_'):
                sName = func.__name__[3:]
                if hasattr(instance, 'oConfig') and sName in instance.oConfig:
                    oConfigSection = instance.oConfig[sName]
                    # iterate over optionParser
                    for sKey, gVal in oConfigSection.iteritems():
                        sOption = '--' +sKey
                        if optionParser.has_option(sOption):
                            oOption = optionParser.get_option(sOption)
                            # FixMe: only if the default is optparse.NO_DEFAULT?
                            if oOption.default is optparse.NO_DEFAULT:
                                # FixMe: does this set the default?
                                oOption.default = gVal
                                # FixMe: how about this?
                                optionParser.defaults[oOption.dest] = oOption.default
            return optionParser

        def new_func(instance, arg):
            try:
                # makebe return a list and prepend it
                optionParser = oUpdateOptionParser(instance)
                opts, newArgList = optionParser.parse_args(arg.split())
                # Must find the remaining args in the original argument list, but
                # mustn't include the command itself
                #if hasattr(arg, 'parsed') and newArgList[0] == arg.parsed.command:
                #    newArgList = newArgList[1:]
                newArgs = remaining_args(arg, newArgList)

# Path: OpenTrader/deps/cmd2plus.py
# def remaining_args(oldArgs, newArgList):
#     '''
#     Preserves the spacing originally in the argument after
#     the removal of options.
# 
#     >>> remaining_args('-f bar   bar   cow', ['bar', 'cow'])
#     'bar   cow'
#     '''
#     pattern = '\s+'.join(re.escape(a) for a in newArgList) + '\s*$'
#     matchObj = re.search(pattern, oldArgs)
#     return oldArgs[matchObj.start():]
# 
# class ParsedString(str):
#     def full_parsed_statement(self):
#         new = ParsedString('%s %s' % (self.parsed.command, self.parsed.args))
#         new.parsed = self.parsed
#         new.parser = self.parser
#         return new
#     def with_args_replaced(self, newargs):
#         new = ParsedString(newargs)
#         new.parsed = self.parsed
#         new.parser = self.parser
#         new.parsed['args'] = newargs
#         new.parsed.statement['args'] = newargs
#         return new


# Path: OpenTrader/OTCmd2_utils.py
import sys
    import optparse
    import pyparsing
from optparse import OptionParser, make_option
from OpenTrader.deps.cmd2plus import remaining_args, ParsedString

        optionParser._func = func

        def oUpdateOptionParser(instance):
            if func.__name__.startswith('do_'):
                sName = func.__name__[3:]
                if hasattr(instance, 'oConfig') and sName in instance.oConfig:
                    oConfigSection = instance.oConfig[sName]
                    # iterate over optionParser
                    for sKey, gVal in oConfigSection.iteritems():
                        sOption = '--' +sKey
                        if optionParser.has_option(sOption):
                            oOption = optionParser.get_option(sOption)
                            # FixMe: only if the default is optparse.NO_DEFAULT?
                            if oOption.default is optparse.NO_DEFAULT:
                                # FixMe: does this set the default?
                                oOption.default = gVal
                                # FixMe: how about this?
                                optionParser.defaults[oOption.dest] = oOption.default
            return optionParser

        def new_func(instance, arg):
            try:
                # makebe return a list and prepend it
                optionParser = oUpdateOptionParser(instance)
                opts, newArgList = optionParser.parse_args(arg.split())
                # Must find the remaining args in the original argument list, but
                # mustn't include the command itself
                #if hasattr(arg, 'parsed') and newArgList[0] == arg.parsed.command:
                #    newArgList = newArgList[1:]
                newArgs = remaining_args(arg, newArgList)

                if isinstance(arg, ParsedString):