mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-01-09 21:50:19 -05:00
repeated equality comparison (auto-fix)
ruff 'PLR1714' --unsafe-fixes
This commit is contained in:
parent
f4e335bbe9
commit
0dc4e67529
@ -114,7 +114,7 @@ select = [
|
||||
'E', 'F', 'I', 'W', 'INT',
|
||||
'Q', 'UP', 'YTT', 'TID', 'C4', 'COM818', 'PIE', 'RET501', 'ISC',
|
||||
'PLE', 'PLW', 'PLC',
|
||||
'PLR0402', 'PLR1711', 'PLR1716', 'PLR1722', 'PLR1733', 'PLR1736', 'PLR1730', 'PLR5501',
|
||||
'PLR0402', 'PLR1711', 'PLR1716', 'PLR1722', 'PLR1733', 'PLR1736', 'PLR1730', 'PLR5501', 'PLR1714',
|
||||
'RUF', # note: RUF can flag many unsolicited errors
|
||||
# preview rules
|
||||
'RUF051', 'RUF056', # useless dict operation
|
||||
|
||||
@ -248,7 +248,7 @@ class CanWestPaper(BasicNewsRecipe):
|
||||
ans = []
|
||||
|
||||
def handle_article(adiv, key):
|
||||
if adiv.name == 'h1' or adiv.name == 'h3':
|
||||
if adiv.name in {'h1', 'h3'}:
|
||||
h1tag = adiv
|
||||
else:
|
||||
h1tag = adiv.h1
|
||||
|
||||
@ -248,7 +248,7 @@ class CanWestPaper(BasicNewsRecipe):
|
||||
ans = []
|
||||
|
||||
def handle_article(adiv, key):
|
||||
if adiv.name == 'h1' or adiv.name == 'h3':
|
||||
if adiv.name in {'h1', 'h3'}:
|
||||
h1tag = adiv
|
||||
else:
|
||||
h1tag = adiv.h1
|
||||
|
||||
@ -9,7 +9,7 @@ def format_tickaroo_liveblog(soup):
|
||||
sources = img['srcset'].split()
|
||||
i=0
|
||||
for x in sources:
|
||||
if x == '960w,' or x == '960w':
|
||||
if x in {'960w,', '960w'}:
|
||||
img['src'] = sources[i-1]
|
||||
break
|
||||
i = i + 1
|
||||
|
||||
@ -248,7 +248,7 @@ class CanWestPaper(BasicNewsRecipe):
|
||||
ans = []
|
||||
|
||||
def handle_article(adiv, key):
|
||||
if adiv.name == 'h1' or adiv.name == 'h3':
|
||||
if adiv.name in {'h1', 'h3'}:
|
||||
h1tag = adiv
|
||||
else:
|
||||
h1tag = adiv.h1
|
||||
|
||||
@ -65,7 +65,7 @@ class NRCNext(BasicNewsRecipe):
|
||||
subst = '\\1'
|
||||
for name in namelist:
|
||||
_, ext = os.path.splitext(name)
|
||||
if (ext == '.html') or (ext == '.ncx'):
|
||||
if ext in {'.html', '.ncx'}:
|
||||
fname = os.path.join(self.output_dir, name)
|
||||
with open(fname) as f:
|
||||
s = f.read()
|
||||
|
||||
@ -248,7 +248,7 @@ class CanWestPaper(BasicNewsRecipe):
|
||||
ans = []
|
||||
|
||||
def handle_article(adiv, key):
|
||||
if adiv.name == 'h1' or adiv.name == 'h3':
|
||||
if adiv.name in {'h1', 'h3'}:
|
||||
h1tag = adiv
|
||||
else:
|
||||
h1tag = adiv.h1
|
||||
|
||||
@ -261,7 +261,7 @@ class CanWestPaper(BasicNewsRecipe):
|
||||
ans = []
|
||||
|
||||
def handle_article(adiv, key):
|
||||
if adiv.name == 'h1' or adiv.name == 'h3':
|
||||
if adiv.name in {'h1', 'h3'}:
|
||||
h1tag = adiv
|
||||
else:
|
||||
h1tag = adiv.h1
|
||||
|
||||
@ -249,7 +249,7 @@ class CanWestPaper(BasicNewsRecipe):
|
||||
ans = []
|
||||
|
||||
def handle_article(adiv, key):
|
||||
if adiv.name == 'h1' or adiv.name == 'h3':
|
||||
if adiv.name in {'h1', 'h3'}:
|
||||
h1tag = adiv
|
||||
else:
|
||||
h1tag = adiv.h1
|
||||
|
||||
@ -194,7 +194,7 @@ class TimesColonist(BasicNewsRecipe):
|
||||
ptext = self.tag_to_string(
|
||||
ptag, use_alt=False, normalize_whitespace=True)
|
||||
ptext = re.sub(r'\s+', '', ptext)
|
||||
if (ptext == '') or (ptext == ' '):
|
||||
if ptext in {'', ' '}:
|
||||
ptag.extract()
|
||||
return self.strip_anchors(soup)
|
||||
|
||||
|
||||
@ -441,7 +441,7 @@ class Build(Command):
|
||||
os.makedirs(x, exist_ok=True)
|
||||
pyqt_extensions, extensions = [], []
|
||||
for ext in all_extensions:
|
||||
if opts.only != 'all' and opts.only != ext.name:
|
||||
if opts.only not in ('all', ext.name):
|
||||
continue
|
||||
if not is_ext_allowed(self.compiling_for, ext):
|
||||
continue
|
||||
|
||||
@ -104,7 +104,7 @@ def adapt_bool(x):
|
||||
x = True
|
||||
elif x == 'false':
|
||||
x = False
|
||||
elif x == 'none' or x == '':
|
||||
elif x in {'none', ''}:
|
||||
x = None
|
||||
else:
|
||||
x = bool(int(x))
|
||||
|
||||
@ -252,7 +252,7 @@ class KOBO(USBMS):
|
||||
elif oncard == 'cardb' and not self._card_b_prefix:
|
||||
self.report_progress(1.0, _('Getting list of books on device...'))
|
||||
return dummy_bl
|
||||
elif oncard and oncard != 'carda' and oncard != 'cardb':
|
||||
elif oncard and oncard not in {'carda', 'cardb'}:
|
||||
self.report_progress(1.0, _('Getting list of books on device...'))
|
||||
return dummy_bl
|
||||
|
||||
@ -262,7 +262,7 @@ class KOBO(USBMS):
|
||||
|
||||
self.fwversion = self.get_firmware_version()
|
||||
|
||||
if not (self.fwversion == (1,0) or self.fwversion == (1,4)):
|
||||
if self.fwversion not in ((1, 0), (1, 4)):
|
||||
self.has_kepubs = True
|
||||
debug_print('Version of driver: ', self.version, 'Has kepubs:', self.has_kepubs)
|
||||
debug_print('Version of firmware: ', self.fwversion, 'Has kepubs:', self.has_kepubs)
|
||||
@ -418,7 +418,7 @@ class KOBO(USBMS):
|
||||
path = self.path_from_contentid(row['ContentID'], row['ContentType'], row['MimeType'], oncard)
|
||||
mime = mime_type_ext(path_to_ext(path)) if path.find('kepub') == -1 else 'application/epub+zip'
|
||||
# debug_print("mime:", mime)
|
||||
if oncard != 'carda' and oncard != 'cardb' and not row['ContentID'].startswith('file:///mnt/sd/'):
|
||||
if oncard not in {'carda', 'cardb'} and not row['ContentID'].startswith('file:///mnt/sd/'):
|
||||
prefix = self._main_prefix
|
||||
elif oncard == 'carda' and row['ContentID'].startswith('file:///mnt/sd/'):
|
||||
prefix = self._card_a_prefix
|
||||
@ -679,12 +679,12 @@ class KOBO(USBMS):
|
||||
# Kobo books do not have book files. They do have some images though
|
||||
# print('kobo book')
|
||||
ContentType = 6
|
||||
elif extension == '.pdf' or extension == '.epub':
|
||||
elif extension in {'.pdf', '.epub'}:
|
||||
# print('ePub or pdf')
|
||||
ContentType = 16
|
||||
elif extension == '.rtf' or extension == '.txt' or extension == '.htm' or extension == '.html':
|
||||
elif extension in {'.rtf', '.txt', '.htm', '.html'}:
|
||||
# print('txt')
|
||||
if self.fwversion == (1,0) or self.fwversion == (1,4) or self.fwversion == (1,7,4):
|
||||
if self.fwversion in ((1, 0), (1, 4), (1, 7, 4)):
|
||||
ContentType = 999
|
||||
else:
|
||||
ContentType = 901
|
||||
@ -709,7 +709,7 @@ class KOBO(USBMS):
|
||||
# for calibre's reference
|
||||
path = self._main_prefix + path + '.kobo'
|
||||
# print('Path: ' + path)
|
||||
elif (ContentType == '6' or ContentType == '10') and (
|
||||
elif (ContentType in {'6', '10'}) and (
|
||||
MimeType == 'application/x-kobo-epub+zip' or (
|
||||
MimeType == 'application/epub+zip' and self.isTolinoDevice())
|
||||
):
|
||||
@ -823,7 +823,7 @@ class KOBO(USBMS):
|
||||
# Reset Im_Reading list in the database
|
||||
if oncard == 'carda':
|
||||
query= "update content set ReadStatus=0, FirstTimeReading = 'true' where BookID is Null and ContentID like 'file:///mnt/sd/%'"
|
||||
elif oncard != 'carda' and oncard != 'cardb':
|
||||
elif oncard not in {'carda', 'cardb'}:
|
||||
query= "update content set ReadStatus=0, FirstTimeReading = 'true' where BookID is Null and ContentID not like 'file:///mnt/sd/%'"
|
||||
|
||||
try:
|
||||
@ -868,7 +868,7 @@ class KOBO(USBMS):
|
||||
# Reset FavouritesIndex list in the database
|
||||
if oncard == 'carda':
|
||||
query= "update content set FavouritesIndex=-1 where BookID is Null and ContentID like 'file:///mnt/sd/%'"
|
||||
elif oncard != 'carda' and oncard != 'cardb':
|
||||
elif oncard not in {'carda', 'cardb'}:
|
||||
query= "update content set FavouritesIndex=-1 where BookID is Null and ContentID not like 'file:///mnt/sd/%'"
|
||||
|
||||
cursor = connection.cursor()
|
||||
@ -1701,7 +1701,7 @@ class KOBOTOUCH(KOBO):
|
||||
self.report_progress(1.0, _('Getting list of books on device...'))
|
||||
debug_print("KoboTouch:books - Asked to process 'cardb', but do not have one!")
|
||||
return dummy_bl
|
||||
elif oncard and oncard != 'carda' and oncard != 'cardb':
|
||||
elif oncard and oncard not in {'carda', 'cardb'}:
|
||||
self.report_progress(1.0, _('Getting list of books on device...'))
|
||||
debug_print('KoboTouch:books - unknown card')
|
||||
return dummy_bl
|
||||
@ -1797,7 +1797,7 @@ class KOBOTOUCH(KOBO):
|
||||
allow_shelves = False
|
||||
if show_debug:
|
||||
debug_print('KoboTouch:update_booklist - have a deleted book')
|
||||
elif self.supports_kobo_archive() and (accessibility == 1 or accessibility == 2):
|
||||
elif self.supports_kobo_archive() and (accessibility in {1, 2}):
|
||||
playlist_map[lpath].append('Archived')
|
||||
allow_shelves = True
|
||||
|
||||
@ -2192,7 +2192,7 @@ class KOBOTOUCH(KOBO):
|
||||
|
||||
if oncard == 'cardb':
|
||||
print('path from_contentid cardb')
|
||||
elif (ContentType == '6' or ContentType == '10'):
|
||||
elif (ContentType in {'6', '10'}):
|
||||
if (MimeType == 'application/octet-stream'): # Audiobooks purchased from Kobo are in a different location.
|
||||
path = self._main_prefix + KOBO_ROOT_DIR_NAME + '/audiobook/' + path
|
||||
elif (MimeType == 'audio/mpeg' and self.isTolinoDevice()):
|
||||
@ -3305,7 +3305,7 @@ class KOBOTOUCH(KOBO):
|
||||
values.append(ContentID)
|
||||
elif oncard == 'carda':
|
||||
query += " WHERE ContentID like 'file:///mnt/sd/%'"
|
||||
elif oncard != 'carda' and oncard != 'cardb':
|
||||
elif oncard not in {'carda', 'cardb'}:
|
||||
query += " WHERE ContentID not like 'file:///mnt/sd/%'"
|
||||
|
||||
if bookshelves:
|
||||
|
||||
@ -362,7 +362,7 @@ class MTP_DEVICE(BASE):
|
||||
metadata = get_metadata(stream, stream_type=ext,
|
||||
force_read_metadata=True,
|
||||
pattern=self.build_template_regexp())
|
||||
if metadata.title != 'metadata' and metadata.title != 'Unknown':
|
||||
if metadata.title not in {'metadata', 'Unknown'}:
|
||||
return metadata
|
||||
stream = self.get_mtp_file(mtp_file)
|
||||
with quick_metadata:
|
||||
|
||||
@ -206,7 +206,7 @@ class USBMS(CLI, Device):
|
||||
elif oncard == 'cardb' and not self._card_b_prefix:
|
||||
self.report_progress(1.0, _('Getting list of books on device...'))
|
||||
return dummy_bl
|
||||
elif oncard and oncard != 'carda' and oncard != 'cardb':
|
||||
elif oncard and oncard not in {'carda', 'cardb'}:
|
||||
self.report_progress(1.0, _('Getting list of books on device...'))
|
||||
return dummy_bl
|
||||
|
||||
|
||||
@ -224,7 +224,7 @@ class Dehyphenator:
|
||||
searchresult = self.html.find(lookupword.lower())
|
||||
except Exception:
|
||||
return hyphenated
|
||||
if self.format == 'html_cleanup' or self.format == 'txt_cleanup':
|
||||
if self.format in {'html_cleanup', 'txt_cleanup'}:
|
||||
if self.html.find(lookupword) != -1 or searchresult != -1:
|
||||
if self.verbose > 2:
|
||||
self.log(' Cleanup:returned dehyphenated word: ' + dehyphenated)
|
||||
|
||||
@ -2,7 +2,7 @@ def _optimize(tagList, tagName, conversion):
|
||||
# copy the tag of interest plus any text
|
||||
newTagList = []
|
||||
for tag in tagList:
|
||||
if tag.name == tagName or tag.name == 'rawtext':
|
||||
if tag.name in (tagName, 'rawtext'):
|
||||
newTagList.append(tag)
|
||||
|
||||
# now, eliminate any duplicates (leaving the last one)
|
||||
|
||||
@ -194,7 +194,7 @@ class PackedIon(PackedData):
|
||||
if data_type == DT_STRING:
|
||||
return self.extract(data_len).decode('utf8')
|
||||
|
||||
if data_type == DT_STRUCT or data_type == DT_LIST:
|
||||
if data_type in (DT_STRUCT, DT_LIST):
|
||||
ion = PackedIon(self.extract(data_len))
|
||||
result = []
|
||||
|
||||
|
||||
@ -862,7 +862,7 @@ class MobiReader:
|
||||
l = self.mobi_html.find(b'<', end)
|
||||
r = self.mobi_html.find(b'>', end)
|
||||
anchor = b'<a id="filepos%d"></a>'
|
||||
if r > -1 and (r < l or l == end or l == -1):
|
||||
if r > -1 and (r < l or l in (end, -1)):
|
||||
p = self.mobi_html.rfind(b'<', 0, end + 1)
|
||||
if (pos < end and p > -1 and not end_tag_re.match(self.mobi_html[p:r]) and
|
||||
not self.mobi_html[p:r + 1].endswith(b'/>')):
|
||||
|
||||
@ -44,7 +44,7 @@ class Reader(FormatReader):
|
||||
def decompress_text(self, number):
|
||||
if self.header_record.compression == 1:
|
||||
return self.section_data(number)
|
||||
if self.header_record.compression == 2 or self.header_record.compression == 258:
|
||||
if self.header_record.compression in {2, 258}:
|
||||
from calibre.ebooks.compression.palmdoc import decompress_doc
|
||||
return decompress_doc(self.section_data(number))
|
||||
return b''
|
||||
|
||||
@ -124,7 +124,7 @@ def fix_fullscreen_images(container):
|
||||
svg = None
|
||||
for elem in body.iterdescendants('*'):
|
||||
name = local_name(elem.tag)
|
||||
if name != 'style' and name != 'script':
|
||||
if name not in {'style', 'script'}:
|
||||
names.append(name)
|
||||
if name == 'svg':
|
||||
svg = elem
|
||||
|
||||
@ -278,8 +278,7 @@ class Text(Element):
|
||||
if m_self and m_other:
|
||||
self.raw = m_self.group(1)
|
||||
other.raw = m_other.group(1)
|
||||
elif self.font_size_em != other.font_size_em \
|
||||
and self.font_size_em != 1.00:
|
||||
elif self.font_size_em not in (other.font_size_em, 1.0):
|
||||
if not self.raw.startswith(r'<span'):
|
||||
self.raw = f'<span style="font-size:{self.font_size_em!s}em">{self.raw}</span>'
|
||||
# Try to allow for a very large initial character
|
||||
@ -949,13 +948,7 @@ class Page:
|
||||
t.tag = 'h2' # It won't get set later
|
||||
# Centered if left and right margins are within FACTOR%
|
||||
# Because indents can waver a bit, use between indent_min and indent_max as == indent
|
||||
if (lmargin < indent_min or lmargin > indent_max) \
|
||||
and lmargin > left_max \
|
||||
and lmargin != xmargin \
|
||||
and lmargin != ymargin \
|
||||
and lmargin >= rmargin - rmargin*CENTER_FACTOR \
|
||||
and lmargin <= rmargin + rmargin*CENTER_FACTOR \
|
||||
and '"float:right"' not in t.raw:
|
||||
if (lmargin < indent_min or lmargin > indent_max) and lmargin > left_max and lmargin not in (xmargin, ymargin) and lmargin >= rmargin - rmargin * CENTER_FACTOR and lmargin <= rmargin + rmargin * CENTER_FACTOR and '"float:right"' not in t.raw:
|
||||
# and t.left + t.width + t.left >= self.width + l_offset - t.average_character_width \
|
||||
# and t.left + t.width + t.left <= self.width + l_offset + t.average_character_width:
|
||||
t.align = 'C'
|
||||
@ -1311,7 +1304,7 @@ class Page:
|
||||
# Font sizes start as pixels/points, but em is more useful
|
||||
for text in self.texts:
|
||||
text.font_size_em = self.font_map[text.font.id].size_em
|
||||
if text.font_size_em != 0.00 and text.font_size_em != 1.00:
|
||||
if text.font_size_em not in {0.0, 1.0}:
|
||||
text.raw = f'<span style="font-size:{text.font_size_em!s}em">{text.raw}</span>'
|
||||
|
||||
def second_pass(self, stats, opts):
|
||||
|
||||
@ -426,7 +426,7 @@ class PDFStream:
|
||||
if fmt == QImage.Format.Format_MonoLSB:
|
||||
image = image.convertToFormat(QImage.Format.Format_Mono)
|
||||
fmt = QImage.Format.Format_Mono
|
||||
elif (fmt != QImage.Format.Format_RGB32 and fmt != QImage.Format.Format_ARGB32):
|
||||
elif (fmt not in (QImage.Format.Format_RGB32, QImage.Format.Format_ARGB32)):
|
||||
image = image.convertToFormat(QImage.Format.Format_ARGB32)
|
||||
fmt = QImage.Format.Format_ARGB32
|
||||
|
||||
|
||||
@ -395,7 +395,7 @@ class Document:
|
||||
if counts['p'] and counts['img'] > counts['p']:
|
||||
reason = 'too many images ({})'.format(counts['img'])
|
||||
to_remove = True
|
||||
elif counts['li'] > counts['p'] and tag != 'ul' and tag != 'ol':
|
||||
elif counts['li'] > counts['p'] and tag not in {'ul', 'ol'}:
|
||||
reason = 'more <li>s than <p>s'
|
||||
to_remove = True
|
||||
elif counts['input'] > (counts['p'] / 3):
|
||||
|
||||
@ -115,7 +115,7 @@ class Configure:
|
||||
smart_output = return_dict.get('smart-output')
|
||||
if not smart_output:
|
||||
return_dict['smart-output'] = 0
|
||||
elif smart_output != 'true' and smart_output != 'false':
|
||||
elif smart_output not in {'true', 'false'}:
|
||||
sys.stderr.write('"smart-output" must be true or false.\n')
|
||||
return 1
|
||||
elif smart_output == 'false':
|
||||
@ -143,7 +143,7 @@ class Configure:
|
||||
value = return_dict.get(font)
|
||||
if not value:
|
||||
return_dict[font] = 0
|
||||
elif value != 'true' and value != 'false':
|
||||
elif value not in {'true', 'false'}:
|
||||
sys.stderr.write(
|
||||
f'"{font}" must be true or false.\n')
|
||||
elif value == 'false':
|
||||
|
||||
@ -353,7 +353,7 @@ file.
|
||||
else:
|
||||
toc_string += f'{line}\n'
|
||||
else:
|
||||
if token_info == 'cw<an<book-mk-st' or token_info =='cw<an<book-mk-en':
|
||||
if token_info in {'cw<an<book-mk-st', 'cw<an<book-mk-en'}:
|
||||
if token_info == 'cw<an<book-mk-st':
|
||||
book_type = 'start'
|
||||
if token_info == 'cw<an<book-mk-en':
|
||||
|
||||
@ -139,8 +139,7 @@ class Fonts:
|
||||
)
|
||||
elif self.__token_info == 'cw<ci<font-style':
|
||||
self.__font_num = line[20:-1]
|
||||
elif self.__token_info == 'tx<nu<__________' or \
|
||||
self.__token_info == 'tx<ut<__________':
|
||||
elif self.__token_info in {'tx<nu<__________', 'tx<ut<__________'}:
|
||||
self.__text_line += line[17:-1]
|
||||
elif self.__token_info == 'mi<mk<fonttb-end':
|
||||
self.__found_end_font_table_func()
|
||||
|
||||
@ -304,23 +304,23 @@ class GetOptions:
|
||||
else:
|
||||
options_dict['empty-paragraphs'] = 1
|
||||
form_lists = options_dict.get('lists')
|
||||
if form_lists == 'true' or form_lists == '1':
|
||||
if form_lists in {'true', '1'}:
|
||||
options_dict['form-lists'] = 1
|
||||
elif form_lists == 'false' or form_lists == '0':
|
||||
elif form_lists in {'false', '0'}:
|
||||
options_dict['form-lists'] = 0
|
||||
else:
|
||||
options_dict['form-lists'] = 0
|
||||
group_styles = options_dict.get('group-styles')
|
||||
if group_styles == 'true' or group_styles == '1':
|
||||
if group_styles in {'true', '1'}:
|
||||
options_dict['group-styles'] = 1
|
||||
elif group_styles == 'false' or group_styles == '0':
|
||||
elif group_styles in {'false', '0'}:
|
||||
options_dict['group-styles'] = 0
|
||||
else:
|
||||
options_dict['group-styles'] = 0
|
||||
group_borders = options_dict.get('group-borders')
|
||||
if group_borders == 'true' or group_borders == '1':
|
||||
if group_borders in {'true', '1'}:
|
||||
options_dict['group-borders'] = 1
|
||||
elif group_borders == 'false' or group_borders == '0':
|
||||
elif group_borders in {'false', '0'}:
|
||||
options_dict['group-borders'] = 0
|
||||
else:
|
||||
options_dict['group-borders'] = 0
|
||||
|
||||
@ -400,13 +400,7 @@ class Inline:
|
||||
for line in read_obj:
|
||||
token = line[0:-1]
|
||||
self.__token_info = ''
|
||||
if token == 'tx<mc<__________<rdblquote'\
|
||||
or token == 'tx<mc<__________<ldblquote'\
|
||||
or token == 'tx<mc<__________<lquote'\
|
||||
or token == 'tx<mc<__________<rquote'\
|
||||
or token == 'tx<mc<__________<emdash'\
|
||||
or token == 'tx<mc<__________<endash'\
|
||||
or token == 'tx<mc<__________<bullet':
|
||||
if token in {'tx<mc<__________<rdblquote', 'tx<mc<__________<ldblquote', 'tx<mc<__________<lquote', 'tx<mc<__________<rquote', 'tx<mc<__________<emdash', 'tx<mc<__________<endash', 'tx<mc<__________<bullet'}:
|
||||
self.__token_info = 'text'
|
||||
else:
|
||||
self.__token_info = line[:16]
|
||||
|
||||
@ -148,8 +148,7 @@ class PreambleDiv:
|
||||
'mi<mk<rtfhed-end\n'
|
||||
)
|
||||
self.__state = 'preamble'
|
||||
elif self.__token_info == 'tx<nu<__________' or \
|
||||
self.__token_info == 'cw<pf<par-def___':
|
||||
elif self.__token_info in {'tx<nu<__________', 'cw<pf<par-def___'}:
|
||||
self.__state = 'body'
|
||||
self.__rtf_final = (
|
||||
'mi<mk<rtfhed-beg\n' +
|
||||
|
||||
@ -699,7 +699,7 @@ class ProcessTokens:
|
||||
# return 'cw<cl<%s<nu<nu<%s>%s<%s\n' % (third_field, token, num, token)
|
||||
|
||||
def bool_st_func(self, pre, token, num):
|
||||
if num is None or num == '' or num == '1':
|
||||
if num is None or num in {'', '1'}:
|
||||
return f'cw<{pre}<{token}<nu<true\n'
|
||||
# return 'cw<nu<nu<nu<%s>true<%s\n' % (token, token)
|
||||
elif num == '0':
|
||||
|
||||
@ -543,7 +543,7 @@ class Styles:
|
||||
self.__styles_dict[type][key][style] = \
|
||||
changed_value
|
||||
else:
|
||||
if value == 0 or value == '0':
|
||||
if value in {0, '0'}:
|
||||
pass
|
||||
elif self.__run_level > 4:
|
||||
msg = f'{type} {key} is based on {value}\n'
|
||||
|
||||
@ -122,10 +122,7 @@ class Table:
|
||||
a row and start a cell.
|
||||
'''
|
||||
# 'cell' : ('tb', 'cell______', self.default_func),
|
||||
if self.__token_info == 'mi<mk<not-in-tbl' or\
|
||||
self.__token_info == 'mi<mk<sect-start' or\
|
||||
self.__token_info == 'mi<mk<sect-close' or\
|
||||
self.__token_info == 'mi<mk<body-close':
|
||||
if self.__token_info in {'mi<mk<not-in-tbl', 'mi<mk<sect-start', 'mi<mk<sect-close', 'mi<mk<body-close'}:
|
||||
self.__close_table(line)
|
||||
elif self.__token_info == 'mi<mk<pard-start':
|
||||
self.__start_row_func(line)
|
||||
@ -426,10 +423,7 @@ class Table:
|
||||
'''
|
||||
# cw<tb<cell______<nu<true
|
||||
# mi<mk<sect-start
|
||||
if self.__token_info == 'mi<mk<not-in-tbl' or\
|
||||
self.__token_info == 'mi<mk<sect-start' or\
|
||||
self.__token_info == 'mi<mk<sect-close' or\
|
||||
self.__token_info == 'mi<mk<body-close':
|
||||
if self.__token_info in {'mi<mk<not-in-tbl', 'mi<mk<sect-start', 'mi<mk<sect-close', 'mi<mk<body-close'}:
|
||||
self.__end_cell_func(line)
|
||||
self.__end_row_func(line)
|
||||
self.__close_table(line)
|
||||
@ -456,10 +450,7 @@ class Table:
|
||||
self.__write_obj.write('mi<mk<closecell_\n')
|
||||
|
||||
def __in_row_func(self, line):
|
||||
if self.__token_info == 'mi<mk<not-in-tbl' or\
|
||||
self.__token_info == 'mi<mk<sect-start' or\
|
||||
self.__token_info == 'mi<mk<sect-close' or\
|
||||
self.__token_info == 'mi<mk<body-close':
|
||||
if self.__token_info in {'mi<mk<not-in-tbl', 'mi<mk<sect-start', 'mi<mk<sect-close', 'mi<mk<body-close'}:
|
||||
self.__end_row_func(line)
|
||||
self.__close_table(line)
|
||||
self.__write_obj.write(line)
|
||||
|
||||
@ -359,7 +359,7 @@ class Textile:
|
||||
if m:
|
||||
rowspan = m.group(1)
|
||||
|
||||
if element == 'td' or element == 'tr':
|
||||
if element in {'td', 'tr'}:
|
||||
m = re.search(rf'({self.vlgn})', matched)
|
||||
if m:
|
||||
style.append(f'vertical-align:{self.vAlign(m.group(1))};')
|
||||
|
||||
@ -1637,7 +1637,7 @@ class BulkText(BulkBase):
|
||||
_('You have entered values. In order to use this '
|
||||
'editor you must first discard them. '
|
||||
'Discard the values?'))
|
||||
if d == QMessageBox.StandardButton.Cancel or d == QMessageBox.StandardButton.No:
|
||||
if d in (QMessageBox.StandardButton.Cancel, QMessageBox.StandardButton.No):
|
||||
return
|
||||
widget.setText('')
|
||||
d = TagEditor(self.parent, self.db, key=('#'+self.col_metadata['label']))
|
||||
|
||||
@ -94,9 +94,7 @@ class MyBlockingBusy(QDialog): # {{{
|
||||
args.do_swap_ta, args.do_title_case and not
|
||||
args.do_swap_ta, args.do_title_sort, bool(args.au),
|
||||
args.do_auto_author, bool(args.aus) and args.do_aus,
|
||||
args.cover_action == 'remove' or args.cover_action ==
|
||||
'generate' or args.cover_action == 'trim' or
|
||||
args.cover_action == 'clone', args.restore_original,
|
||||
args.cover_action in {'remove', 'generate', 'trim', 'clone'}, args.restore_original,
|
||||
args.rating != -1, args.clear_pub, bool(args.pub),
|
||||
args.clear_series, args.pubdate is not None, args.adddate
|
||||
is not None, args.do_series, bool(args.series) and
|
||||
|
||||
@ -140,7 +140,7 @@ class CodeEditor(QPlainTextEdit):
|
||||
ev.accept()
|
||||
return
|
||||
key = ev.key()
|
||||
if key == Qt.Key_Tab or key == Qt.Key_Backtab:
|
||||
if key in (Qt.Key_Tab, Qt.Key_Backtab):
|
||||
'''
|
||||
Handle indenting usingTab and Shift Tab. This is remarkably
|
||||
difficult because of the way Qt represents the edit buffer.
|
||||
|
||||
@ -1855,7 +1855,7 @@ class DeviceBooksModel(BooksModel): # {{{
|
||||
def data(self, index, role):
|
||||
row, col = index.row(), index.column()
|
||||
cname = self.column_map[col]
|
||||
if role == Qt.ItemDataRole.DisplayRole or role == Qt.ItemDataRole.EditRole:
|
||||
if role in (Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole):
|
||||
if cname == 'title':
|
||||
text = self.db[self.map[row]].title
|
||||
if not text:
|
||||
|
||||
@ -697,7 +697,7 @@ class CoversModel(QAbstractListModel): # {{{
|
||||
return None
|
||||
if role == Qt.ItemDataRole.DecorationRole:
|
||||
return pmap
|
||||
if role == Qt.ItemDataRole.DisplayRole or role == Qt.ItemDataRole.ToolTipRole:
|
||||
if role in (Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.ToolTipRole):
|
||||
return text
|
||||
if role == Qt.ItemDataRole.UserRole:
|
||||
return waiting
|
||||
|
||||
@ -820,7 +820,7 @@ class _Parser:
|
||||
if function_tuple and function_tuple[0](arguments):
|
||||
return function_tuple[1](line_number, arguments)
|
||||
# More complicated special cases
|
||||
if id_ == 'arguments' or id_ == 'globals' or id_ == 'set_globals':
|
||||
if id_ in {'arguments', 'globals', 'set_globals'}:
|
||||
new_args = []
|
||||
for arg_list in arguments:
|
||||
arg = arg_list[0]
|
||||
|
||||
@ -1443,7 +1443,7 @@ Python[/URL] documentation for more examples. Returns the empty string if format
|
||||
''')
|
||||
|
||||
def evaluate(self, formatter, kwargs, mi, locals, val, template):
|
||||
if val == '' or val == 'None':
|
||||
if val in {'', 'None'}:
|
||||
return ''
|
||||
if '{' not in template:
|
||||
template = '{0:' + template + '}'
|
||||
|
||||
@ -147,7 +147,7 @@ def jpeg_dimensions(stream):
|
||||
while marker == 0xff:
|
||||
marker = read_byte()
|
||||
q = marker
|
||||
if 0xc0 <= q <= 0xcf and q != 0xc4 and q != 0xcc:
|
||||
if 192 <= q <= 207 and q not in {196, 204}:
|
||||
# SOFn marker
|
||||
stream.seek(3, os.SEEK_CUR)
|
||||
return unpack(b'>HH', read(4))
|
||||
|
||||
@ -739,7 +739,7 @@ class SMTP:
|
||||
to_addrs = [to_addrs]
|
||||
for each in to_addrs:
|
||||
code, resp = self.rcpt(each, rcpt_options)
|
||||
if (code != 250) and (code != 251):
|
||||
if code not in {250, 251}:
|
||||
senderrs[each] = (code, resp)
|
||||
if len(senderrs) == len(to_addrs):
|
||||
# the server refused all our recipients
|
||||
|
||||
@ -115,7 +115,7 @@ def svg_path_to_painter_path(d):
|
||||
x += parse_float()
|
||||
y += parse_float()
|
||||
path.moveTo(x, y)
|
||||
elif cmd == closepath1 or cmd == closepath2:
|
||||
elif cmd in (closepath1, closepath2):
|
||||
path.closeSubpath()
|
||||
elif cmd == lineto_abs:
|
||||
x, y = parse_floats(2)
|
||||
@ -143,7 +143,7 @@ def svg_path_to_painter_path(d):
|
||||
x1, y1, x2, y2, x, y = parse_floats(6, x, y)
|
||||
path.cubicTo(x1, y1, x2, y2, x, y)
|
||||
elif cmd == smoothcurveto_abs:
|
||||
if last_cmd == curveto_abs or last_cmd == curveto_rel or last_cmd == smoothcurveto_abs or last_cmd == smoothcurveto_rel:
|
||||
if last_cmd in (curveto_abs, curveto_rel, smoothcurveto_abs, smoothcurveto_rel):
|
||||
x1 = 2 * x - x2
|
||||
y1 = 2 * y - y2
|
||||
else:
|
||||
@ -151,7 +151,7 @@ def svg_path_to_painter_path(d):
|
||||
x2, y2, x, y = parse_floats(4)
|
||||
path.cubicTo(x1, y1, x2, y2, x, y)
|
||||
elif cmd == smoothcurveto_rel:
|
||||
if last_cmd == curveto_abs or last_cmd == curveto_rel or last_cmd == smoothcurveto_abs or last_cmd == smoothcurveto_rel:
|
||||
if last_cmd in (curveto_abs, curveto_rel, smoothcurveto_abs, smoothcurveto_rel):
|
||||
x1 = 2 * x - x2
|
||||
y1 = 2 * y - y2
|
||||
else:
|
||||
|
||||
@ -1605,7 +1605,7 @@ dl.notes dd:last-of-type { page-break-after: avoid }
|
||||
for c in node.childNodes:
|
||||
self._walknode(c)
|
||||
self.endElementNS(node.qname, node.tagName)
|
||||
if node.nodeType == Node.TEXT_NODE or node.nodeType == Node.CDATA_SECTION_NODE:
|
||||
if node.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
|
||||
self.characters(str(node))
|
||||
|
||||
def odf2xhtml(self, odffile):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user