mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
ac07ff853e
commit
24cb5514f0
@ -16,7 +16,7 @@ class CheckEncoding:
|
||||
sys.stderr.write(_('line: %s char: %s\n') % (line_num, char_position))
|
||||
sys.stderr.write(str(msg) + '\n')
|
||||
|
||||
def check_encoding(self, path, encoding='us-ascii'):
|
||||
def check_encoding(self, path, encoding='us-ascii', verbose = True):
|
||||
line_num = 0
|
||||
with open(path, 'r') as read_obj:
|
||||
for line in read_obj:
|
||||
@ -24,10 +24,11 @@ class CheckEncoding:
|
||||
try:
|
||||
line.decode(encoding)
|
||||
except UnicodeError:
|
||||
if len(line) < 1000:
|
||||
self.__get_position_error(line, encoding, line_num)
|
||||
else:
|
||||
sys.stderr.write(_('line: %d has bad encoding\n') % line_num)
|
||||
if verbose:
|
||||
if len(line) < 1000:
|
||||
self.__get_position_error(line, encoding, line_num)
|
||||
else:
|
||||
sys.stderr.write(_('line: %d has bad encoding\n') % line_num)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -210,7 +210,7 @@ class ConvertToTags:
|
||||
check_encoding_obj = check_encoding.CheckEncoding(
|
||||
bug_handler = self.__bug_handler,
|
||||
)
|
||||
if not check_encoding_obj.check_encoding(self.__file):
|
||||
if not check_encoding_obj.check_encoding(self.__file, verbose = False):
|
||||
self.__write_obj.write('<?xml version="1.0" encoding="US-ASCII" ?>')
|
||||
elif not check_encoding_obj.check_encoding(self.__file, self.__encoding):
|
||||
self.__write_obj.write('<?xml version="1.0" encoding="%s" ?>' % self.__encoding)
|
||||
|
Loading…
x
Reference in New Issue
Block a user