def __init__( self, in_file, bug_handler, table_data, copy=None, run_level=1, ): """ Required: 'file'--file to parse 'table_data' -- a dictionary for each table. 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.__table_data = table_data self.__run_level = run_level self.__write_to = better_mktemp()
def __init__( self, in_file, bug_handler, dtd_path, no_dtd, encoding, indent=None, copy=None, run_level=1, ): """ Required: 'file' 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.__dtd_path = dtd_path self.__no_dtd = no_dtd self.__encoding = 'cp' + encoding # if encoding == 'mac_roman': # self.__encoding = 'mac_roman' self.__indent = indent self.__run_level = run_level self.__write_to = better_mktemp() self.__convert_utf = False self.__bad_encoding = False
def __init__(self, in_file, bug_handler, headings_to_sections, list_of_lists, copy=None, run_level=1, no_headings_as_list=1, write_list_info=0, ): """ Required: 'file' 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.__run_level = run_level self.__no_headings_as_list = no_headings_as_list self.__headings_to_sections = headings_to_sections self.__copy = copy self.__write_to = better_mktemp() self.__list_of_lists = list_of_lists self.__write_list_info = write_list_info
def __init__( self, in_file, bug_handler, default_font_num, copy=None, run_level=1, ): """ Required: 'file'--file to parse 'default_font_num'--the default font number 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.__default_font_num = default_font_num self.__write_to = better_mktemp() self.__run_level = run_level
def __init__( self, in_file, area_to_convert, char_file, default_char_map, bug_handler, invalid_rtf_handler, copy=None, temp_dir=None, symbol=None, wingdings=None, caps=None, convert_caps=None, dingbats=None, run_level=1, ): """ Required: 'file' 'area_to_convert'--the area of file to convert 'char_file'--the file containing the character mappings 'default_char_map'--name of default character map 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.) 'symbol'--whether to load the symbol character map 'winddings'--whether to load the wingdings character map 'caps'--whether to load the caps characer map 'convert_to_caps'--wether to convert caps to utf-8 Returns: nothing """ self.__file = in_file self.__copy = copy if area_to_convert not in ('preamble', 'body'): msg = ('Developer error! Wrong flag.\n' 'in module "hex_2_utf8.py\n' '"area_to_convert" must be "body" or "preamble"\n') raise self.__bug_handler(msg) self.__char_file = char_file self.__area_to_convert = area_to_convert self.__default_char_map = default_char_map self.__symbol = symbol self.__wingdings = wingdings self.__dingbats = dingbats self.__caps = caps self.__convert_caps = 0 self.__convert_symbol = 0 self.__convert_wingdings = 0 self.__convert_zapf = 0 self.__run_level = run_level self.__write_to = better_mktemp() self.__bug_handler = bug_handler self.__invalid_rtf_handler = invalid_rtf_handler
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<ci<bold______' , 'cw<ci<annotation' , 'cw<ci<blue______' , # 'cw<ci<bold______' , 'cw<ci<caps______' , 'cw<ci<char-style' , 'cw<ci<dbl-strike' , 'cw<ci<emboss____' , 'cw<ci<engrave___' , 'cw<ci<font-color' , 'cw<ci<font-down_' , 'cw<ci<font-size_' , 'cw<ci<font-style' , 'cw<ci<font-up___' , 'cw<ci<footnot-mk' , 'cw<ci<green_____' , 'cw<ci<hidden____' , 'cw<ci<italics___' , 'cw<ci<outline___' , 'cw<ci<red_______' , 'cw<ci<shadow____' , 'cw<ci<small-caps' , 'cw<ci<strike-thr' , 'cw<ci<subscript_' , 'cw<ci<superscrip' , 'cw<ci<underlined' , # 'cw<ul<underlined' , ]
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.__found_a_header = False
def __init__(self, bug_handler, in_file=None, copy=None, run_level=1, replace_illegals=1, ): self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy self.__run_level = run_level self.__write_to = better_mktemp() self.__replace_illegals = replace_illegals
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.__state = 'default' self.__bord_pos = 'default' self.__bord_att = []
def __init__( self, in_file, bug_handler, copy=None, run_level=1, # out_file = None, ): self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy self.__write_to = better_mktemp() # self.__write_to = out_file self.__compile_expressions() # variables self.__uc_char = 0 self.__uc_bin = False self.__uc_value = [1]
def separate_footnotes(self): """ Separate all the footnotes in an RTF file and put them at the bottom, where they are easier to process. Each time a footnote is found, print all of its contents to a temporary file. Close both the main and temporary file. Print the footnotes from the temporary file to the bottom of the main file. """ self.__initiate_sep_values() self.__footnote_holder = better_mktemp() with open_for_read(self.__file) as read_obj: with open_for_write(self.__write_to) as self.__write_obj: with open_for_write( self.__footnote_holder) as self.__write_to_foot_obj: for line in read_obj: self.__token_info = line[:16] # keep track of opening and closing brackets if self.__token_info == 'ob<nu<open-brack': self.__ob_count = line[-5:-1] if self.__token_info == 'cb<nu<clos-brack': self.__cb_count = line[-5:-1] # In the middle of footnote text if self.__in_footnote: self.__in_footnote_func(line) # not in the middle of footnote text else: self.__default_sep(line) with open_for_read(self.__footnote_holder) as read_obj: with open_for_write(self.__write_to, append=True) as write_obj: write_obj.write('mi<mk<sect-close\n' 'mi<mk<body-close\n' 'mi<tg<close_____<section\n' 'mi<tg<close_____<body\n' 'mi<tg<close_____<doc\n' 'mi<mk<footnt-beg\n') for line in read_obj: write_obj.write(line) write_obj.write('mi<mk<footnt-end\n') os.remove(self.__footnote_holder) copy_obj = copy.Copy(bug_handler=self.__bug_handler) if self.__copy: copy_obj.copy_file(self.__write_to, "footnote_separate.data") copy_obj.rename(self.__write_to, self.__file) os.remove(self.__write_to)
def __init__( self, in_file, exception_handler, bug_handler, copy=None, run_level=1, ): self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy self.__run_level = run_level self.__write_to = better_mktemp() self.initiate_token_dict() # self.initiate_token_actions() self.compile_expressions() self.__bracket_count = 0 self.__exception_handler = exception_handler self.__bug_handler = bug_handler
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 __init__(self, in_file, bug_handler, copy=None, no_namespace=None, run_level=1, ): """ Required: 'file' 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.__no_namespace = no_namespace self.__write_to = better_mktemp() self.__run_level = run_level
def __init__( self, in_file, bug_handler, out_file, copy=None, orig_file=None, run_level=1, ): self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy self.__run_level = run_level self.__write_to = better_mktemp() self.__bracket_count = 0 self.__ob_count = 0 self.__cb_count = 0 self.__pict_count = 0 self.__in_pict = False self.__already_found_pict = False self.__orig_file = orig_file self.__initiate_pict_dict() self.__out_file = out_file
def join_headers(self): """ Join the footnotes from the bottom of the file and put them in their former places. First, remove the footnotes from the bottom of the input file, outputting them to a temporary file. This creates two new files, one without footnotes, and one of just footnotes. Open both these files to read. When a marker is found in the main file, find the corresponding marker in the footnote file. Output the mix of body and footnotes to a third file. """ if not self.__found_a_header: return self.__write_to2 = better_mktemp() self.__state = 'body' self.__get_headers() self.__join_from_temp() self.__write_obj.close() self.__read_from_head_obj.close() copy_obj = copy.Copy(bug_handler=self.__bug_handler) if self.__copy: copy_obj.copy_file(self.__write_to, "header_join.data") copy_obj.rename(self.__write_to, self.__file) os.remove(self.__write_to) os.remove(self.__header_holder)