mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-18 12:03:33 +02:00
Removed polyglots unicode_type usage
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from collections import OrderedDict
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -49,8 +49,8 @@ class Footnotes(object):
|
||||
if note is not None and note.type == 'normal':
|
||||
self.counter += 1
|
||||
anchor = 'note_%d' % self.counter
|
||||
self.notes[anchor] = (unicode_type(self.counter), note)
|
||||
return anchor, unicode_type(self.counter)
|
||||
self.notes[anchor] = (str(self.counter), note)
|
||||
return anchor, str(self.counter)
|
||||
return None, None
|
||||
|
||||
def __iter__(self):
|
||||
|
||||
@@ -7,7 +7,7 @@ from lxml.html.builder import OL, UL, SPAN
|
||||
from ebook_converter.ebooks.docx.block_styles import ParagraphStyle
|
||||
from ebook_converter.ebooks.docx.char_styles import RunStyle, inherit
|
||||
from ebook_converter.ebooks.metadata import roman
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -288,7 +288,7 @@ class Numbering(object):
|
||||
seen_instances.add(num_id)
|
||||
p.tag = 'li'
|
||||
p.set('value', '%s' % counter[ilvl])
|
||||
p.set('list-lvl', unicode_type(ilvl))
|
||||
p.set('list-lvl', str(ilvl))
|
||||
p.set('list-id', num_id)
|
||||
if lvl.num_template is not None:
|
||||
val = lvl.format_template(counter, ilvl, lvl.num_template)
|
||||
|
||||
@@ -2,7 +2,7 @@ from lxml.html.builder import TABLE, TR, TD
|
||||
|
||||
from ebook_converter.ebooks.docx.block_styles import inherit, read_shd as rs, read_border, binary_property, border_props, ParagraphStyle, border_to_css
|
||||
from ebook_converter.ebooks.docx.char_styles import RunStyle
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -643,9 +643,9 @@ class Table(object):
|
||||
td = TD()
|
||||
style_map[td] = s = self.style_map[tc]
|
||||
if s.col_span is not inherit:
|
||||
td.set('colspan', unicode_type(s.col_span))
|
||||
td.set('colspan', str(s.col_span))
|
||||
if s.row_span is not inherit:
|
||||
td.set('rowspan', unicode_type(s.row_span))
|
||||
td.set('rowspan', str(s.row_span))
|
||||
td.tail = '\n\t\t\t'
|
||||
tr.append(td)
|
||||
for x in self.namespace.XPath('./w:p|./w:tbl')(tc):
|
||||
|
||||
@@ -21,7 +21,7 @@ from ebook_converter.ebooks.docx.fields import Fields
|
||||
from ebook_converter.ebooks.docx.settings import Settings
|
||||
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
|
||||
from ebook_converter.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, getcwd, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, getcwd
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -476,7 +476,7 @@ class Convert(object):
|
||||
current_hyperlink = x
|
||||
elif x.tag.endswith('}instrText') and x.text and x.text.strip().startswith('TOC '):
|
||||
old_anchor = current_anchor
|
||||
anchor = unicode_type(uuid.uuid4())
|
||||
anchor = str(uuid.uuid4())
|
||||
self.anchor_map[anchor] = current_anchor = generate_anchor('toc', frozenset(itervalues(self.anchor_map)))
|
||||
self.toc_anchor = current_anchor
|
||||
if old_anchor is not None:
|
||||
@@ -493,7 +493,7 @@ class Convert(object):
|
||||
if m is not None:
|
||||
n = min(6, max(1, int(m.group(1))))
|
||||
dest.tag = 'h%d' % n
|
||||
dest.set('data-heading-level', unicode_type(n))
|
||||
dest.set('data-heading-level', str(n))
|
||||
|
||||
if style.bidi is True:
|
||||
dest.set('dir', 'rtl')
|
||||
|
||||
@@ -11,7 +11,7 @@ from ebook_converter.ebooks.pdf.render.common import PAPER_SIZES
|
||||
from ebook_converter.utils.date import utcnow
|
||||
from ebook_converter.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||
from ebook_converter.utils.zipfile import ZipFile
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, native_string_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, native_string_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -62,9 +62,9 @@ def create_skeleton(opts, namespaces=None):
|
||||
|
||||
def margin(which):
|
||||
val = page_margin(opts, which)
|
||||
return w(which), unicode_type(int(val * 20))
|
||||
return w(which), str(int(val * 20))
|
||||
body.append(E.sectPr(
|
||||
E.pgSz(**{w('w'):unicode_type(width), w('h'):unicode_type(height)}),
|
||||
E.pgSz(**{w('w'):str(width), w('h'):str(height)}),
|
||||
E.pgMar(**dict(map(margin, 'left top right bottom'.split()))),
|
||||
E.cols(**{w('space'):'720'}),
|
||||
E.docGrid(**{w('linePitch'):"360"}),
|
||||
|
||||
@@ -11,7 +11,7 @@ from ebook_converter.ebooks.docx.writer.lists import ListsManager
|
||||
from ebook_converter.ebooks.oeb.stylizer import Stylizer as Sz, Style as St
|
||||
from ebook_converter.ebooks.oeb.base import XPath, barename
|
||||
from ebook_converter.utils.localization import lang_as_iso639_1
|
||||
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes
|
||||
from ebook_converter.polyglot.builtins import string_or_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -98,7 +98,7 @@ class TextRun(object):
|
||||
for text, preserve_whitespace, bookmark in self.texts:
|
||||
if bookmark is not None:
|
||||
bid = links_manager.bookmark_id
|
||||
makeelement(r, 'w:bookmarkStart', w_id=unicode_type(bid), w_name=bookmark)
|
||||
makeelement(r, 'w:bookmarkStart', w_id=str(bid), w_name=bookmark)
|
||||
if text is None:
|
||||
makeelement(r, 'w:br', w_clear=preserve_whitespace)
|
||||
elif hasattr(text, 'xpath'):
|
||||
@@ -109,7 +109,7 @@ class TextRun(object):
|
||||
if preserve_whitespace:
|
||||
t.set('{http://www.w3.org/XML/1998/namespace}space', 'preserve')
|
||||
if bookmark is not None:
|
||||
makeelement(r, 'w:bookmarkEnd', w_id=unicode_type(bid))
|
||||
makeelement(r, 'w:bookmarkEnd', w_id=str(bid))
|
||||
|
||||
def __repr__(self):
|
||||
return repr(self.texts)
|
||||
@@ -125,7 +125,7 @@ class TextRun(object):
|
||||
def style_weight(self):
|
||||
ans = 0
|
||||
for text, preserve_whitespace, bookmark in self.texts:
|
||||
if isinstance(text, unicode_type):
|
||||
if isinstance(text, str):
|
||||
ans += len(text)
|
||||
return ans
|
||||
|
||||
@@ -205,7 +205,7 @@ class Block(object):
|
||||
p = makeelement(body, 'w:p')
|
||||
end_bookmarks = []
|
||||
for bmark in self.bookmarks:
|
||||
end_bookmarks.append(unicode_type(self.links_manager.bookmark_id))
|
||||
end_bookmarks.append(str(self.links_manager.bookmark_id))
|
||||
makeelement(p, 'w:bookmarkStart', w_id=end_bookmarks[-1], w_name=bmark)
|
||||
if self.block_lang:
|
||||
rpr = makeelement(p, 'w:rPr')
|
||||
@@ -218,8 +218,8 @@ class Block(object):
|
||||
self.float_spec.serialize(self, ppr)
|
||||
if self.numbering_id is not None:
|
||||
numpr = makeelement(ppr, 'w:numPr')
|
||||
makeelement(numpr, 'w:ilvl', w_val=unicode_type(self.numbering_id[1]))
|
||||
makeelement(numpr, 'w:numId', w_val=unicode_type(self.numbering_id[0]))
|
||||
makeelement(numpr, 'w:ilvl', w_val=str(self.numbering_id[1]))
|
||||
makeelement(numpr, 'w:numId', w_val=str(self.numbering_id[0]))
|
||||
if self.linked_style is not None:
|
||||
makeelement(ppr, 'w:pStyle', w_val=self.linked_style.id)
|
||||
elif self.style.id:
|
||||
@@ -439,8 +439,8 @@ class Convert(object):
|
||||
if self.add_toc:
|
||||
self.links_manager.process_toc_links(self.oeb)
|
||||
|
||||
if self.add_cover and self.oeb.metadata.cover and unicode_type(self.oeb.metadata.cover[0]) in self.oeb.manifest.ids:
|
||||
cover_id = unicode_type(self.oeb.metadata.cover[0])
|
||||
if self.add_cover and self.oeb.metadata.cover and str(self.oeb.metadata.cover[0]) in self.oeb.manifest.ids:
|
||||
cover_id = str(self.oeb.metadata.cover[0])
|
||||
item = self.oeb.manifest.ids[cover_id]
|
||||
self.cover_img = self.images_manager.read_image(item.href)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
import posixpath
|
||||
from collections import namedtuple
|
||||
from functools import partial
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues
|
||||
|
||||
from lxml import etree
|
||||
|
||||
@@ -31,7 +31,7 @@ def get_image_margins(style):
|
||||
ans = {}
|
||||
for edge in 'Left Right Top Bottom'.split():
|
||||
val = as_num(getattr(style, 'padding' + edge)) + as_num(getattr(style, 'margin' + edge))
|
||||
ans['dist' + edge[0]] = unicode_type(pt_to_emu(val))
|
||||
ans['dist' + edge[0]] = str(pt_to_emu(val))
|
||||
return ans
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ class ImagesManager(object):
|
||||
makeelement(parent, 'wp:simplePos', x='0', y='0')
|
||||
makeelement(makeelement(parent, 'wp:positionH', relativeFrom='margin'), 'wp:align').text = floating
|
||||
makeelement(makeelement(parent, 'wp:positionV', relativeFrom='line'), 'wp:align').text = 'top'
|
||||
makeelement(parent, 'wp:extent', cx=unicode_type(width), cy=unicode_type(height))
|
||||
makeelement(parent, 'wp:extent', cx=str(width), cy=str(height))
|
||||
if fake_margins:
|
||||
# DOCX does not support setting margins for inline images, so we
|
||||
# fake it by using effect extents to simulate margins
|
||||
@@ -141,7 +141,7 @@ class ImagesManager(object):
|
||||
|
||||
def create_docx_image_markup(self, parent, name, alt, img_rid, width, height):
|
||||
makeelement, namespaces = self.document_relationships.namespace.makeelement, self.document_relationships.namespace.namespaces
|
||||
makeelement(parent, 'wp:docPr', id=unicode_type(self.count), name=name, descr=alt)
|
||||
makeelement(parent, 'wp:docPr', id=str(self.count), name=name, descr=alt)
|
||||
makeelement(makeelement(parent, 'wp:cNvGraphicFramePr'), 'a:graphicFrameLocks', noChangeAspect="1")
|
||||
g = makeelement(parent, 'a:graphic')
|
||||
gd = makeelement(g, 'a:graphicData', uri=namespaces['pic'])
|
||||
@@ -154,7 +154,7 @@ class ImagesManager(object):
|
||||
makeelement(makeelement(bf, 'a:stretch'), 'a:fillRect')
|
||||
spPr = makeelement(pic, 'pic:spPr')
|
||||
xfrm = makeelement(spPr, 'a:xfrm')
|
||||
makeelement(xfrm, 'a:off', x='0', y='0'), makeelement(xfrm, 'a:ext', cx=unicode_type(width), cy=unicode_type(height))
|
||||
makeelement(xfrm, 'a:off', x='0', y='0'), makeelement(xfrm, 'a:ext', cx=str(width), cy=str(height))
|
||||
makeelement(makeelement(spPr, 'a:prstGeom', prst='rect'), 'a:avLst')
|
||||
|
||||
def create_filename(self, href, fmt):
|
||||
@@ -165,7 +165,7 @@ class ImagesManager(object):
|
||||
base = fname
|
||||
while fname.lower() in self.seen_filenames:
|
||||
num += 1
|
||||
fname = base + unicode_type(num)
|
||||
fname = base + str(num)
|
||||
self.seen_filenames.add(fname.lower())
|
||||
fname += os.extsep + fmt.lower()
|
||||
return fname
|
||||
@@ -200,7 +200,7 @@ class ImagesManager(object):
|
||||
makeelement(makeelement(parent, 'wp:positionH', relativeFrom='page'), 'wp:align').text = 'center'
|
||||
makeelement(makeelement(parent, 'wp:positionV', relativeFrom='page'), 'wp:align').text = 'center'
|
||||
width, height = map(pt_to_emu, (width, height))
|
||||
makeelement(parent, 'wp:extent', cx=unicode_type(width), cy=unicode_type(height))
|
||||
makeelement(parent, 'wp:extent', cx=str(width), cy=str(height))
|
||||
makeelement(parent, 'wp:effectExtent', l='0', r='0', t='0', b='0')
|
||||
makeelement(parent, 'wp:wrapTopAndBottom')
|
||||
self.create_docx_image_markup(parent, 'cover.jpg', _('Cover'), img.rid, width, height)
|
||||
|
||||
@@ -4,7 +4,6 @@ import urllib.parse
|
||||
import uuid
|
||||
|
||||
from ebook_converter.utils.filenames import ascii_text
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -34,7 +33,7 @@ class TOCItem(object):
|
||||
p = makeelement(body, 'w:p', append=False)
|
||||
ppr = makeelement(p, 'w:pPr')
|
||||
makeelement(ppr, 'w:pStyle', w_val="Normal")
|
||||
makeelement(ppr, 'w:ind', w_left='0', w_firstLineChars='0', w_firstLine='0', w_leftChars=unicode_type(200 * self.level))
|
||||
makeelement(ppr, 'w:ind', w_left='0', w_firstLineChars='0', w_firstLine='0', w_leftChars=str(200 * self.level))
|
||||
if self.is_first:
|
||||
makeelement(ppr, 'w:pageBreakBefore', w_val='off')
|
||||
r = makeelement(p, 'w:r')
|
||||
@@ -68,7 +67,7 @@ class LinksManager(object):
|
||||
self.namespace = namespace
|
||||
self.log = log
|
||||
self.document_relationships = document_relationships
|
||||
self.top_anchor = unicode_type(uuid.uuid4().hex)
|
||||
self.top_anchor = str(uuid.uuid4().hex)
|
||||
self.anchor_map = {}
|
||||
self.used_bookmark_names = set()
|
||||
self.bmark_id = 0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from collections import defaultdict
|
||||
from operator import attrgetter
|
||||
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -80,7 +80,7 @@ class NumberingDefinition(object):
|
||||
|
||||
def serialize(self, parent):
|
||||
makeelement = self.namespace.makeelement
|
||||
an = makeelement(parent, 'w:abstractNum', w_abstractNumId=unicode_type(self.num_id))
|
||||
an = makeelement(parent, 'w:abstractNum', w_abstractNumId=str(self.num_id))
|
||||
makeelement(an, 'w:multiLevelType', w_val='hybridMultilevel')
|
||||
makeelement(an, 'w:name', w_val='List %d' % (self.num_id + 1))
|
||||
for level in self.levels:
|
||||
@@ -111,12 +111,12 @@ class Level(object):
|
||||
return hash((self.start, self.num_fmt, self.lvl_text))
|
||||
|
||||
def serialize(self, parent, makeelement):
|
||||
lvl = makeelement(parent, 'w:lvl', w_ilvl=unicode_type(self.ilvl))
|
||||
makeelement(lvl, 'w:start', w_val=unicode_type(self.start))
|
||||
lvl = makeelement(parent, 'w:lvl', w_ilvl=str(self.ilvl))
|
||||
makeelement(lvl, 'w:start', w_val=str(self.start))
|
||||
makeelement(lvl, 'w:numFmt', w_val=self.num_fmt)
|
||||
makeelement(lvl, 'w:lvlText', w_val=self.lvl_text)
|
||||
makeelement(lvl, 'w:lvlJc', w_val='left')
|
||||
makeelement(makeelement(lvl, 'w:pPr'), 'w:ind', w_hanging='360', w_left=unicode_type(1152 + self.ilvl * 360))
|
||||
makeelement(makeelement(lvl, 'w:pPr'), 'w:ind', w_hanging='360', w_left=str(1152 + self.ilvl * 360))
|
||||
if self.num_fmt == 'bullet':
|
||||
ff = {'\uf0b7':'Symbol', '\uf0a7':'Wingdings'}.get(self.lvl_text, 'Courier New')
|
||||
makeelement(makeelement(lvl, 'w:rPr'), 'w:rFonts', w_ascii=ff, w_hAnsi=ff, w_hint="default")
|
||||
@@ -162,5 +162,5 @@ class ListsManager(object):
|
||||
defn.serialize(parent)
|
||||
makeelement = self.namespace.makeelement
|
||||
for defn in self.definitions:
|
||||
n = makeelement(parent, 'w:num', w_numId=unicode_type(defn.num_id + 1))
|
||||
makeelement(n, 'w:abstractNumId', w_val=unicode_type(defn.num_id))
|
||||
n = makeelement(parent, 'w:num', w_numId=str(defn.num_id + 1))
|
||||
makeelement(n, 'w:abstractNumId', w_val=str(defn.num_id))
|
||||
|
||||
@@ -7,7 +7,7 @@ from lxml import etree
|
||||
from ebook_converter.ebooks import parse_css_length
|
||||
from ebook_converter.ebooks.docx.writer.utils import convert_color, int_or_zero
|
||||
from ebook_converter.utils.localization import lang_as_iso639_1
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
from ebook_converter.tinycss.css21 import CSS21Parser
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class CombinedStyle(object):
|
||||
pPr = makeelement(block, 'w:pPr')
|
||||
self.bs.serialize_properties(pPr, normal_style.bs)
|
||||
if self.outline_level is not None:
|
||||
makeelement(pPr, 'w:outlineLvl', w_val=unicode_type(self.outline_level + 1))
|
||||
makeelement(pPr, 'w:outlineLvl', w_val=str(self.outline_level + 1))
|
||||
rPr = makeelement(block, 'w:rPr')
|
||||
self.rs.serialize_properties(rPr, normal_style.rs)
|
||||
|
||||
@@ -106,16 +106,16 @@ class FloatSpec(object):
|
||||
|
||||
def serialize(self, block, parent):
|
||||
if self.is_dropcaps:
|
||||
attrs = dict(w_dropCap='drop', w_lines=unicode_type(self.dropcaps_lines), w_wrap='around', w_vAnchor='text', w_hAnchor='text')
|
||||
attrs = dict(w_dropCap='drop', w_lines=str(self.dropcaps_lines), w_wrap='around', w_vAnchor='text', w_hAnchor='text')
|
||||
else:
|
||||
attrs = dict(
|
||||
w_wrap='around', w_vAnchor='text', w_hAnchor='text', w_xAlign=self.x_align, w_y='1',
|
||||
w_hSpace=unicode_type(self.h_space), w_vSpace=unicode_type(self.v_space), w_hRule=self.h_rule
|
||||
w_hSpace=str(self.h_space), w_vSpace=str(self.v_space), w_hRule=self.h_rule
|
||||
)
|
||||
if self.w is not None:
|
||||
attrs['w_w'] = unicode_type(self.w)
|
||||
attrs['w_w'] = str(self.w)
|
||||
if self.h is not None:
|
||||
attrs['w_h'] = unicode_type(self.h)
|
||||
attrs['w_h'] = str(self.h)
|
||||
self.makeelement(parent, 'w:framePr', **attrs)
|
||||
# Margins are already applied by the frame style, so override them to
|
||||
# be zero on individual blocks
|
||||
@@ -135,7 +135,7 @@ class FloatSpec(object):
|
||||
width = getattr(self, 'border_%s_width' % edge)
|
||||
bstyle = getattr(self, 'border_%s_style' % edge)
|
||||
self.makeelement(
|
||||
bdr, 'w:'+edge, w_space=unicode_type(padding), w_val=bstyle, w_sz=unicode_type(width), w_color=getattr(self, 'border_%s_color' % edge))
|
||||
bdr, 'w:'+edge, w_space=str(padding), w_val=bstyle, w_sz=str(width), w_color=getattr(self, 'border_%s_color' % edge))
|
||||
|
||||
|
||||
class DOCXStyle(object):
|
||||
@@ -231,7 +231,7 @@ class TextStyle(DOCXStyle):
|
||||
self.spacing = None
|
||||
va = css.first_vertical_align
|
||||
if isinstance(va, numbers.Number):
|
||||
self.vertical_align = unicode_type(int(va * 2))
|
||||
self.vertical_align = str(int(va * 2))
|
||||
else:
|
||||
val = {
|
||||
'top':'superscript', 'text-top':'superscript', 'sup':'superscript', 'super':'superscript',
|
||||
@@ -287,9 +287,9 @@ class TextStyle(DOCXStyle):
|
||||
w = self.w
|
||||
is_normal_style = self is normal_style
|
||||
if is_normal_style or self.padding != normal_style.padding:
|
||||
bdr.set(w('space'), unicode_type(self.padding))
|
||||
bdr.set(w('space'), str(self.padding))
|
||||
if is_normal_style or self.border_width != normal_style.border_width:
|
||||
bdr.set(w('sz'), unicode_type(self.border_width))
|
||||
bdr.set(w('sz'), str(self.border_width))
|
||||
if is_normal_style or self.border_style != normal_style.border_style:
|
||||
bdr.set(w('val'), self.border_style)
|
||||
if is_normal_style or self.border_color != normal_style.border_color:
|
||||
@@ -339,7 +339,7 @@ class TextStyle(DOCXStyle):
|
||||
if check_attr('shadow'):
|
||||
rPr.append(makeelement(rPr, 'shadow', val=bmap(self.shadow)))
|
||||
if check_attr('spacing'):
|
||||
rPr.append(makeelement(rPr, 'spacing', val=unicode_type(self.spacing or 0)))
|
||||
rPr.append(makeelement(rPr, 'spacing', val=str(self.spacing or 0)))
|
||||
if is_normal_style:
|
||||
rPr.append(makeelement(rPr, 'vertAlign', val=self.vertical_align if self.vertical_align in {'superscript', 'subscript'} else 'baseline'))
|
||||
elif self.vertical_align != normal_style.vertical_align:
|
||||
@@ -377,7 +377,7 @@ class DescendantTextStyle(object):
|
||||
for name, attr in (('sz', 'font_size'), ('b', 'bold'), ('i', 'italic')):
|
||||
pval, cval = vals(attr)
|
||||
if pval != cval:
|
||||
val = 'on' if attr in {'bold', 'italic'} else unicode_type(cval) # bold, italic are toggle properties
|
||||
val = 'on' if attr in {'bold', 'italic'} else str(cval) # bold, italic are toggle properties
|
||||
for suffix in ('', 'Cs'):
|
||||
add(name + suffix, val=val)
|
||||
|
||||
@@ -398,7 +398,7 @@ class DescendantTextStyle(object):
|
||||
if check('shadow'):
|
||||
add('shadow', val='on') # toggle property
|
||||
if check('spacing'):
|
||||
add('spacing', val=unicode_type(child_style.spacing or 0))
|
||||
add('spacing', val=str(child_style.spacing or 0))
|
||||
if check('vertical_align'):
|
||||
val = child_style.vertical_align
|
||||
if val in {'superscript', 'subscript', 'baseline'}:
|
||||
@@ -408,9 +408,9 @@ class DescendantTextStyle(object):
|
||||
|
||||
bdr = {}
|
||||
if check('padding'):
|
||||
bdr['space'] = unicode_type(child_style.padding)
|
||||
bdr['space'] = str(child_style.padding)
|
||||
if check('border_width'):
|
||||
bdr['sz'] = unicode_type(child_style.border_width)
|
||||
bdr['sz'] = str(child_style.border_width)
|
||||
if check('border_style'):
|
||||
bdr['val'] = child_style.border_style
|
||||
if check('border_color'):
|
||||
@@ -534,14 +534,14 @@ class BlockStyle(DOCXStyle):
|
||||
e = bdr.makeelement(w(edge))
|
||||
padding = getattr(self, 'padding_' + edge)
|
||||
if (self is normal_style and padding > 0) or (padding != getattr(normal_style, 'padding_' + edge)):
|
||||
e.set(w('space'), unicode_type(padding))
|
||||
e.set(w('space'), str(padding))
|
||||
width = getattr(self, 'border_%s_width' % edge)
|
||||
bstyle = getattr(self, 'border_%s_style' % edge)
|
||||
if (self is normal_style and width > 0 and bstyle != 'none'
|
||||
) or width != getattr(normal_style, 'border_%s_width' % edge
|
||||
) or bstyle != getattr(normal_style, 'border_%s_style' % edge):
|
||||
e.set(w('val'), bstyle)
|
||||
e.set(w('sz'), unicode_type(width))
|
||||
e.set(w('sz'), str(width))
|
||||
e.set(w('color'), getattr(self, 'border_%s_color' % edge))
|
||||
if e.attrib:
|
||||
bdr.append(e)
|
||||
@@ -565,15 +565,15 @@ class BlockStyle(DOCXStyle):
|
||||
if css_unit in ('em', 'ex'):
|
||||
lines = max(0, int(css_val * (50 if css_unit == 'ex' else 100)))
|
||||
if (self is normal_style and lines > 0) or getter(self) != getter(normal_style):
|
||||
spacing.set(w(attr + 'Lines'), unicode_type(lines))
|
||||
spacing.set(w(attr + 'Lines'), str(lines))
|
||||
else:
|
||||
getter = attrgetter('margin_' + edge)
|
||||
val = getter(self)
|
||||
if (self is normal_style and val > 0) or val != getter(normal_style):
|
||||
spacing.set(w(attr), unicode_type(val))
|
||||
spacing.set(w(attr), str(val))
|
||||
|
||||
if self is normal_style or self.line_height != normal_style.line_height:
|
||||
spacing.set(w('line'), unicode_type(self.line_height))
|
||||
spacing.set(w('line'), str(self.line_height))
|
||||
spacing.set(w('lineRule'), 'atLeast')
|
||||
|
||||
if spacing.attrib:
|
||||
@@ -586,31 +586,31 @@ class BlockStyle(DOCXStyle):
|
||||
if css_unit in ('em', 'ex'):
|
||||
chars = max(0, int(css_val * (50 if css_unit == 'ex' else 100)))
|
||||
if (self is normal_style and chars > 0) or getter(self) != getter(normal_style):
|
||||
ind.set(w(edge + 'Chars'), unicode_type(chars))
|
||||
ind.set(w(edge + 'Chars'), str(chars))
|
||||
else:
|
||||
getter = attrgetter('margin_' + edge)
|
||||
val = getter(self)
|
||||
if (self is normal_style and val > 0) or val != getter(normal_style):
|
||||
ind.set(w(edge), unicode_type(val))
|
||||
ind.set(w(edge), str(val))
|
||||
ind.set(w(edge + 'Chars'), '0') # This is needed to override any declaration in the parent style
|
||||
css_val, css_unit = parse_css_length(self.css_text_indent)
|
||||
if css_unit in ('em', 'ex'):
|
||||
chars = int(css_val * (50 if css_unit == 'ex' else 100))
|
||||
if css_val >= 0:
|
||||
if (self is normal_style and chars > 0) or self.css_text_indent != normal_style.css_text_indent:
|
||||
ind.set(w('firstLineChars'), unicode_type(chars))
|
||||
ind.set(w('firstLineChars'), str(chars))
|
||||
else:
|
||||
if (self is normal_style and chars < 0) or self.css_text_indent != normal_style.css_text_indent:
|
||||
ind.set(w('hangingChars'), unicode_type(abs(chars)))
|
||||
ind.set(w('hangingChars'), str(abs(chars)))
|
||||
else:
|
||||
val = self.text_indent
|
||||
if val >= 0:
|
||||
if (self is normal_style and val > 0) or self.text_indent != normal_style.text_indent:
|
||||
ind.set(w('firstLine'), unicode_type(val))
|
||||
ind.set(w('firstLine'), str(val))
|
||||
ind.set(w('firstLineChars'), '0') # This is needed to override any declaration in the parent style
|
||||
else:
|
||||
if (self is normal_style and val < 0) or self.text_indent != normal_style.text_indent:
|
||||
ind.set(w('hanging'), unicode_type(abs(val)))
|
||||
ind.set(w('hanging'), str(abs(val)))
|
||||
ind.set(w('hangingChars'), '0')
|
||||
if ind.attrib:
|
||||
pPr.append(ind)
|
||||
@@ -684,7 +684,7 @@ class StylesManager(object):
|
||||
pure_block_styles.add(bs)
|
||||
|
||||
self.pure_block_styles = sorted(pure_block_styles, key=block_counts.__getitem__)
|
||||
bnum = len(unicode_type(max(1, len(pure_block_styles) - 1)))
|
||||
bnum = len(str(max(1, len(pure_block_styles) - 1)))
|
||||
for i, bs in enumerate(self.pure_block_styles):
|
||||
bs.id = bs.name = '%0{}d Block'.format(bnum) % i
|
||||
bs.seq = i
|
||||
@@ -704,7 +704,7 @@ class StylesManager(object):
|
||||
heading_style = styles[-1]
|
||||
heading_style.outline_level = i
|
||||
|
||||
snum = len(unicode_type(max(1, len(counts) - 1)))
|
||||
snum = len(str(max(1, len(counts) - 1)))
|
||||
heading_styles = []
|
||||
for i, (style, count) in enumerate(counts.most_common()):
|
||||
if i == 0:
|
||||
@@ -732,7 +732,7 @@ class StylesManager(object):
|
||||
if run.descendant_style is None:
|
||||
run.descendant_style = descendant_style_map[ds] = ds
|
||||
ds_counts[run.descendant_style] += run.style_weight
|
||||
rnum = len(unicode_type(max(1, len(ds_counts) - 1)))
|
||||
rnum = len(str(max(1, len(ds_counts) - 1)))
|
||||
for i, (text_style, count) in enumerate(ds_counts.most_common()):
|
||||
text_style.id = 'Text%d' % i
|
||||
text_style.name = '%0{}d Text'.format(rnum) % i
|
||||
|
||||
@@ -2,7 +2,7 @@ from collections import namedtuple
|
||||
|
||||
from ebook_converter.ebooks.docx.writer.utils import convert_color
|
||||
from ebook_converter.ebooks.docx.writer.styles import read_css_block_borders as rcbb, border_edges
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -112,7 +112,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=unicode_type(self.width[1]))
|
||||
makeelement(tcPr, 'w:tcW', w_type=self.width[0], w_w=str(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
|
||||
@@ -123,7 +123,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=unicode_type(border.width), w_color=border.color)
|
||||
makeelement(b, 'w:' + edge, w_val=border.style, w_sz=str(border.width), w_color=border.color)
|
||||
if len(b) > 0:
|
||||
tcPr.append(b)
|
||||
|
||||
@@ -133,7 +133,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=unicode_type(int(padding * 20)))
|
||||
makeelement(m, 'w:' + edge, w_type='dxa', w_w=str(int(padding * 20)))
|
||||
if len(m) > 0:
|
||||
tcPr.append(m)
|
||||
|
||||
@@ -353,14 +353,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=unicode_type(self.width[1]))
|
||||
makeelement(tblPr, 'w:tblW', w_type=self.width[0], w_w=str(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'] = unicode_type(max(0, int(val *20)))
|
||||
kw['w_' + edge + 'FromText'] = str(max(0, int(val *20)))
|
||||
makeelement(tblPr, 'w:tblpPr', **kw)
|
||||
if self.jc is not None:
|
||||
makeelement(tblPr, 'w:jc', w_val=self.jc)
|
||||
|
||||
Reference in New Issue
Block a user