home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import sys
-
- class ParseOptions:
-
- def __init__(self, system_string, options_dict):
- self._ParseOptions__system_string = system_string[1:]
- long_list = self._ParseOptions__make_long_list_func(options_dict)
- short_list = self._ParseOptions__make_short_list_func(options_dict)
- self._ParseOptions__legal_options = long_list + short_list
- self._ParseOptions__short_long_dict = self._ParseOptions__make_short_long_dict_func(options_dict)
- self._ParseOptions__opt_with_args = self._ParseOptions__make_options_with_arg_list(options_dict)
- self._ParseOptions__options_okay = 1
-
-
- def __make_long_list_func(self, options_dict):
- legal_list = []
- keys = options_dict.keys()
- for key in keys:
- key = '--' + key
- legal_list.append(key)
-
- return legal_list
-
-
- def __make_short_list_func(self, options_dict):
- legal_list = []
- keys = options_dict.keys()
- for key in keys:
- values = options_dict[key]
-
- try:
- legal_list.append('-' + values[1])
- continue
- except IndexError:
- continue
-
-
-
- return legal_list
-
-
- def __make_short_long_dict_func(self, options_dict):
- short_long_dict = { }
- keys = options_dict.keys()
- for key in keys:
- values = options_dict[key]
-
- try:
- short = '-' + values[1]
- long = '--' + key
- short_long_dict[short] = long
- continue
- except IndexError:
- continue
-
-
-
- return short_long_dict
-
-
- def __make_options_with_arg_list(self, options_dict):
- opt_with_arg = []
- keys = options_dict.keys()
- for key in keys:
- values = options_dict[key]
-
- try:
- if values[0]:
- opt_with_arg.append('--' + key)
- continue
- except IndexError:
- continue
-
-
-
- return opt_with_arg
-
-
- def __sub_short_with_long(self):
- new_string = []
- sub_list = self._ParseOptions__short_long_dict.keys()
- for item in self._ParseOptions__system_string:
- if item in sub_list:
- item = self._ParseOptions__short_long_dict[item]
-
- new_string.append(item)
-
- return new_string
-
-
- def __pair_arg_with_option(self):
- opt_len = len(self._ParseOptions__system_string)
- new_system_string = []
- counter = 0
- slurp_value = 0
- for arg in self._ParseOptions__system_string:
- counter += 1
- if slurp_value:
- slurp_value = 0
- continue
-
- if arg[0] != '-':
- new_system_string.append(arg)
- continue
- if '=' in arg:
- new_system_string.append(arg)
- continue
- if arg in self._ParseOptions__opt_with_args:
- if counter + 1 > opt_len:
- sys.stderr.write('option "%s" must take an argument\n' % arg)
- new_system_string.append(arg)
- self._ParseOptions__options_okay = 0
- elif self._ParseOptions__system_string[counter][0] == '-':
- sys.stderr.write('option "%s" must take an argument\n' % arg)
- new_system_string.append(arg)
- self._ParseOptions__options_okay = 0
- else:
- new_system_string.append(arg + '=' + self._ParseOptions__system_string[counter])
- slurp_value = 1
- counter + 1 > opt_len
- new_system_string.append(arg)
-
- return new_system_string
-
-
- def __get_just_options(self):
- highest = 0
- counter = 0
- found_options = 0
- for item in self._ParseOptions__system_string:
- if item[0] == '-':
- highest = counter
- found_options = 1
-
- counter += 1
-
- if found_options:
- just_options = self._ParseOptions__system_string[:highest + 1]
- arguments = self._ParseOptions__system_string[highest + 1:]
- else:
- just_options = []
- arguments = self._ParseOptions__system_string
- if found_options:
- for item in just_options:
- if item[0] != '-':
- sys.stderr.write('%s is an argument in an option list\n' % item)
- self._ParseOptions__options_okay = 0
- continue
-
-
- return (just_options, arguments)
-
-
- def __is_legal_option_func(self):
- illegal_options = []
- for arg in self._ParseOptions__system_string:
- if '=' in arg:
- temp_list = arg.split('=')
- arg = temp_list[0]
-
- if arg not in self._ParseOptions__legal_options and arg[0] == '-':
- illegal_options.append(arg)
- continue
-
- if illegal_options:
- self._ParseOptions__options_okay = 0
- sys.stderr.write('The following options are not permitted:\n')
- for not_legal in illegal_options:
- sys.stderr.write('%s\n' % not_legal)
-
-
-
-
- def __make_options_dict(self, options):
- options_dict = { }
- for item in options:
- if '=' in item:
- (option, arg) = item.split('=')
- else:
- option = item
- arg = None
- if option[0] == '-':
- option = option[1:]
-
- if option[0] == '-':
- option = option[1:]
-
- options_dict[option] = arg
-
- return options_dict
-
-
- def parse_options(self):
- self._ParseOptions__system_string = self._ParseOptions__sub_short_with_long()
- self._ParseOptions__system_string = self._ParseOptions__pair_arg_with_option()
- (options, arguments) = self._ParseOptions__get_just_options()
- self._ParseOptions__is_legal_option_func()
- if self._ParseOptions__options_okay:
- options_dict = self._ParseOptions__make_options_dict(options)
- return (options_dict, arguments)
- return (0, 0)
-
-
- if __name__ == '__main__':
- this_dict = {
- 'indents': [
- 0,
- 'i'],
- 'output': [
- 1,
- 'o'],
- 'test3': [
- 1,
- 't'] }
- test_obj = ParseOptions(system_string = sys.argv, options_dict = this_dict)
- (options, the_args) = test_obj.parse_options()
- print options, the_args
-
-