Remove unused code

This commit is contained in:
Kovid Goyal 2019-12-19 22:50:55 +05:30
parent a0420c9820
commit ae962ae3b1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -65,110 +65,20 @@ def refresh_spell_check_status():
from calibre.constants import plugins from calibre.constants import plugins
_speedup = plugins['html_syntax_highlighter'][0] _speedup = plugins['html_syntax_highlighter'][0]
if _speedup is not None:
Tag = _speedup.Tag Tag = _speedup.Tag
bold_tags, italic_tags = _speedup.bold_tags, _speedup.italic_tags bold_tags, italic_tags = _speedup.bold_tags, _speedup.italic_tags
State = _speedup.State State = _speedup.State
def spell_property(sfmt, locale): def spell_property(sfmt, locale):
s = QTextCharFormat(sfmt) s = QTextCharFormat(sfmt)
s.setProperty(SPELL_LOCALE_PROPERTY, locale) s.setProperty(SPELL_LOCALE_PROPERTY, locale)
return s return s
_speedup.init(spell_property, dictionaries.recognized, split_into_words_and_positions) _speedup.init(spell_property, dictionaries.recognized, split_into_words_and_positions)
del spell_property del spell_property
check_spelling = _speedup.check_spelling check_spelling = _speedup.check_spelling
else:
bold_tags = {'b', 'strong'} | {'h%d' % d for d in range(1, 7)}
italic_tags = {'i', 'em'}
class Tag(object):
__slots__ = ('name', 'bold', 'italic', 'lang')
def __init__(self, name, bold=None, italic=None, lang=None):
self.name = name
self.bold = name in bold_tags if bold is None else bold
self.italic = name in italic_tags if italic is None else italic
self.lang = lang
def __eq__(self, other):
try:
return self.name == other.name and self.lang == other.lang
except AttributeError:
return False
def copy(self):
ans = Tag(self.name, self.bold, self.italic, self.lang)
return ans
class State(object):
__slots__ = (
'tag_being_defined', 'tags', 'is_bold', 'is_italic', 'current_lang',
'parse', 'css_formats', 'sub_parser_state', 'default_lang', 'attribute_name',)
def __init__(self, tags=None):
self.tags = []
self.is_bold = self.is_italic = False
self.tag_being_defined = self.current_lang = self.css_formats = \
self.sub_parser_state = self.default_lang = self.attribute_name = None
self.parse = NORMAL
def copy(self):
ans = State()
for x in self.__slots__:
setattr(ans, x, getattr(self, x))
self.tags = [x.copy() for x in self.tags]
if self.tag_being_defined is not None:
self.tag_being_defined = self.tag_being_defined.copy()
if self.sub_parser_state is not None:
ans.sub_parser_state = self.sub_parser_state.copy()
return ans
def __eq__(self, other):
try:
return (
self.parse == other.parse and
self.sub_parser_state == other.sub_parser_state and
self.tag_being_defined == other.tag_being_defined and
self.attribute_name == other.attribute_name and
self.tags == other.tags
)
except AttributeError:
return False
def __ne__(self, other):
return not self.__eq__(other)
def __repr__(self):
return '<State %s is_bold=%s is_italic=%s current_lang=%s>' % (
'->'.join(x.name for x in self.tags), self.is_bold, self.is_italic, self.current_lang)
__str__ = __repr__
def check_spelling(text, tlen, fmt, locale, sfmt, store_locale):
split_ans = []
ppos = 0
r, a = dictionaries.recognized, split_ans.append
for start, length in split_into_words_and_positions(text, lang=locale.langcode):
if start > ppos:
a((start - ppos, fmt))
ppos = start + length
recognized = r(text[start:ppos], locale)
if recognized:
a((length, fmt))
else:
if store_locale:
s = QTextCharFormat(sfmt)
s.setProperty(SPELL_LOCALE_PROPERTY, locale)
a((length, s))
else:
a((length, sfmt))
if ppos < tlen:
a((tlen - ppos, fmt))
return split_ans
del _speedup
def finish_opening_tag(state, cdata_tags): def finish_opening_tag(state, cdata_tags):