######################################################################### # # # # # 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. # # # # # ######################################################################### import sys, os from ebook_converter.ebooks.rtf2xml import copy from ebook_converter.ptempfile import better_mktemp from . import open_for_read, open_for_write class DeleteInfo: """Delete unecessary destination groups""" def __init__(self, in_file , bug_handler, copy=None, run_level=1, ): self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy self.__write_to = better_mktemp() self.__run_level = run_level self.__initiate_allow() self.__bracket_count= 0 self.__ob_count = 0 self.__cb_count = 0 self.__ob = 0 self.__write_cb = False self.__found_delete = False def __initiate_allow(self): """ Initiate a list of destination groups which should be printed out. """ self.__allowable = ('cw 3: msg = 'Flag problem\n' raise self.__bug_handler(msg) return True elif self.__token_info in self.__allowable : if self.__ob: self.__write_obj.write(self.__ob) self.__ob = 0 self.__state = 'default' else: pass return True elif self.__token_info == 'cw 5: msg = ('After an asterisk, and found neither an allowable or non-allowable token\n\ token is "%s"\n') % self.__token_info raise self.__bug_handler(msg) if not self.__ob: self.__write_cb = True self.__ob = 0 self.__state = 'delete' self.__cb_count = 0 return False def __found_list_func(self, line): """ print out control words in this group """ self.__state = 'list' def __list_func(self, line): """ Check to see if the group has ended. Return True for all control words. Return False otherwise. """ if self.__delete_count == self.__cb_count and \ self.__token_info == 'cb