예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
 def __init__(
     self,
     in_file,
     bug_handler,
     default_font,
     copy=None,
     run_level=1,
 ):
     """
     Required:
         'file'--file to parse
         'default_font' --document default font
     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.__default_font = default_font
     self.__copy = copy
     self.__run_level = run_level
     self.__write_to = better_mktemp()
예제 #4
0
 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
예제 #5
0
 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()
예제 #6
0
 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
예제 #7
0
 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
예제 #8
0
 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
예제 #9
0
 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' ,
     ]
예제 #10
0
 def __init__(self,
         in_file,
         copy=None,
         run_level=1,
         ):
     self.__file = in_file
     self.__copy = copy
     self.__run_level = run_level
     self.__write_to = better_mktemp()
예제 #11
0
 def __init__(
     self,
     in_file,
     copy=None,
     run_level=1,
 ):
     self.__file = in_file
     self.__copy = copy
     self.__run_level = run_level
     self.__write_to = better_mktemp()
예제 #12
0
 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' ,
     ]
예제 #13
0
파일: footnote.py 프로젝트: Farb/calibre
 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_footnote = 0
예제 #14
0
 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
예제 #15
0
 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 = []
예제 #16
0
 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
예제 #17
0
 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 = []
예제 #18
0
 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.__run_level = run_level
     self.__write_to = better_mktemp()
예제 #19
0
 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]
예제 #20
0
 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(self.__file) as read_obj:
         with open(self.__write_to, 'w') as self.__write_obj:
             with open(self.__footnote_holder, 'w') 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(self.__footnote_holder, 'r') as read_obj:
         with open(self.__write_to, 'a') 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)
예제 #21
0
파일: footnote.py 프로젝트: Farb/calibre
 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(self.__file) as read_obj:
         with open(self.__write_to, 'w') as self.__write_obj:
             with open(self.__footnote_holder, 'w') 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(self.__footnote_holder, 'r') as read_obj:
         with open(self.__write_to, 'a') 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)
예제 #22
0
 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
예제 #23
0
 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
예제 #24
0
 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
예제 #25
0
 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
예제 #26
0
파일: pict.py 프로젝트: JimmXinu/calibre
 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
예제 #27
0
 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
예제 #28
0
파일: footnote.py 프로젝트: Farb/calibre
 def join_footnotes(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_footnote:
         return
     self.__write_to2 = better_mktemp()
     self.__state = 'body'
     self.__get_footnotes()
     self.__join_from_temp()
     # self.__write_obj.close()
     # self.__read_from_foot_obj.close()
     copy_obj = copy.Copy(bug_handler=self.__bug_handler)
     if self.__copy:
         copy_obj.copy_file(self.__write_to2, "footnote_joined.data")
     copy_obj.rename(self.__write_to2, self.__file)
     os.remove(self.__write_to2)
     os.remove(self.__footnote_holder)
예제 #29
0
 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)