From 51751b197e430e902c546e85121082e111041a7b Mon Sep 17 00:00:00 2001 From: Sengian Date: Tue, 11 Jan 2011 00:00:20 +0100 Subject: [PATCH] clean rtf2xml inline --- src/calibre/ebooks/rtf2xml/inline.py | 78 +++++++++++++++------------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/src/calibre/ebooks/rtf2xml/inline.py b/src/calibre/ebooks/rtf2xml/inline.py index 55e6ed1dbb..83c383fa1f 100755 --- a/src/calibre/ebooks/rtf2xml/inline.py +++ b/src/calibre/ebooks/rtf2xml/inline.py @@ -1,5 +1,7 @@ import sys, os, tempfile + from calibre.ebooks.rtf2xml import copy + """ States. 1. default @@ -36,6 +38,7 @@ class Inline: self.__copy = copy self.__run_level = run_level self.__write_to = tempfile.mktemp() + def __initiate_values(self): """ Initiate all values. @@ -81,12 +84,12 @@ class Inline: self.__in_para = 0 # not in paragraph self.__char_dict = { # character info => ci - 'annotation' : 'annotation', + 'annotation' : 'annotation', 'blue______' : 'blue', 'bold______' : 'bold', - 'caps______' : 'caps', - 'char-style' : 'character-style', - 'dbl-strike' : 'double-strike-through', + 'caps______' : 'caps', + 'char-style' : 'character-style', + 'dbl-strike' : 'double-strike-through', 'emboss____' : 'emboss', 'engrave___' : 'engrave', 'font-color' : 'font-color', @@ -94,7 +97,7 @@ class Inline: 'font-size_' : 'font-size', 'font-style' : 'font-style', 'font-up___' : 'superscript', - 'footnot-mk' : 'footnote-marker', + 'footnot-mk' : 'footnote-marker', 'green_____' : 'green', 'hidden____' : 'hidden', 'italics___' : 'italics', @@ -105,9 +108,10 @@ class Inline: 'strike-thr' : 'strike-through', 'subscript_' : 'subscript', 'superscrip' : 'superscript', - 'underlined' : 'underlined', + 'underlined' : 'underlined', } self.__caps_list = ['false'] + def __set_list_func(self, line): """ Requires: @@ -126,6 +130,7 @@ class Inline: self.__place = 'in_list' self.__inline_list = self.__list_inline_list self.__groups_in_waiting = self.__groups_in_waiting_list + def __default_func(self, line): """ Requires: @@ -138,8 +143,8 @@ class Inline: action = self.__default_dict.get(self.__token_info) if action: action(line) - if self.__token_info != 'cw 3: - msg = 'self.__inline_list is %s\n' % self.__inline_list + msg = _('self.__inline_list is %s\n') % self.__inline_list raise self.__bug_handler, msg self.__write_obj.write('error\n') self.__groups_in_waiting[0] = 0 @@ -308,6 +317,7 @@ class Inline: self.__write_obj.write('<%s>%s' % (the_key, the_dict[the_key])) self.__write_obj.write('\n') self.__groups_in_waiting[0] = 0 + def __end_para_func(self, line): """ Requires: @@ -336,6 +346,7 @@ class Inline: self.__write_obj.write('mi%s' % (the_key, the_dict[the_key])) self.__write_obj.write('\n') self.__groups_in_waiting[0] = 0 + def __found_field_func(self, line): """ Just a default function to make sure I don't prematurely exit default state """ pass + def form_tags(self): """ Requires: @@ -380,32 +393,27 @@ class Inline: the state. """ self.__initiate_values() - read_obj = open(self.__file, 'r') - self.__write_obj = open(self.__write_to, 'w') - line_to_read = 1 - while line_to_read: - line_to_read = read_obj.readline() - line = line_to_read - token = line[0:-1] - self.__token_info = '' - if token == 'tx