'Parse the command line and fill in self.values and self.files.
After having parsed the options, the remaining command line
arguments are interpreted as files and passed to .handle_files()
for processing.
As final step the option handlers are called in the order
of the options given on the command line.'

def parse(self):

    self.values = values = {}
    for o in self.options:
        if o.has_default:
            values[(o.prefix + o.name)] = o.default
        else:
            values[(o.prefix + o.name)] = 0
    (flags, lflags) = _getopt_flags(self.options)
    try:
        (optlist, files) = getopt.getopt(self.arguments, flags, lflags)
        if self.globbing:
            l = []
            for f in files:
                gf = glob.glob(f)
                if (not gf):
                    l.append(f)
                else:
                    l[len(l):] = gf
            files = l
        self.optionlist = optlist
        self.files = (files + self.files)
    except getopt.error as why:
        self.help(why)
        sys.exit(1)
    rc = self.handle_files(self.files)
    if (rc is not None):
        sys.exit(rc)
    for (optionname, value) in optlist:
        try:
            value = int(value)
        except ValueError:
            pass
        handlername = ('handle' + optionname.replace('-', '_'))
        try:
            handler = getattr(self, handlername)
        except AttributeError:
            if (value == ''):
                if (optionname in values):
                    values[optionname] = (values[optionname] + 1)
                else:
                    values[optionname] = 1
            else:
                values[optionname] = value
        else:
            rc = handler(value)
            if (rc is not None):
                raise SystemExit(rc)
    rc = self.check_files(self.files)
    if (rc is not None):
        sys.exit(rc)
