Modify delete_info in rtf2xml

This commit is contained in:
Sengian 2011-01-11 18:39:55 +01:00
parent 576cac2b98
commit 9ed1e94190
2 changed files with 23 additions and 28 deletions

View File

@ -133,8 +133,6 @@ class RTFInput(InputFormatPlugin):
) )
parser.parse_rtf() parser.parse_rtf()
ans = open('dataxml.xml').read() ans = open('dataxml.xml').read()
if debug_dir is None:
os.remove('dataxml.xml')
return ans return ans
def extract_images(self, picts): def extract_images(self, picts):

View File

@ -34,14 +34,14 @@ class DeleteInfo:
self.__bracket_count= 0 self.__bracket_count= 0
self.__ob_count = 0 self.__ob_count = 0
self.__cb_count = 0 self.__cb_count = 0
self.__after_asterisk = False # self.__after_asterisk = False
self.__delete = 0 # self.__delete = 0
self.__initiate_allow() self.__initiate_allow()
self.__ob = 0 self.__ob = 0
self.__write_cb = 0 self.__write_cb = False
self.__run_level = run_level self.__run_level = run_level
self.__found_delete = False self.__found_delete = False
self.__list = False # self.__list = False
def __initiate_allow(self): def __initiate_allow(self):
""" """
@ -69,7 +69,7 @@ class DeleteInfo:
self.__state_dict = { self.__state_dict = {
'default' : self.__default_func, 'default' : self.__default_func,
'after_asterisk' : self.__asterisk_func, 'after_asterisk' : self.__asterisk_func,
'delete' : self.__delete_func, 'delete' : self.__delete_func,
'list' : self.__list_func, 'list' : self.__list_func,
} }
@ -99,7 +99,7 @@ class DeleteInfo:
if self.__delete_count == self.__cb_count: if self.__delete_count == self.__cb_count:
self.__state = 'default' self.__state = 'default'
if self.__write_cb: if self.__write_cb:
self.__write_cb = 0 self.__write_cb = True
return True return True
return False return False
@ -116,7 +116,7 @@ class DeleteInfo:
""" """
# Test for {\*}, in which case don't enter # Test for {\*}, in which case don't enter
# delete state # delete state
self.__after_asterisk = False # only enter this function once # self.__after_asterisk = False # only enter this function once
self.__found_delete = True self.__found_delete = True
if self.__token_info == 'cb<nu<clos-brack': if self.__token_info == 'cb<nu<clos-brack':
if self.__delete_count == self.__cb_count: if self.__delete_count == self.__cb_count:
@ -128,7 +128,7 @@ class DeleteInfo:
# not sure what happens here! # not sure what happens here!
# believe I have a '{\*} # believe I have a '{\*}
if self.__run_level > 3: if self.__run_level > 3:
msg = 'flag problem\n' msg = _('flag problem\n')
raise self.__bug_handler, msg raise self.__bug_handler, msg
return True return True
elif self.__token_info in self.__allowable : elif self.__token_info in self.__allowable :
@ -144,18 +144,18 @@ class DeleteInfo:
self.__found_list_func(line) self.__found_list_func(line)
elif self.__token_info in self.__not_allowable: elif self.__token_info in self.__not_allowable:
if not self.__ob: if not self.__ob:
self.__write_cb = 1 self.__write_cb = False
self.__ob = 0 self.__ob = 0
self.__state = 'delete' self.__state = 'delete'
self.__cb_count = 0 self.__cb_count = 0
return False return False
else: else:
if self.__run_level > 5: if self.__run_level > 5:
msg = _('After an asterisk, and found neither an allowable or non-allowble token\n\ msg = _('After an asterisk, and found neither an allowable or non-allowable token\n\
token is "%s"\n') % self.__token_info token is "%s"\n') % self.__token_info
raise self.__bug_handler raise self.__bug_handler, msg
if not self.__ob: if not self.__ob:
self.__write_cb = 1 self.__write_cb = True
self.__ob = 0 self.__ob = 0
self.__state = 'delete' self.__state = 'delete'
self.__cb_count = 0 self.__cb_count = 0
@ -177,7 +177,7 @@ class DeleteInfo:
'cb<nu<clos-brack': 'cb<nu<clos-brack':
self.__state = 'default' self.__state = 'default'
if self.__write_cb: if self.__write_cb:
self.__write_cb = 0 self.__write_cb = False
return True return True
return False return False
elif line[0:2] == 'cw': elif line[0:2] == 'cw':
@ -188,8 +188,8 @@ class DeleteInfo:
def delete_info(self): def delete_info(self):
"""Main method for handling other methods. Read one line in at """Main method for handling other methods. Read one line in at
a time, and determine wheter to print the line based on the state.""" a time, and determine wheter to print the line based on the state."""
self.__write_obj = open(self.__write_to, 'w') with open(self.__file, 'r') as read_obj, \
with open(self.__file, 'r') as read_obj: open(self.__write_to, 'w') as self.__write_obj:
for line in read_obj: for line in read_obj:
#ob<nu<open-brack<0001 #ob<nu<open-brack<0001
to_print = True to_print = True
@ -203,19 +203,16 @@ class DeleteInfo:
sys.stderr.write(_('No action in dictionary state is "%s" \n') sys.stderr.write(_('No action in dictionary state is "%s" \n')
% self.__state) % self.__state)
to_print = action(line) to_print = action(line)
""" # if self.__after_asterisk:
if self.__after_asterisk: # to_print = self.__asterisk_func(line)
to_print = self.__asterisk_func(line) # elif self.__list:
elif self.__list: # self.__in_list_func(line)
self.__in_list_func(line) # elif self.__delete:
elif self.__delete: # to_print = self.__delete_func(line)
to_print = self.__delete_func(line) # else:
else: # to_print = self.__default_func(line)
to_print = self.__default_func(line)
"""
if to_print: if to_print:
self.__write_obj.write(line) self.__write_obj.write(line)
self.__write_obj.close()
copy_obj = copy.Copy(bug_handler = self.__bug_handler) copy_obj = copy.Copy(bug_handler = self.__bug_handler)
if self.__copy: if self.__copy:
copy_obj.copy_file(self.__write_to, "delete_info.data") copy_obj.copy_file(self.__write_to, "delete_info.data")