'Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.'

def cmdloop(self, intro=None):

    self.preloop()
    if (self.use_rawinput and self.completekey):
        try:
            import readline
            self.old_completer = readline.get_completer()
            readline.set_completer(self.complete)
            readline.parse_and_bind((self.completekey + ':    complete'))
            history = os.path.expanduser(self.history_file)
            if os.path.exists(history):
                readline.read_history_file(history)
        except ImportError:
            pass
    try:
        if (intro is not None):
            self.intro = intro
        if self.intro:
            self.stdout.write((str(self.intro) + '\n'))
        stop = None
        while (not stop):
            if self.cmdqueue:
                line = self.cmdqueue.pop(0)
            elif self.use_rawinput:
                try:
                    line = raw_input(self.prompt)
                except EOFError:
                    self.log('')
                    self.do_exit('')
                except KeyboardInterrupt:
                    self.log('')
                    line = ''
            else:
                self.stdout.write(self.prompt)
                self.stdout.flush()
                line = self.stdin.readline()
                if (not len(line)):
                    line = ''
                else:
                    line = line.rstrip('\r\n')
            line = self.precmd(line)
            stop = self.onecmd(line)
            stop = self.postcmd(stop, line)
        self.postloop()
    finally:
        if (self.use_rawinput and self.completekey):
            try:
                import readline
                readline.set_completer(self.old_completer)
                readline.write_history_file(history)
            except ImportError:
                pass
