unnecessary collection call and some dict with keyword arguments (extra-edit)

This commit is contained in:
un-pogaz 2025-01-24 11:14:19 +01:00
parent bd59bf631e
commit 5d7c9a4cf3
13 changed files with 75 additions and 76 deletions

View File

@ -21,6 +21,6 @@ class ParisReview(BasicNewsRecipe):
# remove_attributes = ['style',] # remove_attributes = ['style',]
# keep_only_tags = [] # keep_only_tags = []
remove_tags = [] remove_tags = []
# remove_tags_before = dict() # remove_tags_before = {}
remove_tags_after = {} remove_tags_after = {}
feeds = [('Posts', 'http://feeds.feedburner.com/TheParisReviewBlog')] feeds = [('Posts', 'http://feeds.feedburner.com/TheParisReviewBlog')]

View File

@ -91,10 +91,10 @@ class Bookmark: # {{{
if entry_type: if entry_type:
displayed_location = location // MAGIC_MOBI_CONSTANT + 1 displayed_location = location // MAGIC_MOBI_CONSTANT + 1
user_notes[location] = dict(id=self.id, user_notes[location] = {'id': self.id,
displayed_location=displayed_location, 'displayed_location': displayed_location,
type=entry_type, 'type': entry_type,
text=text) 'text': text}
eo += rec_len + 8 eo += rec_len + 8
current_entry += 1 current_entry += 1
@ -127,10 +127,10 @@ class Bookmark: # {{{
if end_loc != self.last_read: if end_loc != self.last_read:
# print(' adding Bookmark at 0x%x (%d)' % (end_loc, end_loc/MAGIC_MOBI_CONSTANT + 1)) # print(' adding Bookmark at 0x%x (%d)' % (end_loc, end_loc/MAGIC_MOBI_CONSTANT + 1))
displayed_location = end_loc // MAGIC_MOBI_CONSTANT + 1 displayed_location = end_loc // MAGIC_MOBI_CONSTANT + 1
user_notes[end_loc - 1] = dict(id=self.id, user_notes[end_loc - 1] = {'id': self.id,
displayed_location=displayed_location, 'displayed_location': displayed_location,
type='Bookmark', 'type': 'Bookmark',
text=None) 'text': None}
rec_len, = unpack('>I', data[eo+4:eo+8]) rec_len, = unpack('>I', data[eo+4:eo+8])
eo += rec_len + 8 eo += rec_len + 8
sig = data[eo:eo+4] sig = data[eo:eo+4]
@ -200,10 +200,10 @@ class Bookmark: # {{{
e_type = 'Unknown annotation type' e_type = 'Unknown annotation type'
displayed_location = location/MAGIC_TOPAZ_CONSTANT + 1 displayed_location = location/MAGIC_TOPAZ_CONSTANT + 1
user_notes[location] = dict(id=self.id, user_notes[location] = {'id': self.id,
displayed_location=displayed_location, 'displayed_location': displayed_location,
type=e_type, 'type': e_type,
text=text) 'text': text}
if text_len == 0xFFFFFFFF: if text_len == 0xFFFFFFFF:
e_base = e_base + 14 e_base = e_base + 14
else: else:
@ -263,10 +263,10 @@ class Bookmark: # {{{
displayed_location = location displayed_location = location
e_type = 'Bookmark' e_type = 'Bookmark'
text = None text = None
user_notes[location] = dict(id=self.id, user_notes[location] = {'id': self.id,
displayed_location=displayed_location, 'displayed_location': displayed_location,
type=e_type, 'type': e_type,
text=text) 'text': text}
self.pdf_page_offset = pdf_location - location self.pdf_page_offset = pdf_location - location
e_base += (7 + label_len) e_base += (7 + label_len)
current_entry += 1 current_entry += 1

View File

@ -245,7 +245,7 @@ class KINDLE(USBMS):
if mc_path: if mc_path:
timestamp = utcfromtimestamp(os.path.getmtime(mc_path)) timestamp = utcfromtimestamp(os.path.getmtime(mc_path))
bookmarked_books['clippings'] = self.UserAnnotation(type='kindle_clippings', bookmarked_books['clippings'] = self.UserAnnotation(type='kindle_clippings',
value=dict(path=mc_path, timestamp=timestamp)) value={'path': mc_path, 'timestamp': timestamp})
# This returns as job.result in gui2.ui.annotations_fetched(self,job) # This returns as job.result in gui2.ui.annotations_fetched(self,job)
return bookmarked_books return bookmarked_books

View File

