From b2c90ff4609855d1f0bc54cffff93edde01fc3a4 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:14:21 +0100 Subject: [PATCH] convert docstrings comments (extra-edit) --- src/calibre/devices/kindle/bookmark.py | 71 +++++++++---------- src/calibre/devices/misc.py | 58 ++++++++------- src/calibre/ebooks/lrf/pylrs/pylrs.py | 28 ++++---- src/calibre/ebooks/rtf2xml/colors.py | 42 ++++++----- src/calibre/ebooks/rtf2xml/fields_small.py | 5 +- src/calibre/ebooks/rtf2xml/get_options.py | 63 ++++++++-------- src/calibre/ebooks/rtf2xml/hex_2_utf8.py | 36 +++++----- src/calibre/ebooks/rtf2xml/inline.py | 16 ++--- src/calibre/ebooks/rtf2xml/list_numbers.py | 8 +-- src/calibre/ebooks/rtf2xml/list_table.py | 28 ++++---- src/calibre/ebooks/rtf2xml/options_trem.py | 6 +- src/calibre/ebooks/rtf2xml/paragraph_def.py | 15 ++-- src/calibre/ebooks/rtf2xml/pict.py | 8 +-- src/calibre/ebooks/rtf2xml/preamble_div.py | 16 ++--- src/calibre/ebooks/rtf2xml/process_tokens.py | 44 ++++++------ src/calibre/ebooks/rtf2xml/sections.py | 12 ++-- src/calibre/ebooks/rtf2xml/styles.py | 12 ++-- src/calibre/ebooks/rtf2xml/table.py | 18 +++-- src/calibre/library/catalogs/epub_mobi.py | 4 +- .../library/catalogs/epub_mobi_builder.py | 10 ++- 20 files changed, 225 insertions(+), 275 deletions(-) diff --git a/src/calibre/devices/kindle/bookmark.py b/src/calibre/devices/kindle/bookmark.py index 0a5ecf965e..3104ddc5cd 100644 --- a/src/calibre/devices/kindle/bookmark.py +++ b/src/calibre/devices/kindle/bookmark.py @@ -111,13 +111,11 @@ class Bookmark: # {{{ # Switch location to start (0x08:0x0c) start, = unpack('>I', data[eo+8:eo+12]) user_notes[start] = user_notes[end_loc] - ''' - print(" %s: swapping 0x%x (%d) to 0x%x (%d)" % (user_notes[end_loc]['type'], - end_loc, - end_loc/MAGIC_MOBI_CONSTANT + 1, - start, - start//MAGIC_MOBI_CONSTANT + 1)) - ''' + # print(" %s: swapping 0x%x (%d) to 0x%x (%d)" % (user_notes[end_loc]['type'], + # end_loc, + # end_loc/MAGIC_MOBI_CONSTANT + 1, + # start, + # start//MAGIC_MOBI_CONSTANT + 1)) user_notes[start]['displayed_location'] = start // MAGIC_MOBI_CONSTANT + 1 user_notes.pop(end_loc) else: @@ -225,37 +223,36 @@ class Bookmark: # {{{ e_base = 0x0d self.pdf_page_offset = 0 while current_entry < entries: - ''' - location, = unpack('>I', data[e_base+2:e_base+6]) - text = None - text_len, = unpack('>I', data[e_base+0xA:e_base+0xE]) - e_type, = unpack('>B', data[e_base+1]) - if e_type == 0: - e_type = 'Bookmark' - elif e_type == 1: - e_type = 'Highlight' - text = get_topaz_highlight(location/MAGIC_TOPAZ_CONSTANT + 1) - elif e_type == 2: - e_type = 'Note' - text = data[e_base+0x10:e_base+0x10+text_len] - else: - e_type = 'Unknown annotation type' + # location, = unpack('>I', data[e_base+2:e_base+6]) + # text = None + # text_len, = unpack('>I', data[e_base+0xA:e_base+0xE]) + # e_type, = unpack('>B', data[e_base+1]) + # if e_type == 0: + # e_type = 'Bookmark' + # elif e_type == 1: + # e_type = 'Highlight' + # text = get_topaz_highlight(location/MAGIC_TOPAZ_CONSTANT + 1) + # elif e_type == 2: + # e_type = 'Note' + # text = data[e_base+0x10:e_base+0x10+text_len] + # else: + # e_type = 'Unknown annotation type' + # + # if self.book_format in ['tpz','azw1']: + # displayed_location = location/MAGIC_TOPAZ_CONSTANT + 1 + # elif self.book_format == 'pdf': + # # *** This needs implementation + # displayed_location = location + # user_notes[location] = dict(id=self.id, + # displayed_location=displayed_location, + # type=e_type, + # text=text) + # if text_len == 0xFFFFFFFF: + # e_base = e_base + 14 + # else: + # e_base = e_base + 14 + 2 + text_len + # current_entry += 1 - if self.book_format in ['tpz','azw1']: - displayed_location = location/MAGIC_TOPAZ_CONSTANT + 1 - elif self.book_format == 'pdf': - # *** This needs implementation - displayed_location = location - user_notes[location] = dict(id=self.id, - displayed_location=displayed_location, - type=e_type, - text=text) - if text_len == 0xFFFFFFFF: - e_base = e_base + 14 - else: - e_base = e_base + 14 + 2 + text_len - current_entry += 1 - ''' # Use label as page number pdf_location, = unpack('>I', data[e_base+1:e_base+5]) label_len, = unpack('>H', data[e_base+5:e_base+7]) diff --git a/src/calibre/devices/misc.py b/src/calibre/devices/misc.py index 770cb39fc5..d02f89a69f 100644 --- a/src/calibre/devices/misc.py +++ b/src/calibre/devices/misc.py @@ -319,36 +319,34 @@ class NEXTBOOK(USBMS): SUPPORTS_SUB_DIRS = True THUMBNAIL_HEIGHT = 120 - ''' - def upload_cover(self, path, filename, metadata, filepath): - if metadata.thumbnail and metadata.thumbnail[-1]: - path = path.replace('/', os.sep) - is_main = path.startswith(self._main_prefix) - prefix = None - if is_main: - prefix = self._main_prefix - else: - if self._card_a_prefix and \ - path.startswith(self._card_a_prefix): - prefix = self._card_a_prefix - elif self._card_b_prefix and \ - path.startswith(self._card_b_prefix): - prefix = self._card_b_prefix - if prefix is None: - prints('WARNING: Failed to find prefix for:', filepath) - return - thumbnail_dir = os.path.join(prefix, '.Cover') - - relpath = os.path.relpath(filepath, prefix) - if relpath.startswith('..\\'): - relpath = relpath[3:] - thumbnail_dir = os.path.join(thumbnail_dir, relpath) - if not os.path.exists(thumbnail_dir): - os.makedirs(thumbnail_dir) - with open(os.path.join(thumbnail_dir, filename+'.jpg'), 'wb') as f: - f.write(metadata.thumbnail[-1]) - fsync(f) - ''' + # def upload_cover(self, path, filename, metadata, filepath): + # if metadata.thumbnail and metadata.thumbnail[-1]: + # path = path.replace('/', os.sep) + # is_main = path.startswith(self._main_prefix) + # prefix = None + # if is_main: + # prefix = self._main_prefix + # else: + # if self._card_a_prefix and \ + # path.startswith(self._card_a_prefix): + # prefix = self._card_a_prefix + # elif self._card_b_prefix and \ + # path.startswith(self._card_b_prefix): + # prefix = self._card_b_prefix + # if prefix is None: + # prints('WARNING: Failed to find prefix for:', filepath) + # return + # thumbnail_dir = os.path.join(prefix, '.Cover') + # + # relpath = os.path.relpath(filepath, prefix) + # if relpath.startswith('..\\'): + # relpath = relpath[3:] + # thumbnail_dir = os.path.join(thumbnail_dir, relpath) + # if not os.path.exists(thumbnail_dir): + # os.makedirs(thumbnail_dir) + # with open(os.path.join(thumbnail_dir, filename+'.jpg'), 'wb') as f: + # f.write(metadata.thumbnail[-1]) + # fsync(f) class MOOVYBOOK(USBMS): diff --git a/src/calibre/ebooks/lrf/pylrs/pylrs.py b/src/calibre/ebooks/lrf/pylrs/pylrs.py index 6d7aa0b14e..acce6e17b5 100644 --- a/src/calibre/ebooks/lrf/pylrs/pylrs.py +++ b/src/calibre/ebooks/lrf/pylrs/pylrs.py @@ -161,15 +161,13 @@ class Delegator: for m in methods: setattr(self, m, getattr(d, m)) - ''' - for setting in d.getSettings(): - if isinstance(setting, string_or_bytes): - setting = (d, setting) - delegates = \ - self.delegatedSettingsDict.setdefault(setting[1], []) - delegates.append(setting[0]) - self.delegatedSettings.append(setting) - ''' + # for setting in d.getSettings(): + # if isinstance(setting, string_or_bytes): + # setting = (d, setting) + # delegates = \ + # self.delegatedSettingsDict.setdefault(setting[1], []) + # delegates.append(setting[0]) + # self.delegatedSettings.append(setting) def applySetting(self, name, value, testValid=False): applied = False @@ -193,13 +191,11 @@ class Delegator: def applySettings(self, settings, testValid=False): for (setting, value) in settings.items(): self.applySetting(setting, value, testValid) - ''' - if setting not in self.delegatedSettingsDict: - raise LrsError("setting %s not valid" % setting) - delegates = self.delegatedSettingsDict[setting] - for d in delegates: - setattr(d, setting, value) - ''' + # if setting not in self.delegatedSettingsDict: + # raise LrsError("setting %s not valid" % setting) + # delegates = self.delegatedSettingsDict[setting] + # for d in delegates: + # setattr(d, setting, value) def appendDelegates(self, element, sourceEncoding): for d in self.delegates: diff --git a/src/calibre/ebooks/rtf2xml/colors.py b/src/calibre/ebooks/rtf2xml/colors.py index a310c35a82..b549fea4b7 100644 --- a/src/calibre/ebooks/rtf2xml/colors.py +++ b/src/calibre/ebooks/rtf2xml/colors.py @@ -166,28 +166,26 @@ class Colors: if the_index > -1: line = re.sub(self.__line_color_exp, self.__sub_from_line_color, line) self.__write_obj.write(line) - ''' - if num == 0: - hex_num = 'false' - else: - hex_num = self.__color_dict.get(num) - if hex_num == None: - if self.__run_level > 0: - sys.stderr.write( - 'module is colors.py\n' - 'function is self.__after_color_func\n' - 'no value in self.__color_dict for key %s\n' % num - ) - if self.__run_level > 3: - sys.stderr.write( - 'run level is %s\n' - 'Script will now quit\n' - % self.__run_level) - else: - self.__write_obj.write( - 'cw 0: + # sys.stderr.write( + # 'module is colors.py\n' + # 'function is self.__after_color_func\n' + # 'no value in self.__color_dict for key %s\n' % num + # ) + # if self.__run_level > 3: + # sys.stderr.write( + # 'run level is %s\n' + # 'Script will now quit\n' + # % self.__run_level) + # else: + # self.__write_obj.write( + # 'cw\'.\n' - 'in the configuration file.\n' - ) - return_options['valid'] = 0 - ''' + # sys.stderr.write( + # 'Please provide and file to output with the -o option.\n' + # 'Or set \'\'.\n' + # 'in the configuration file.\n' + # ) + # return_options['valid'] = 0 pass if 'indent' in the_keys: try: @@ -242,28 +237,26 @@ class GetOptions: sys.stderr.write('--indent must take an integer') return_options['valid'] = 0 # check for format and pyxml - ''' - the_format = return_options.get('format') - if the_format != 'raw': - no_pyxml = return_options.get('no-pyxml') - if no_pyxml: - sys.stderr.write('You want to convert your file to "%s".\n' - 'Sorry, but you must have pyxml installed\n' - 'in order to convert your document to anything but raw XML.\n' - 'Please do not use the --format option.\n\n' - % the_format - ) - return_options['valid'] = 0 - xslt_proc = return_options.get('xslt-processor') - if xslt_proc == None and not no_pyxml: - sys.stderr.write('You want to convert your file to "%s".\n' - 'Sorry, but you must have an xslt processor set up\n' - 'in order to conevert your document to anything but raw XML.\n' - 'Please use --format raw.\n\n' - % the_format - ) - return_options['valid'] = 0 - ''' + # the_format = return_options.get('format') + # if the_format != 'raw': + # no_pyxml = return_options.get('no-pyxml') + # if no_pyxml: + # sys.stderr.write('You want to convert your file to "%s".\n' + # 'Sorry, but you must have pyxml installed\n' + # 'in order to convert your document to anything but raw XML.\n' + # 'Please do not use the --format option.\n\n' + # % the_format + # ) + # return_options['valid'] = 0 + # xslt_proc = return_options.get('xslt-processor') + # if xslt_proc == None and not no_pyxml: + # sys.stderr.write('You want to convert your file to "%s".\n' + # 'Sorry, but you must have an xslt processor set up\n' + # 'in order to conevert your document to anything but raw XML.\n' + # 'Please use --format raw.\n\n' + # % the_format + # ) + # return_options['valid'] = 0 return return_options def __get_config_options(self): diff --git a/src/calibre/ebooks/rtf2xml/hex_2_utf8.py b/src/calibre/ebooks/rtf2xml/hex_2_utf8.py index 28416ac91d..40a47cb05d 100644 --- a/src/calibre/ebooks/rtf2xml/hex_2_utf8.py +++ b/src/calibre/ebooks/rtf2xml/hex_2_utf8.py @@ -568,22 +568,20 @@ class Hex2Utf8: self.__convert_body() -''' -how to swap case for non-capitals -my_string.swapcase() -An example of how to use a hash for the caps function -(but I shouldn't need this, since utf text is separate - from regular text?) -sub_dict = { - "а" : "some other value" - } -def my_sub_func(matchobj): - info = matchobj.group(0) - value = sub_dict.get(info) - return value - return "f" -line = "а more text" -reg_exp = re.compile(r'(?Pа|б)') -line2 = re.sub(reg_exp, my_sub_func, line) -print line2 -''' +# how to swap case for non-capitals +# my_string.swapcase() +# An example of how to use a hash for the caps function +# (but I shouldn't need this, since utf text is separate +# from regular text?) +# sub_dict = { +# "а" : "some other value" +# } +# def my_sub_func(matchobj): +# info = matchobj.group(0) +# value = sub_dict.get(info) +# return value +# return "f" +# line = "а more text" +# reg_exp = re.compile(r'(?Pа|б)') +# line2 = re.sub(reg_exp, my_sub_func, line) +# print line2 diff --git a/src/calibre/ebooks/rtf2xml/inline.py b/src/calibre/ebooks/rtf2xml/inline.py index b72a5d2c90..7a63e6f3b6 100644 --- a/src/calibre/ebooks/rtf2xml/inline.py +++ b/src/calibre/ebooks/rtf2xml/inline.py @@ -209,15 +209,13 @@ class Inline: if name: self.__inline_list[-1]['contains_inline'] = 1 self.__inline_list[-1][name] = char_value - ''' - if name == 'font-style': - if char_value == 'Symbol': - self.__write_obj.write('mi%s' % self.__att_val_dict['name']) self.__write_obj.write('%s' % self.__att_val_dict['style-num']) - tabs_list = ['tabs-left', 'tabs-right', 'tabs-decimal', 'tabs-center', - 'tabs-bar', 'tabs'] - ''' - for tab_item in tabs_list: - if self.__att_val_dict[tab_item] != '': - the_value = self.__att_val_dict[tab_item] - the_value = the_value[:-1] - self.__write_obj.write('<%s>%s' % (tab_item, the_value)) - ''' + tabs_list = ['tabs-left', 'tabs-right', 'tabs-decimal', 'tabs-center', 'tabs-bar', 'tabs'] + # for tab_item in tabs_list: + # if self.__att_val_dict[tab_item] != '': + # the_value = self.__att_val_dict[tab_item] + # the_value = the_value[:-1] + # self.__write_obj.write('<%s>%s' % (tab_item, the_value)) if self.__att_val_dict['tabs'] != '': the_value = self.__att_val_dict['tabs'] # the_value = the_value[:-1] diff --git a/src/calibre/ebooks/rtf2xml/pict.py b/src/calibre/ebooks/rtf2xml/pict.py index 0cc750b88c..104ddf55d3 100644 --- a/src/calibre/ebooks/rtf2xml/pict.py +++ b/src/calibre/ebooks/rtf2xml/pict.py @@ -115,11 +115,9 @@ class Pict: has not already been created.) Set the self.__in_pict flag to true. If the line does not contain pict data, return 1 ''' - ''' - $pict_count++; - $pict_count = sprintf("%03d", $pict_count); - print OUTPUT "dv$pict_count\n"; - ''' + # $pict_count++; + # $pict_count = sprintf("%03d", $pict_count); + # print OUTPUT "dv$pict_count\n"; if self.__token_info == 'cw%03d\n" % self.__pict_count) diff --git a/src/calibre/ebooks/rtf2xml/preamble_div.py b/src/calibre/ebooks/rtf2xml/preamble_div.py index 95534bf22d..bde0b04f91 100644 --- a/src/calibre/ebooks/rtf2xml/preamble_div.py +++ b/src/calibre/ebooks/rtf2xml/preamble_div.py @@ -191,15 +191,13 @@ class PreambleDiv: ''' If not font table is found, make a string for a default one ''' - ''' - self.__style_sheet_final = 'mi>> Use to debug generated catalog code before pipeline conversion <<< - ''' + # >>> Use to debug generated catalog code before pipeline conversion <<< GENERATE_DEBUG_EPUB = False if GENERATE_DEBUG_EPUB: catalog_debug_path = os.path.join(os.path.expanduser('~'), 'Desktop', 'Catalog debug') diff --git a/src/calibre/library/catalogs/epub_mobi_builder.py b/src/calibre/library/catalogs/epub_mobi_builder.py index 22031334a3..b6faad35e3 100644 --- a/src/calibre/library/catalogs/epub_mobi_builder.py +++ b/src/calibre/library/catalogs/epub_mobi_builder.py @@ -3072,12 +3072,10 @@ class CatalogBuilder: # Don't include Author for Kindle title_str = self.format_ncx_text('%s' % (book['title']), dest='title') if self.opts.connected_kindle and book['id'] in self.bookmarked_books: - ''' - dots = int((book['percent_read'] + 5)/10) - dot_string = '+' * dots - empty_dots = '-' * (10 - dots) - title_str += ' %s%s' % (dot_string,empty_dots) - ''' + # dots = int((book['percent_read'] + 5)/10) + # dot_string = '+' * dots + # empty_dots = '-' * (10 - dots) + # title_str += ' %s%s' % (dot_string,empty_dots) title_str += '*' sec_text = title_str else: