######################################################################### # # # # # 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, check_brackets from ebook_converter.ptempfile import better_mktemp from . import open_for_read, open_for_write class AddBrackets: """ Add brackets for old RTF. Logic: When control words without their own brackets are encountered and in the list of allowed words, this will add brackets to facilitate the treatment of the file """ def __init__(self, in_file, bug_handler, copy=None, run_level=1, ): """ Required: 'file'--file to parse Optional: 'copy'-- whether to make a copy of result for debugging 'temp_dir' --where to output temporary results (default is directory from which the script is run.) Returns: nothing """ self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy self.__write_to = better_mktemp() self.__run_level = run_level self.__state_dict = { 'before_body' : self.__before_body_func, 'in_body' : self.__in_body_func, 'after_control_word' : self.__after_control_word_func, 'in_ignore' : self.__ignore_func, } self.__accept = [ 'cw 0: sys.stderr.write( 'Sorry, but this files has a mix of old and new RTF.\n' 'Some characteristics cannot be converted.\n') os.remove(self.__write_to)