######################################################################### # # # # # copyright 2002 Paul Henry Tremblay # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # # General Public License for more details. # # # # # ######################################################################### class OverrideTable: """ Parse a line of text to make the override table. Return a string (which will convert to XML) and the dictionary containing all the information about the lists. This dictionary is the result of the dictionary that is first passed to this module. This module modifies the dictionary, assigning lists numbers to each list. """ def __init__( self, list_of_lists, run_level=1, ): self.__list_of_lists = list_of_lists self.__initiate_values() self.__run_level = run_level def __initiate_values(self): self.__override_table_final = '' self.__state = 'default' self.__override_list = [] self.__state_dict = { 'default' : self.__default_func, 'override' : self.__override_func, 'unsure_ob' : self.__after_bracket_func, } self.__override_dict = { 'cw 3: msg = 'This override does not appear to have a list-id\n' raise self.__bug_handler(msg) current_table_id = override_dict.get('list-table-id') if current_table_id is None and self.__run_level > 3: msg = 'This override does not appear to have a list-table-id\n' raise self.__bug_handler(msg) counter = 0 for list in self.__list_of_lists: info_dict = list[0] old_table_id = info_dict.get('list-table-id') if old_table_id == current_table_id: self.__list_of_lists[counter][0]['list-id'].append(list_id) break counter += 1 def __parse_lines(self, line): """ Requires: line --ine to parse Returns: nothing Logic: Break the into tokens by splitting it on the newline. Call on the method according to the state. """ lines = line.split('\n') self.__ob_count = 0 self.__ob_group = 0 for line in lines: self.__token_info = line[:16] if self.__token_info == 'ob 3: msg = 'No matching token after open bracket\n' msg += 'token is "%s\n"' % (line) raise self.__bug_handler(msg) def __write_final_string(self): """ Requires: line -- line to parse Returns: nothing Logic: First write out the override-table tag. Iteratere through the dictionaries in the main override_list. For each dictionary, write an empty tag "override-list". Add the attributes and values of the tag from the dictionary. """ self.__override_table_final = 'mi%s' % (the_key, the_dict[the_key]) self.__override_table_final += '\n' self.__override_table_final += '\n' self.__override_table_final += \ 'mi