@ -126,14 +126,14 @@ class Bookmark: # {{{
# book_title = row[8] # book_title = row[8]
chapter_progress = min(round(float(100*row['ChapterProgress']),2),100) chapter_progress = min(round(float(100*row['ChapterProgress']),2),100)
user_notes[note_id] = dict(id=self.id, user_notes[note_id] = {'id': self.id,
displayed_location=note_id, 'displayed_location': note_id,
type=e_type, 'type': e_type,
text=text, 'text': text,
annotation=annotation, 'annotation': annotation,
chapter=current_chapter, 'chapter': current_chapter,
chapter_title=chapter_title, 'chapter_title': chapter_title,
chapter_progress=chapter_progress) 'chapter_progress': chapter_progress}
previous_chapter = current_chapter previous_chapter = current_chapter
# debug_print("e_type:" , e_type, '\t', 'loc: ', note_id, 'text: ', text, # debug_print("e_type:" , e_type, '\t', 'loc: ', note_id, 'text: ', text,
# 'annotation: ', annotation, 'chapter_title: ', chapter_title, # 'annotation: ', annotation, 'chapter_title: ', chapter_title,

View File

@ -267,8 +267,7 @@ TAG_INFO = dict(
setemptyview=(0xF52A, {'show':1, 'empty':0}, writeWord), setemptyview=(0xF52A, {'show':1, 'empty':0}, writeWord),
pageposition=(0xF52B, {'any':0,'upper':1, 'lower':2}, writeWord), pageposition=(0xF52B, {'any':0,'upper':1, 'lower':2}, writeWord),
evensidemargin=(0xF52C, writeWord), evensidemargin=(0xF52C, writeWord),
framemode=(0xF52E, framemode=(0xF52E, {'None':0, 'curve':2, 'square':1}, writeWord),
{'None':0, 'curve':2, 'square':1}, writeWord),
blockwidth=(0xF531, writeWord), blockwidth=(0xF531, writeWord),
blockheight=(0xF532, writeWord), blockheight=(0xF532, writeWord),
blockrule=(0xF533, {'horz-fixed':0x14, 'horz-adjustable':0x12, blockrule=(0xF533, {'horz-fixed':0x14, 'horz-adjustable':0x12,

View File

@ -238,8 +238,8 @@ class MetadataUpdater:
offset += consumed offset += consumed
len_comp, consumed = self.decode_vwi(self.data[offset:offset+4]) len_comp, consumed = self.decode_vwi(self.data[offset:offset+4])
offset += consumed offset += consumed
blocks[val] = dict(offset=hdr_offset,len_uncomp=len_uncomp,len_comp=len_comp) blocks[val] = {'offset': hdr_offset,'len_uncomp': len_uncomp,'len_comp': len_comp}
topaz_headers[tag] = dict(blocks=blocks) topaz_headers[tag] = {'blocks': blocks}
th_seq.append(tag) th_seq.append(tag)
self.eoth = self.data[offset] self.eoth = self.data[offset]
offset += 1 offset += 1

View File

@ -332,23 +332,24 @@ def render_jacket(mi, output_profile,
def generate_html(comments): def generate_html(comments):
display = Attributes() display = Attributes()
args = dict(xmlns=XHTML_NS, args = {
title_str=title_str, 'xmlns': XHTML_NS,
identifiers=Identifiers(mi.identifiers), 'title_str': title_str,
css=css, 'identifiers': Identifiers(mi.identifiers),
title=title, 'css': css,
author=author, 'title': title,
publisher=publisher, publisher_label=_('Publisher'), 'author': author,
pubdate_label=_('Published'), pubdate=Timestamp(pubdate, tweaks['gui_pubdate_display_format']), 'publisher': publisher, 'publisher_label': _('Publisher'),
series_label=ngettext('Series', 'Series', 1), series=series, 'pubdate_label': _('Published'), 'pubdate': Timestamp(pubdate, tweaks['gui_pubdate_display_format']),
rating_label=_('Rating'), rating=rating, 'series_label': ngettext('Series', 'Series', 1), 'series': series,
tags_label=_('Tags'), tags=tags, 'rating_label': _('Rating'), 'rating': rating,
timestamp=Timestamp(timestamp, tweaks['gui_timestamp_display_format']), timestamp_label=_('Date'), 'tags_label': _('Tags'), 'tags': tags,
comments=comments, 'timestamp': Timestamp(timestamp, tweaks['gui_timestamp_display_format']), 'timestamp_label': _('Date'),
footer='', 'comments': comments,
display=display, 'footer': '',
searchable_tags=' '.join(escape(t)+'ttt' for t in tags.tags_list), 'display': display,
) 'searchable_tags': ' '.join(escape(t)+'ttt' for t in tags.tags_list),
}
for key in mi.custom_field_keys(): for key in mi.custom_field_keys():
m = mi.get_user_metadata(key, False) or {} m = mi.get_user_metadata(key, False) or {}
try: try:

View File

@ -102,7 +102,7 @@ class FetchAnnotationsAction(InterfaceAction):
path = get_device_path_from_id(id) path = get_device_path_from_id(id)
mi = db.get_metadata(id, index_is_id=True) mi = db.get_metadata(id, index_is_id=True)
a_path = device.create_annotations_path(mi, device_path=path) a_path = device.create_annotations_path(mi, device_path=path)
path_map[id] = dict(path=a_path, fmts=get_formats(id)) path_map[id] = {'path': a_path, 'fmts': get_formats(id)}
return path_map return path_map
device = self.gui.device_manager.device device = self.gui.device_manager.device

View File

@ -1168,7 +1168,7 @@ class CatalogBuilder:
authors=book['authors']) authors=book['authors'])
myMeta.author_sort = book['author_sort'] myMeta.author_sort = book['author_sort']
a_path = d.create_upload_path('/<storage>', myMeta, 'x.bookmark', create_dirs=False) a_path = d.create_upload_path('/<storage>', myMeta, 'x.bookmark', create_dirs=False)
path_map[id] = dict(path=a_path, fmts=[x.rpartition('.')[2] for x in book['formats']]) path_map[id] = {'path': a_path, 'fmts': [x.rpartition('.')[2] for x in book['formats']]}
path_map, book_ext = _resolve_bookmark_paths(self.opts.connected_device['storage'], path_map) path_map, book_ext = _resolve_bookmark_paths(self.opts.connected_device['storage'], path_map)
if path_map: if path_map:

View File

@ -29,26 +29,26 @@ plugboard_save_to_disk_value = 'save_to_disk'
DEFAULT_TEMPLATE = '{author_sort}/{title}/{title} - {authors}' DEFAULT_TEMPLATE = '{author_sort}/{title}/{title} - {authors}'
DEFAULT_SEND_TEMPLATE = '{author_sort}/{title} - {authors}' DEFAULT_SEND_TEMPLATE = '{author_sort}/{title} - {authors}'
FORMAT_ARG_DESCS = dict( FORMAT_ARG_DESCS = {
title=_('The title'), 'title': _('The title'),
authors=_('The authors'), 'authors': _('The authors'),
author_sort=_('The author sort string. To use only the first letter ' 'author_sort': _('The author sort string. To use only the first letter '
'of the name use {author_sort[0]}'), 'of the name use {author_sort[0]}'),
tags=_('The tags'), 'tags': _('The tags'),
series=_('The series'), 'series': _('The series'),
series_index=_('The series number. ' 'series_index': _('The series number. '
'To get leading zeros use {series_index:0>3s} or ' 'To get leading zeros use {series_index:0>3s} or '
'{series_index:>3s} for leading spaces'), '{series_index:>3s} for leading spaces'),
rating=_('The rating'), 'rating': _('The rating'),
isbn=_('The ISBN'), 'isbn': _('The ISBN'),
publisher=_('The publisher'), 'publisher': _('The publisher'),
timestamp=_('The date'), 'timestamp': _('The date'),
pubdate=_('The published date'), 'pubdate': _('The published date'),
last_modified=_('The date when the metadata for this book record' 'last_modified': _('The date when the metadata for this book record'
' was last modified'), ' was last modified'),
languages=_('The language(s) of this book'), 'languages': _('The language(s) of this book'),
id=_('The calibre internal id') 'id': _('The calibre internal id')
) }
FORMAT_ARGS = {} FORMAT_ARGS = {}
for x in FORMAT_ARG_DESCS: for x in FORMAT_ARG_DESCS:

View File

@ -72,11 +72,11 @@ def get_wordcount(text):
non_asian_words = nonj_len(text) non_asian_words = nonj_len(text)
words = non_asian_words + asian_chars words = non_asian_words + asian_chars
return dict(characters=characters, return {'characters': characters,
chars_no_spaces=chars_no_spaces, 'chars_no_spaces': chars_no_spaces,
asian_chars=asian_chars, 'asian_chars': asian_chars,
non_asian_words=non_asian_words, 'non_asian_words': non_asian_words,
words=words) 'words': words}
def dict2obj(dictionary): def dict2obj(dictionary):

View File

@ -38,8 +38,7 @@ from polyglot.builtins import string_or_bytes
def classes(classes): def classes(classes):
q = frozenset(classes.split(' ')) q = frozenset(classes.split(' '))
return dict(attrs={ return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)})
'class': lambda x: x and frozenset(x.split()).intersection(q)})
def prefixed_classes(classes): def prefixed_classes(classes):