from __future__ import absolute_import, division, print_function, unicode_literals ######################################################################### # # # # # 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. # # # # # ######################################################################### from ebook_converter.polyglot.builtins import unicode_type class ListTable: """ Parse the list table line. Make a string. Form a dictionary. Return the string and the dictionary. """ def __init__( self, bug_handler, run_level=1, ): self.__bug_handler = bug_handler self.__initiate_values() self.__run_level = run_level def __initiate_values(self): self.__list_table_final = '' self.__state = 'default' self.__final_dict = {} self.__list_dict = {} self.__all_lists = [] self.__level_text_string = '' self.__level_text_list = [] self.__found_level_text_length = 0 self.__level_text_position = None self.__prefix_string = None self.__level_numbers_string = '' self.__state_dict = { 'default' : self.__default_func, 'level' : self.__level_func, 'list' : self.__list_func, 'unsure_ob' : self.__after_bracket_func, 'level_number' : self.__level_number_func, 'level_text' : self.__level_text_func, 'list_name' : self.__list_name_func, } self.__main_list_dict = { 'cw a list. The first item is a dictionary. The second item is a list containing a dictionary: [{list-id:[]}, [{}]] self.__all_lists[-1][0] => a dictionary of the list attributes self.__all_lists[-1][-1] => a list with just a dictionary self.__all_lists[-1][-1][0] => the dictionary of level attributes """ self.__state = 'level' self.__level_ob_count = self.__ob_count self.__all_lists[-1].append([]) the_dict = {} self.__all_lists[-1][-1].append(the_dict) self.__level_dict def __level_func(self, line): """ Requires: line -- line to parse Returns: nothing Logic: Look for the end of the this group. Change states if an open bracket is found. Add attributes to all_dicts if an appropriate token is found. """ if self.__token_info == 'cb 3: msg = 'No matching token after open bracket\n' msg += 'token is "%s\n"' % (line) raise self.__bug_handler def __add_to_final_line(self): """ Method no longer used. """ self.__list_table_final = 'mi value pair. Remove the first item (the dictionary) form this list. Now iterate through what is left in the list. Each list will conatin one item, a dictionary. Get this dictionary and print out key => value pair. """ not_allow = ['list-id',] id = 0 self.__list_table_final = 'mi