mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
use calibre function to clean lower ascii char in rtf2xml
This commit is contained in:
parent
51751b197e
commit
bc433b2650
@ -16,7 +16,10 @@
|
||||
# #
|
||||
#########################################################################
|
||||
import os, tempfile
|
||||
|
||||
from calibre.ebooks.rtf2xml import copy
|
||||
from calibre.utils.cleantext import clean_ascii_chars
|
||||
|
||||
class ReplaceIllegals:
|
||||
"""
|
||||
reaplace illegal lower ascii characters
|
||||
@ -30,21 +33,14 @@ class ReplaceIllegals:
|
||||
self.__copy = copy
|
||||
self.__run_level = run_level
|
||||
self.__write_to = tempfile.mktemp()
|
||||
|
||||
def replace_illegals(self):
|
||||
"""
|
||||
"""
|
||||
nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 14, 15, 16, 17, 18, 19]
|
||||
read_obj = open(self.__file, 'r')
|
||||
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
|
||||
for num in nums:
|
||||
line = line.replace(chr(num), '')
|
||||
write_obj.write(line)
|
||||
read_obj.close()
|
||||
write_obj.close()
|
||||
with open(self.__file, 'r') as read_obj, \
|
||||
open(self.__write_to, 'w') as write_obj:
|
||||
for line in read_obj:
|
||||
write_obj.write(clean_ascii_chars(line))
|
||||
copy_obj = copy.Copy()
|
||||
if self.__copy:
|
||||
copy_obj.copy_file(self.__write_to, "replace_illegals.data")
|
||||
|
Loading…
x
Reference in New Issue
Block a user