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
|
import os, tempfile
|
||||||
|
|
||||||
from calibre.ebooks.rtf2xml import copy
|
from calibre.ebooks.rtf2xml import copy
|
||||||
|
from calibre.utils.cleantext import clean_ascii_chars
|
||||||
|
|
||||||
class ReplaceIllegals:
|
class ReplaceIllegals:
|
||||||
"""
|
"""
|
||||||
reaplace illegal lower ascii characters
|
reaplace illegal lower ascii characters
|
||||||
@ -30,21 +33,14 @@ class ReplaceIllegals:
|
|||||||
self.__copy = copy
|
self.__copy = copy
|
||||||
self.__run_level = run_level
|
self.__run_level = run_level
|
||||||
self.__write_to = tempfile.mktemp()
|
self.__write_to = tempfile.mktemp()
|
||||||
|
|
||||||
def replace_illegals(self):
|
def replace_illegals(self):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 14, 15, 16, 17, 18, 19]
|
with open(self.__file, 'r') as read_obj, \
|
||||||
read_obj = open(self.__file, 'r')
|
open(self.__write_to, 'w') as write_obj:
|
||||||
write_obj = open(self.__write_to, 'w')
|
for line in read_obj:
|
||||||
line_to_read = 1
|
write_obj.write(clean_ascii_chars(line))
|
||||||
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()
|
|
||||||
copy_obj = copy.Copy()
|
copy_obj = copy.Copy()
|
||||||
if self.__copy:
|
if self.__copy:
|
||||||
copy_obj.copy_file(self.__write_to, "replace_illegals.data")
|
copy_obj.copy_file(self.__write_to, "replace_illegals.data")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user