mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
py3: Disambiguate str()
This commit is contained in:
parent
d4c95b0df6
commit
6bd02c1aae
@ -10,7 +10,7 @@ from collections import namedtuple
|
||||
|
||||
from calibre.ebooks.docx.writer.utils import convert_color
|
||||
from calibre.ebooks.docx.writer.styles import read_css_block_borders as rcbb, border_edges
|
||||
from polyglot.builtins import iteritems, range
|
||||
from polyglot.builtins import iteritems, range, unicode_type
|
||||
|
||||
|
||||
class Dummy(object):
|
||||
@ -116,7 +116,7 @@ class Cell(object):
|
||||
def serialize(self, parent, makeelement):
|
||||
tc = makeelement(parent, 'w:tc')
|
||||
tcPr = makeelement(tc, 'w:tcPr')
|
||||
makeelement(tcPr, 'w:tcW', w_type=self.width[0], w_w=str(self.width[1]))
|
||||
makeelement(tcPr, 'w:tcW', w_type=self.width[0], w_w=unicode_type(self.width[1]))
|
||||
# For some reason, Word 2007 refuses to honor <w:shd> at the table or row
|
||||
# level, despite what the specs say, so we inherit and apply at the
|
||||
# cell level
|
||||
@ -127,7 +127,7 @@ class Cell(object):
|
||||
b = makeelement(tcPr, 'w:tcBorders', append=False)
|
||||
for edge, border in iteritems(self.borders):
|
||||
if border is not None and border.width > 0 and border.style != 'none':
|
||||
makeelement(b, 'w:' + edge, w_val=border.style, w_sz=str(border.width), w_color=border.color)
|
||||
makeelement(b, 'w:' + edge, w_val=border.style, w_sz=unicode_type(border.width), w_color=border.color)
|
||||
if len(b) > 0:
|
||||
tcPr.append(b)
|
||||
|
||||
@ -137,7 +137,7 @@ class Cell(object):
|
||||
if edge in {'top', 'bottom'} or (edge == 'left' and self is self.row.first_cell) or (edge == 'right' and self is self.row.last_cell):
|
||||
padding += getattr(self.row, 'padding_' + edge)
|
||||
if padding > 0:
|
||||
makeelement(m, 'w:' + edge, w_type='dxa', w_w=str(int(padding * 20)))
|
||||
makeelement(m, 'w:' + edge, w_type='dxa', w_w=unicode_type(int(padding * 20)))
|
||||
if len(m) > 0:
|
||||
tcPr.append(m)
|
||||
|
||||
@ -357,14 +357,14 @@ class Table(object):
|
||||
return
|
||||
tbl = makeelement(parent, 'w:tbl')
|
||||
tblPr = makeelement(tbl, 'w:tblPr')
|
||||
makeelement(tblPr, 'w:tblW', w_type=self.width[0], w_w=str(self.width[1]))
|
||||
makeelement(tblPr, 'w:tblW', w_type=self.width[0], w_w=unicode_type(self.width[1]))
|
||||
if self.float in {'left', 'right'}:
|
||||
kw = {'w_vertAnchor':'text', 'w_horzAnchor':'text', 'w_tblpXSpec':self.float}
|
||||
for edge in border_edges:
|
||||
val = getattr(self, 'margin_' + edge) or 0
|
||||
if {self.float, edge} == {'left', 'right'}:
|
||||
val = max(val, 2)
|
||||
kw['w_' + edge + 'FromText'] = str(max(0, int(val *20)))
|
||||
kw['w_' + edge + 'FromText'] = unicode_type(max(0, int(val *20)))
|
||||
makeelement(tblPr, 'w:tblpPr', **kw)
|
||||
if self.jc is not None:
|
||||
makeelement(tblPr, 'w:jc', w_val=self.jc)
|
||||
|
@ -16,7 +16,7 @@ from calibre.ebooks.oeb.polish.replace import rename_files, rationalize_folders
|
||||
from calibre.ebooks.oeb.polish.split import split, merge
|
||||
from calibre.utils.filenames import nlinks_file
|
||||
from calibre.ptempfile import TemporaryFile, TemporaryDirectory
|
||||
from polyglot.builtins import iteritems, itervalues
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
|
||||
|
||||
def get_container(*args, **kwargs):
|
||||
@ -99,7 +99,7 @@ class ContainerTests(BaseTest):
|
||||
|
||||
def new_container():
|
||||
count[0] += 1
|
||||
tdir = os.mkdir(os.path.join(self.tdir, str(count[0])))
|
||||
tdir = os.mkdir(os.path.join(self.tdir, unicode_type(count[0])))
|
||||
return get_container(book, tdir=tdir)
|
||||
|
||||
# Test simple opf rename
|
||||
|
@ -20,6 +20,7 @@ from calibre.ebooks.oeb.polish.utils import guess_type
|
||||
from calibre.ebooks.oeb.base import OEB_DOCS
|
||||
from calibre.ebooks.metadata.book.base import Metadata
|
||||
from calibre.ebooks.metadata.opf3 import CALIBRE_PREFIX
|
||||
from polyglot.builtins import unicode_type
|
||||
|
||||
OPF_TEMPLATE = '''
|
||||
<package xmlns="http://www.idpf.org/2007/opf" version="{ver}" prefix="calibre: %s" unique-identifier="uid">
|
||||
@ -78,7 +79,7 @@ class Structure(BaseTest):
|
||||
|
||||
def create_epub(self, *args, **kw):
|
||||
n = next(counter)
|
||||
ep = os.path.join(self.tdir, str(n) + 'book.epub')
|
||||
ep = os.path.join(self.tdir, unicode_type(n) + 'book.epub')
|
||||
with open(ep, 'wb') as f:
|
||||
f.write(create_epub(*args, **kw).getvalue())
|
||||
c = get_container(ep, tdir=os.path.join(self.tdir, 'container%d' % n), tweak_mode=True)
|
||||
|
@ -160,7 +160,7 @@ class TextBrowser(PlainTextEdit): # {{{
|
||||
|
||||
def calculate_metrics(self):
|
||||
w = self.fontMetrics()
|
||||
self.number_width = max(map(lambda x:w.width(str(x)), range(10)))
|
||||
self.number_width = max(map(lambda x:w.width(unicode_type(x)), range(10)))
|
||||
self.space_width = w.width(' ')
|
||||
|
||||
def show_context_menu(self, pos):
|
||||
|
@ -93,7 +93,9 @@ def create_lexer(base_class):
|
||||
state.pygments_stack = statestack
|
||||
return formats
|
||||
|
||||
return type(str('Qt'+base_class.__name__), (base_class,), {
|
||||
name_type = type(base_class.__name__)
|
||||
|
||||
return type(name_type('Qt'+base_class.__name__), (base_class,), {
|
||||
'get_tokens_unprocessed': get_tokens_unprocessed,
|
||||
'lex_a_line':lex_a_line,
|
||||
})
|
||||
@ -144,7 +146,8 @@ def create_formats(highlighter):
|
||||
|
||||
|
||||
def create_highlighter(name, lexer_class):
|
||||
return type(str(name), (SyntaxHighlighter,), {
|
||||
name_type = type(lexer_class.__name__)
|
||||
return type(name_type(name), (SyntaxHighlighter,), {
|
||||
'state_map': {NORMAL:create_lexer(lexer_class)().lex_a_line},
|
||||
'create_formats_func': create_formats,
|
||||
'user_data_factory': PygmentsUserData,
|
||||
|
@ -262,7 +262,7 @@ class TextEdit(PlainTextEdit):
|
||||
self.setFont(font)
|
||||
self.highlighter.apply_theme(theme)
|
||||
w = self.fontMetrics()
|
||||
self.number_width = max(map(lambda x:w.width(str(x)), range(10)))
|
||||
self.number_width = max(map(lambda x:w.width(unicode_type(x)), range(10)))
|
||||
self.size_hint = QSize(self.expected_geometry[0] * w.averageCharWidth(), self.expected_geometry[1] * w.height())
|
||||
self.highlight_color = theme_color(theme, 'HighlightRegion', 'bg')
|
||||
self.highlight_cursor_line()
|
||||
@ -685,7 +685,7 @@ class TextEdit(PlainTextEdit):
|
||||
painter.setFont(f)
|
||||
self.last_current_lnum = (top, bottom - top)
|
||||
painter.drawText(0, top, self.line_number_area.width() - 5, self.fontMetrics().height(),
|
||||
Qt.AlignRight, str(num + 1))
|
||||
Qt.AlignRight, unicode_type(num + 1))
|
||||
if current == num:
|
||||
painter.restore()
|
||||
block = block.next()
|
||||
|
Loading…
x
Reference in New Issue
Block a user