Move check encoding

This commit is contained in:
Sengian 2011-01-06 00:01:24 +01:00
parent d0655c4d9a
commit 428fcdd141
2 changed files with 16 additions and 12 deletions

View File

@ -193,21 +193,13 @@ class ParseRtf:
copy_obj.set_dir(self.__debug_dir)
copy_obj.remove_files()
copy_obj.copy_file(self.__temp_file, "original_file")
#Check to see if the file is correct ascii
check_encoding_obj = check_encoding.CheckEncoding(
bug_handler = RtfInvalidCodeException,
)
if check_encoding_obj.check_encoding(self.__file):
file_name = self.__file if isinstance(self.__file, str) else self.__file.encode('utf-8')
msg = _('File %s does not appear to be ascii.\n') % file_name
raise InvalidRtfException, msg
# Function to check if bracket are well handled
if self.__debug_dir or self.__run_level > 2:
self.__check_brack_obj = check_brackets.CheckBrackets\
(file = self.__temp_file,
bug_handler = RtfInvalidCodeException,
)
# convert Macintosh and Windows line endings to Unix line endings
#convert Macintosh and Windows line endings to Unix line endings
#why do this if you don't wb after?
line_obj = line_endings.FixLineEndings(
in_file = self.__temp_file,
@ -238,7 +230,19 @@ class ParseRtf:
os.remove(self.__temp_file)
except OSError:
pass
#Check to see if the file is correctly encoded
check_encoding_obj = check_encoding.CheckEncoding(
bug_handler = RtfInvalidCodeException,
)
if check_encoding_obj.check_encoding(self.__file, 'cp1252') and \
check_encoding_obj.check_encoding(self.__file, 'cp437') and \
check_encoding_obj.check_encoding(self.__file, 'cp850') and \
check_encoding_obj.check_encoding(self.__file, 'mac_roman'):
file_name = self.__file if isinstance(self.__file, str) \
else self.__file.encode('utf-8')
msg = _('File %s does not appear to be correctly encoded.\n') % file_name
raise InvalidRtfException, msg
delete_info_obj = delete_info.DeleteInfo(
in_file = self.__temp_file,
copy = self.__copy,

View File

@ -74,9 +74,9 @@ class DefaultEncoding:
self.__datafetched = True
if self.__platform == 'Macintosh':
code_page = self.__code_page
else
else:
code_page = 'ansicpg' + self.__code_page
return platform, code_page, self.__default_num
return self.__platform, code_page, self.__default_num
def get_codepage(self):
if not self.__datafetched: