1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-07 05:23:34 +02:00

Removed polyglots unicode_type usage

This commit is contained in:
2020-04-20 19:25:28 +02:00
parent ef7e2b10be
commit 128705f258
130 changed files with 657 additions and 716 deletions

View File

@@ -25,7 +25,6 @@ from ebook_converter.ebooks.rtf2xml import headings_to_sections, \
body_styles, preamble_rest, group_styles, \
inline
from ebook_converter.ebooks.rtf2xml.old_rtf import OldRtf
from ebook_converter.polyglot.builtins import unicode_type
from . import open_for_read, open_for_write
@@ -249,7 +248,7 @@ class ParseRtf:
enc = encode_obj.get_codepage()
# TODO: to check if cp is a good idea or if I should use a dict to convert
enc = 'cp' + enc
msg = '%s\nException in token processing' % unicode_type(msg)
msg = '%s\nException in token processing' % str(msg)
if check_encoding_obj.check_encoding(self.__file, enc):
file_name = self.__file if isinstance(self.__file, bytes) \
else self.__file.encode('utf-8')

View File

@@ -1,7 +1,5 @@
import sys
from ebook_converter.polyglot.builtins import unicode_type
class CheckEncoding:
@@ -15,7 +13,7 @@ class CheckEncoding:
try:
char.decode(encoding)
except ValueError as msg:
sys.stderr.write('line: %s char: %s\n%s\n' % (line_num, char_position, unicode_type(msg)))
sys.stderr.write('line: %s char: %s\n%s\n' % (line_num, char_position, str(msg)))
def check_encoding(self, path, encoding='us-ascii', verbose=True):
line_num = 0

View File

@@ -14,7 +14,6 @@ import os
from ebook_converter.ebooks.rtf2xml import copy
from ebook_converter.ptempfile import better_mktemp
from ebook_converter.polyglot.builtins import unicode_type
from . import open_for_read, open_for_write
@@ -57,7 +56,7 @@ class Footnote:
if self.__first_line:
self.__first_line_func(line)
if self.__token_info == 'cw<ci<footnot-mk':
num = unicode_type(self.__footnote_count)
num = str(self.__footnote_count)
self.__write_to_foot_obj.write(line)
self.__write_to_foot_obj.write(
'tx<nu<__________<%s\n' % num
@@ -94,7 +93,7 @@ class Footnote:
self.__found_footnote(line)
self.__write_obj.write(line)
if self.__token_info == 'cw<ci<footnot-mk':
num = unicode_type(self.__footnote_count + 1)
num = str(self.__footnote_count + 1)
self.__write_obj.write(
'tx<nu<__________<%s\n' % num
)

View File

@@ -15,7 +15,6 @@ import sys, os, io
from ebook_converter.ebooks.rtf2xml import get_char_map, copy
from ebook_converter.ebooks.rtf2xml.char_set import char_set
from ebook_converter.ptempfile import better_mktemp
from ebook_converter.polyglot.builtins import unicode_type
from . import open_for_read, open_for_write
@@ -482,7 +481,7 @@ class Hex2Utf8:
the_string = ''
for letter in text:
hex_num = hex(ord(letter))
hex_num = unicode_type(hex_num)
hex_num = str(hex_num)
hex_num = hex_num.upper()
hex_num = hex_num[2:]
hex_num = '\'%s' % hex_num

View File

@@ -11,8 +11,6 @@
# #
#########################################################################
from ebook_converter.polyglot.builtins import unicode_type
class ListTable:
"""
@@ -234,7 +232,7 @@ class ListTable:
"""
num = line[18:]
num = int(num, 16)
level = unicode_type(round((num - 1)/2, 0))
level = str(round((num - 1)/2, 0))
level = level[:-2]
level = 'level%s-show-level' % level
self.__all_lists[-1][-1][0][level] = 'true'
@@ -291,11 +289,11 @@ class ListTable:
num = line[18:]
the_num = int(num, 16)
if not self.__found_level_text_length:
self.__all_lists[-1][-1][0]['list-text-length'] = unicode_type(the_num)
self.__all_lists[-1][-1][0]['list-text-length'] = str(the_num)
self.__found_level_text_length = 1
else:
the_num += 1
the_string = unicode_type(the_num)
the_string = str(the_num)
level_marker = 'level%s-suffix' % the_string
show_marker = 'show-level%s' % the_string
self.__level_text_position = level_marker
@@ -383,7 +381,7 @@ class ListTable:
for list in self.__all_lists:
id += 1
self.__list_table_final += 'mi<tg<open-att__<list-in-table'
# self.__list_table_final += '<list-id>%s' % (unicode_type(id))
# self.__list_table_final += '<list-id>%s' % (str(id))
the_dict = list[0]
the_keys = the_dict.keys()
for the_key in the_keys:
@@ -398,7 +396,7 @@ class ListTable:
for level in levels:
level_num += 1
self.__list_table_final += 'mi<tg<empty-att_<level-in-table'
self.__list_table_final += '<level>%s' % (unicode_type(level_num))
self.__list_table_final += '<level>%s' % (str(level_num))
the_dict2 = level[0]
the_keys2 = the_dict2.keys()
is_bullet = 0

View File

@@ -14,7 +14,6 @@ import sys, os, re
from ebook_converter.ebooks.rtf2xml import copy
from ebook_converter.ptempfile import better_mktemp
from ebook_converter.polyglot.builtins import unicode_type
from . import open_for_read, open_for_write
@@ -289,7 +288,7 @@ class MakeLists:
'mi<mk<list_start\n'
)
# bogus levels are sometimes written for empty paragraphs
if unicode_type(self.__level) not in self.__allow_levels:
if str(self.__level) not in self.__allow_levels:
lev_num = '0'
else:
lev_num = self.__level

View File

@@ -12,8 +12,6 @@
#########################################################################
import sys
from ebook_converter.polyglot.builtins import unicode_type
from . import open_for_read
@@ -138,7 +136,7 @@ class OldRtf:
if self.__run_level > 3:
sys.stderr.write(
'Old rtf construction %s (bracket %s, line %s)\n' % (
self.__inline_info, unicode_type(self.__ob_group), line_num)
self.__inline_info, str(self.__ob_group), line_num)
)
return True
self.__previous_token = line[6:16]

View File

@@ -14,7 +14,6 @@ import sys, os
from ebook_converter.ebooks.rtf2xml import copy, border_parse
from ebook_converter.ptempfile import better_mktemp
from ebook_converter.polyglot.builtins import unicode_type
from . import open_for_read, open_for_write
@@ -623,7 +622,7 @@ if another paragraph_def is found, the state changes to collect_tokens.
num = len(self.__style_num_strings)
new_style = 1
num = '%04d' % num
self.__att_val_dict['style-num'] = 's' + unicode_type(num)
self.__att_val_dict['style-num'] = 's' + str(num)
if new_style:
self.__write_body_styles()

View File

@@ -14,7 +14,6 @@ import sys, os
from ebook_converter.ebooks.rtf2xml import copy
from ebook_converter.ptempfile import better_mktemp
from ebook_converter.polyglot.builtins import unicode_type
from . import open_for_read, open_for_write
@@ -77,7 +76,7 @@ class Pict:
try:
os.mkdir(self.__dir_name)
except OSError as msg:
msg = "%sCouldn't make directory '%s':\n" % (unicode_type(msg), self.__dir_name)
msg = "%sCouldn't make directory '%s':\n" % (str(msg), self.__dir_name)
raise self.__bug_handler
else:
if self.__run_level > 1:

View File

@@ -14,7 +14,6 @@ import os, re
from ebook_converter.ebooks.rtf2xml import copy, check_brackets
from ebook_converter.ptempfile import better_mktemp
from ebook_converter.polyglot.builtins import unicode_type
from . import open_for_read, open_for_write
@@ -694,7 +693,7 @@ class ProcessTokens:
if num[-1] == ';':
num = num[:-1]
third_field = 'en'
num = unicode_type('%X' % int(num))
num = str('%X' % int(num))
if len(num) != 2:
num = "0" + num
return 'cw<%s<%s<%s<%s\n' % (pre, token, third_field, num)
@@ -731,7 +730,7 @@ class ProcessTokens:
return 0
num = '%0.2f' % round(numerator/denominator, 2)
return num
string_num = unicode_type(num)
string_num = str(num)
if string_num[-2:] == ".0":
string_num = string_num[:-2]
return string_num

View File

@@ -14,7 +14,6 @@ import sys, os
from ebook_converter.ebooks.rtf2xml import copy
from ebook_converter.ptempfile import better_mktemp
from ebook_converter.polyglot.builtins import unicode_type
from . import open_for_read, open_for_write
@@ -275,8 +274,8 @@ class Sections:
my_string += 'mi<tg<close_____<section\n'
else:
self.__found_first_sec = 1
my_string += 'mi<tg<open-att__<section<num>%s' % unicode_type(self.__section_num)
my_string += '<num-in-level>%s' % unicode_type(self.__section_num)
my_string += 'mi<tg<open-att__<section<num>%s' % str(self.__section_num)
my_string += '<num-in-level>%s' % str(self.__section_num)
my_string += '<type>rtf-native'
my_string += '<level>0'
keys = self.__section_values.keys()
@@ -358,7 +357,7 @@ class Sections:
'<num-in-level>%s'
'<type>rtf-native'
'<level>0\n'
% (unicode_type(self.__section_num), unicode_type(self.__section_num))
% (str(self.__section_num), str(self.__section_num))
)
self.__found_first_sec = 1
elif self.__token_info == 'tx<nu<__________':
@@ -369,7 +368,7 @@ class Sections:
'<num-in-level>%s'
'<type>rtf-native'
'<level>0\n'
% (unicode_type(self.__section_num), unicode_type(self.__section_num))
% (str(self.__section_num), str(self.__section_num))
)
self.__write_obj.write(
'cw<pf<par-def___<true\n'
@@ -462,7 +461,7 @@ class Sections:
self.__field_num = self.__field_num[1:]
self.__write_obj.write(
'mi<tg<close_____<section\n'
'mi<tg<open-att__<section<num>%s' % unicode_type(num)
'mi<tg<open-att__<section<num>%s' % str(num)
)
if self.__list_of_sec_values:
keys = self.__list_of_sec_values[0].keys()
@@ -472,7 +471,7 @@ class Sections:
self.__list_of_sec_values = self.__list_of_sec_values[1:]
self.__write_obj.write('<level>0')
self.__write_obj.write('<type>rtf-native')
self.__write_obj.write('<num-in-level>%s' % unicode_type(self.__section_num))
self.__write_obj.write('<num-in-level>%s' % str(self.__section_num))
self.__write_obj.write('\n')
# Look here

View File

@@ -14,7 +14,6 @@ import sys, os
from ebook_converter.ebooks.rtf2xml import copy, border_parse
from ebook_converter.ptempfile import better_mktemp
from ebook_converter.polyglot.builtins import unicode_type
from . import open_for_read, open_for_write
@@ -399,13 +398,13 @@ class Table:
left_position = float(left_position)
width = new_cell_position - self.__last_cell_position - left_position
# width = round(width, 2)
width = unicode_type('%.2f' % width)
width = str('%.2f' % width)
self.__last_cell_position = new_cell_position
widths_exists = self.__row_dict.get('widths')
if widths_exists:
self.__row_dict['widths'] += ', %s' % unicode_type(width)
self.__row_dict['widths'] += ', %s' % str(width)
else:
self.__row_dict['widths'] = unicode_type(width)
self.__row_dict['widths'] = str(width)
self.__cell_list[-1]['width'] = width
self.__cell_list.append({})
self.__cell_widths.append(width)