From b5aca6ff5c59cede6050a4894b9ac7c37e8e12e9 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:14:15 +0100 Subject: [PATCH] uniform string quote (extra-edit) --- recipes/alternatives_economiques.recipe | 2 +- recipes/fokus.recipe | 16 ++-- recipes/ieee_spectrum_mag.recipe | 2 +- recipes/le_canard_enchaine.recipe | 2 +- recipes/readitlater.recipe | 8 +- recipes/vic_times.recipe | 2 +- setup/build.py | 4 +- src/calibre/devices/interface.py | 12 +-- .../generators/fast_page_generator.py | 4 +- src/calibre/devices/kindle/bookmark.py | 8 +- src/calibre/devices/kobo/driver.py | 52 +++++------ src/calibre/ebooks/chm/reader.py | 2 +- .../ebooks/conversion/plugins/chm_input.py | 6 +- src/calibre/ebooks/conversion/preprocess.py | 16 ++-- src/calibre/ebooks/conversion/utils.py | 22 ++--- src/calibre/ebooks/hyphenate.py | 4 +- src/calibre/ebooks/lit/mssha1.py | 4 +- src/calibre/ebooks/lrf/meta.py | 4 +- src/calibre/ebooks/lrf/pylrs/pylrf.py | 4 +- src/calibre/ebooks/lrf/pylrs/pylrs.py | 12 +-- src/calibre/ebooks/metadata/topaz.py | 2 +- src/calibre/ebooks/oeb/base.py | 38 ++++---- src/calibre/ebooks/readability/readability.py | 6 +- src/calibre/ebooks/rtf2xml/ParseRtf.py | 8 +- src/calibre/ebooks/rtf2xml/add_brackets.py | 4 +- src/calibre/ebooks/rtf2xml/body_styles.py | 4 +- src/calibre/ebooks/rtf2xml/colors.py | 12 +-- src/calibre/ebooks/rtf2xml/convert_to_tags.py | 14 +-- src/calibre/ebooks/rtf2xml/delete_info.py | 4 +- src/calibre/ebooks/rtf2xml/field_strings.py | 8 +- src/calibre/ebooks/rtf2xml/fields_large.py | 16 ++-- src/calibre/ebooks/rtf2xml/fields_small.py | 20 ++--- src/calibre/ebooks/rtf2xml/fonts.py | 14 +-- src/calibre/ebooks/rtf2xml/footnote.py | 4 +- src/calibre/ebooks/rtf2xml/get_char_map.py | 9 +- src/calibre/ebooks/rtf2xml/group_borders.py | 14 +-- src/calibre/ebooks/rtf2xml/group_styles.py | 14 +-- src/calibre/ebooks/rtf2xml/header.py | 4 +- .../ebooks/rtf2xml/headings_to_sections.py | 6 +- src/calibre/ebooks/rtf2xml/hex_2_utf8.py | 12 +-- src/calibre/ebooks/rtf2xml/info.py | 4 +- src/calibre/ebooks/rtf2xml/inline.py | 20 ++--- src/calibre/ebooks/rtf2xml/list_numbers.py | 14 +-- src/calibre/ebooks/rtf2xml/list_table.py | 4 +- src/calibre/ebooks/rtf2xml/make_lists.py | 14 +-- src/calibre/ebooks/rtf2xml/old_rtf.py | 4 +- src/calibre/ebooks/rtf2xml/options_trem.py | 8 +- src/calibre/ebooks/rtf2xml/output.py | 4 +- src/calibre/ebooks/rtf2xml/paragraph_def.py | 32 +++---- src/calibre/ebooks/rtf2xml/paragraphs.py | 16 ++-- src/calibre/ebooks/rtf2xml/preamble_div.py | 4 +- src/calibre/ebooks/rtf2xml/preamble_rest.py | 4 +- src/calibre/ebooks/rtf2xml/sections.py | 12 +-- src/calibre/ebooks/rtf2xml/styles.py | 26 +++--- src/calibre/ebooks/rtf2xml/table.py | 40 ++++----- src/calibre/ebooks/rtf2xml/table_info.py | 4 +- src/calibre/ebooks/textile/functions.py | 64 ++++++------- .../gui2/markdown_syntax_highlighter.py | 2 +- .../gui2/preferences/create_custom_column.py | 12 +-- .../library/catalogs/epub_mobi_builder.py | 52 +++++------ src/calibre/srv/http_request.py | 4 +- src/calibre/utils/bibtex.py | 4 +- src/calibre/utils/ffml_processor.py | 8 +- src/calibre/utils/imghdr.py | 2 +- src/calibre/utils/smartypants.py | 36 ++++---- src/calibre/utils/smtplib.py | 90 +++++++++---------- src/calibre/utils/threadpool.py | 8 +- src/calibre/utils/titlecase.py | 4 +- src/calibre/utils/wordcount.py | 4 +- src/calibre/utils/zipfile.py | 24 ++--- src/calibre/web/feeds/templates.py | 4 +- src/odf/attrconverters.py | 4 +- src/odf/element.py | 8 +- src/odf/namespaces.py | 2 +- src/odf/odf2moinmoin.py | 2 +- src/odf/odf2xhtml.py | 52 +++++------ src/odf/opendocument.py | 24 ++--- src/odf/teletype.py | 8 +- src/qt/__main__.py | 2 +- 79 files changed, 512 insertions(+), 517 deletions(-) diff --git a/recipes/alternatives_economiques.recipe b/recipes/alternatives_economiques.recipe index d341bfc683..e13e57cc92 100644 --- a/recipes/alternatives_economiques.recipe +++ b/recipes/alternatives_economiques.recipe @@ -21,7 +21,7 @@ class AlternativesEconomiques(BasicNewsRecipe): remove_images = False def get_cover_url(self): - """Récupère dynamiquement l'URL de la dernière une depuis MLP""" + '''Récupère dynamiquement l'URL de la dernière une depuis MLP''' br = self.get_browser() try: # Accéder à la page du magazine sur MLP diff --git a/recipes/fokus.recipe b/recipes/fokus.recipe index 2bcb22ba19..206e9750dc 100644 --- a/recipes/fokus.recipe +++ b/recipes/fokus.recipe @@ -74,7 +74,7 @@ class Fokus(BasicNewsRecipe): return br def get_web_sections(self, main_url: str) -> dict[str, str]: - """Return a dict of (1) section URL and (2) section name key-value pairs found at `main_url`. + '''Return a dict of (1) section URL and (2) section name key-value pairs found at `main_url`. For example, if the Fokus website currently includes an 'Aktuellt' section, the dict should include an entry on the form: `{'https://www.fokus.se/aktuellt': 'Aktuellt'}`. @@ -84,7 +84,7 @@ class Fokus(BasicNewsRecipe): Yields: dict[str, str]: (1) URLs and (2) human-readable names of Fokus sections. - """ + ''' self.log(f"Identifying all sections under '{main_url}'...") soup = self.index_to_soup(main_url) @@ -110,14 +110,14 @@ class Fokus(BasicNewsRecipe): return section_urls_and_names def parse_article_blurb(self, article_blurb) -> dict[str, str, str, str] | None: - """Given a
tag of class 'Blurb', parse it into a dict. + '''Given a
tag of class 'Blurb', parse it into a dict. Args: article_blurb (Tag): An
tag hosting metadata and the URL of an article. Returns: dict[str, str, str, str]: A dict on a `{'url': str, 'title': str, 'description': str, 'date': str}` format. - """ + ''' if a_tag := article_blurb.find('a', href=True): url = a_tag['href'].strip().rstrip('/') if url.startswith('/'): @@ -147,7 +147,7 @@ class Fokus(BasicNewsRecipe): return def _get_article_blurbs(self, soup) -> dict[str, dict[str, str, str, str]]: - """Given a Fokus webpage `soup`, return a dict of unique article entries found on the page. + '''Given a Fokus webpage `soup`, return a dict of unique article entries found on the page. The key of a given entry in the output dictionary is the article URL. The corresponding value is a dictionary on a `{'url': str, 'title': str, 'description': str, 'date': str}` format. @@ -157,7 +157,7 @@ class Fokus(BasicNewsRecipe): Returns: dict[str, dict[str, str, str, str]]: A dict with article URLs as keys and 'article dicts' as values. - """ + ''' def _log(article) -> None: '''Log a digestible summary of the input `article` blurb.''' @@ -187,7 +187,7 @@ class Fokus(BasicNewsRecipe): return parsed_blurbs def get_article_blurbs(self, sections: dict[str, str]) -> dict[str, dict[str, str, str, str]]: - """Create and return a dict of all unique article blurbs found in all `sections`. + '''Create and return a dict of all unique article blurbs found in all `sections`. The key of a given entry in the output dictionary is the article URL. The corresponding value is a dictionary on a `{'url': str, 'title': str, 'description': str, 'date': str}` format. @@ -197,7 +197,7 @@ class Fokus(BasicNewsRecipe): Returns: dict[str, dict[str, str, str, str]]: A dict with article URLs as keys and 'article dicts' as values. - """ + ''' self.log(f'Identifying all articles under all {len(sections)} sections...') article_blurbs = {} diff --git a/recipes/ieee_spectrum_mag.recipe b/recipes/ieee_spectrum_mag.recipe index 9575beb77e..f0a590f0fb 100644 --- a/recipes/ieee_spectrum_mag.recipe +++ b/recipes/ieee_spectrum_mag.recipe @@ -27,7 +27,7 @@ class IEEESpectrumMagazine(BasicNewsRecipe): ] def get_cover_url(self): - """Go to this month's URL and pull cover image from there.""" + '''Go to this month's URL and pull cover image from there.''' month_url = 'https://spectrum.ieee.org/magazine/{}'.format(self.year_month) soup = self.index_to_soup(month_url) img_meta = soup.find('meta', property='og:image') diff --git a/recipes/le_canard_enchaine.recipe b/recipes/le_canard_enchaine.recipe index a4ecd4862d..10a8aaf0fa 100644 --- a/recipes/le_canard_enchaine.recipe +++ b/recipes/le_canard_enchaine.recipe @@ -48,7 +48,7 @@ class LeCanardEnchaine(BasicNewsRecipe): ''' def get_cover_url(self): - """Récupère dynamiquement l'URL de la dernière une""" + '''Récupère dynamiquement l'URL de la dernière une''' br = self.get_browser() try: soup = self.index_to_soup(br.open('https://boutique.lecanardenchaine.fr/acheter-au-numero/').read()) diff --git a/recipes/readitlater.recipe b/recipes/readitlater.recipe index 5a45b93596..475611ea77 100644 --- a/recipes/readitlater.recipe +++ b/recipes/readitlater.recipe @@ -53,11 +53,11 @@ class Pocket(BasicNewsRecipe): articles = [] def get_browser(self, *args, **kwargs): - """ + ''' We need to pretend to be a recent version of safari for the mac to prevent User-Agent checks Pocket api requires username and password so fail loudly if it's missing from the config. - """ + ''' br = BasicNewsRecipe.get_browser(self, user_agent='Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; \ en-us) AppleWebKit/533.19.4 (KHTML, like Gecko) \ @@ -151,10 +151,10 @@ class Pocket(BasicNewsRecipe): pass def default_cover(self, cover_file): - """ + ''' Create a generic cover for recipes that don't have a cover This override adds time to the cover - """ + ''' try: from calibre.ebooks.covers import calibre_cover2 title = self.title if isinstance(self.title, type(u'')) else \ diff --git a/recipes/vic_times.recipe b/recipes/vic_times.recipe index 034724e7b6..dcadbe8c18 100644 --- a/recipes/vic_times.recipe +++ b/recipes/vic_times.recipe @@ -206,7 +206,7 @@ class TimesColonist(BasicNewsRecipe): if atag is not None: url = atag['href'] url = url.strip() - # print("Checking >>"+url+'<<\n\r') + # print('Checking >>'+url+'<<\n\r') if url.startswith('/'): url = self.url_prefix + url if url in self.url_list: diff --git a/setup/build.py b/setup/build.py index d5599db17c..868c419de8 100644 --- a/setup/build.py +++ b/setup/build.py @@ -608,12 +608,12 @@ class Build(Command): os.remove(x) def check_call(self, *args, **kwargs): - """print cmdline if an error occurred + '''print cmdline if an error occurred If something is missing (cmake e.g.) you get a non-informative error self.check_call(qmc + [ext.name+'.pro']) so you would have to look at the source to see the actual command. - """ + ''' try: subprocess.check_call(*args, **kwargs) except: diff --git a/src/calibre/devices/interface.py b/src/calibre/devices/interface.py index be3dc32676..a4b4efb700 100644 --- a/src/calibre/devices/interface.py +++ b/src/calibre/devices/interface.py @@ -359,7 +359,7 @@ class DevicePlugin(Plugin): raise NotImplementedError() def total_space(self, end_session=True): - """ + ''' Get total space available on the mountpoints: 1. Main memory 2. Memory Card A @@ -368,11 +368,11 @@ class DevicePlugin(Plugin): :return: A 3 element list with total space in bytes of (1, 2, 3). If a particular device doesn't have any of these locations it should return 0. - """ + ''' raise NotImplementedError() def free_space(self, end_session=True): - """ + ''' Get free space available on the mountpoints: 1. Main memory 2. Card A @@ -381,11 +381,11 @@ class DevicePlugin(Plugin): :return: A 3 element list with free space in bytes of (1, 2, 3). If a particular device doesn't have any of these locations it should return -1. - """ + ''' raise NotImplementedError() def books(self, oncard=None, end_session=True): - """ + ''' Return a list of e-books on the device. :param oncard: If 'carda' or 'cardb' return a list of e-books on the @@ -395,7 +395,7 @@ class DevicePlugin(Plugin): :return: A BookList. - """ + ''' raise NotImplementedError() def upload_books(self, files, names, on_card=None, end_session=True, diff --git a/src/calibre/devices/kindle/apnx_page_generator/generators/fast_page_generator.py b/src/calibre/devices/kindle/apnx_page_generator/generators/fast_page_generator.py index 9027f4d1bf..e759a14477 100644 --- a/src/calibre/devices/kindle/apnx_page_generator/generators/fast_page_generator.py +++ b/src/calibre/devices/kindle/apnx_page_generator/generators/fast_page_generator.py @@ -16,7 +16,7 @@ class FastPageGenerator(IPageGenerator): raise Exception('Fast calculation impossible.') def _generate(self, mobi_file_path: str, real_count: int | None) -> Pages: - """ + ''' 2300 characters of uncompressed text per page. This is not meant to map 1 to 1 to a print book but to be a close enough measure. @@ -30,7 +30,7 @@ class FastPageGenerator(IPageGenerator): accessible in MOBI files (part of the header). Also, It's faster to work off of the length then to decompress and parse the actual text. - """ + ''' pages = [] count = 0 diff --git a/src/calibre/devices/kindle/bookmark.py b/src/calibre/devices/kindle/bookmark.py index 61e8671f01..52968c0446 100644 --- a/src/calibre/devices/kindle/bookmark.py +++ b/src/calibre/devices/kindle/bookmark.py @@ -61,11 +61,11 @@ class Bookmark(): # {{{ bpl = bpar_offset + 4 bpar_len, = unpack('>I', data[bpl:bpl+4]) bpar_len += 8 - # print "bpar_len: 0x%x" % bpar_len + # print 'bpar_len: 0x%x' % bpar_len eo = bpar_offset + bpar_len # Walk bookmark entries - # print " --- %s --- " % self.path + # print ' --- %s --- ' % self.path current_entry = 1 sig = data[eo:eo+4] previous_block = None @@ -80,7 +80,7 @@ class Bookmark(): # {{{ current_block = 'data_header' # entry_type = "data_header" location, = unpack('>I', data[eo+0x34:eo+0x38]) - # print "data_header location: %d" % location + # print 'data_header location: %d' % location else: current_block = 'text_block' if previous_block == 'empty_data': @@ -125,7 +125,7 @@ class Bookmark(): # {{{ # be the same - cheat by nudging -1 # Skip bookmark for last_read_location 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 user_notes[end_loc - 1] = dict(id=self.id, displayed_location=displayed_location, diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 44fdde439e..fdfa3ea679 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -321,7 +321,7 @@ class KOBO(USBMS): playlist_map[lpath].append('Recommendation') path = self.normalize_path(path) - # print "Normalized FileName: " + path + # print 'Normalized FileName: ' + path idx = bl_cache.get(lpath, None) if idx is not None: @@ -332,7 +332,7 @@ class KOBO(USBMS): # Try the Touch version if the image does not exist imagename = self.normalize_path(self._main_prefix + KOBO_ROOT_DIR_NAME + '/images/' + ImageID + ' - N3_LIBRARY_FULL.parsed') - # print "Image name Normalized: " + imagename + # print 'Image name Normalized: ' + imagename if not os.path.exists(imagename): debug_print('Strange - The image name does not exist - title: ', title) if imagename is not None: @@ -452,7 +452,7 @@ class KOBO(USBMS): need_sync = True del bl[idx] - # print "count found in cache: %d, count of files in metadata: %d, need_sync: %s" % \ + # print 'count found in cache: %d, count of files in metadata: %d, need_sync: %s' % \ # (len(bl_cache), len(bl), need_sync) if need_sync: # self.count_found_in_bl != len(bl) or need_sync: if oncard == 'cardb': @@ -561,33 +561,33 @@ class KOBO(USBMS): for i, path in enumerate(paths): self.report_progress((i+1) / float(len(paths)), _('Removing books from device...')) path = self.normalize_path(path) - # print "Delete file normalized path: " + path + # print 'Delete file normalized path: ' + path extension = os.path.splitext(path)[1] ContentType = self.get_content_type_from_extension(extension) if extension else self.get_content_type_from_path(path) ContentID = self.contentid_from_path(path, ContentType) ImageID = self.delete_via_sql(ContentID, ContentType) - # print " We would now delete the Images for" + ImageID + # print ' We would now delete the Images for' + ImageID self.delete_images(ImageID, path) if os.path.exists(path): # Delete the ebook - # print "Delete the ebook: " + path + # print 'Delete the ebook: ' + path os.unlink(path) filepath = os.path.splitext(path)[0] for ext in self.DELETE_EXTS: if os.path.exists(filepath + ext): - # print "Filename: " + filename + # print 'Filename: ' + filename os.unlink(filepath + ext) if os.path.exists(path + ext): - # print "Filename: " + filename + # print 'Filename: ' + filename os.unlink(path + ext) if self.SUPPORTS_SUB_DIRS: try: - # print "removed" + # print 'removed' os.removedirs(os.path.dirname(path)) except Exception: pass @@ -601,9 +601,9 @@ class KOBO(USBMS): self.report_progress((i+1) / float(len(paths)), _('Removing books from device metadata listing...')) for bl in booklists: for book in bl: - # print "Book Path: " + book.path + # print 'Book Path: ' + book.path if path.endswith(book.path): - # print " Remove: " + book.path + # print ' Remove: ' + book.path bl.remove_book(book) self.report_progress(1.0, _('Removing books from device metadata listing...')) @@ -634,12 +634,12 @@ class KOBO(USBMS): prints('in add_books_to_metadata. Prefix is None!', path, self._main_prefix) continue - # print "Add book to metadata: " - # print "prefix: " + prefix + # print 'Add book to metadata: ' + # print 'prefix: ' + prefix lpath = path.partition(prefix)[2] if lpath.startswith('/') or lpath.startswith('\\'): lpath = lpath[1:] - # print "path: " + lpath + # print 'path: ' + lpath book = self.book_class(prefix, lpath, info.title, other=info) if book.size is None or book.size == 0: book.size = os.stat(self.normalize_path(path)).st_size @@ -686,13 +686,13 @@ class KOBO(USBMS): def get_content_type_from_extension(self, extension): if extension == '.kobo': # Kobo books do not have book files. They do have some images though - # print "kobo book" + # print 'kobo book' ContentType = 6 elif extension == '.pdf' or extension == '.epub': - # print "ePub or pdf" + # print 'ePub or pdf' ContentType = 16 elif extension == '.rtf' or extension == '.txt' or extension == '.htm' or extension == '.html': - # print "txt" + # print 'txt' if self.fwversion == (1,0) or self.fwversion == (1,4) or self.fwversion == (1,7,4): ContentType = 999 else: @@ -708,14 +708,14 @@ class KOBO(USBMS): print('path from_contentid cardb') elif oncard == 'carda': path = path.replace('file:///mnt/sd/', self._card_a_prefix) - # print "SD Card: " + path + # print 'SD Card: ' + path else: if ContentType == '6' and MimeType == 'Shortcover': # This is a hack as the kobo files do not exist # but the path is required to make a unique id # for calibre's reference path = self._main_prefix + path + '.kobo' - # print "Path: " + path + # print 'Path: ' + path elif (ContentType == '6' or ContentType == '10') and ( MimeType == 'application/x-kobo-epub+zip' or ( MimeType == 'application/epub+zip' and self.isTolinoDevice()) @@ -724,12 +724,12 @@ class KOBO(USBMS): path = self._main_prefix + path.replace('file:///mnt/onboard/', '') else: path = self._main_prefix + KOBO_ROOT_DIR_NAME + '/kepub/' + path - # print "Internal: " + path + # print 'Internal: ' + path else: - # if path.startswith("file:///mnt/onboard/"): + # if path.startswith('file:///mnt/onboard/'): path = path.replace('file:///mnt/onboard/', self._main_prefix) path = path.replace('/mnt/onboard/', self._main_prefix) - # print "Internal: " + path + # print 'Internal: ' + path return path @@ -1820,7 +1820,7 @@ class KOBOTOUCH(KOBO): debug_print('KoboTouch:update_booklist - playlist_map=', playlist_map) path = self.normalize_path(path) - # print "Normalized FileName: " + path + # print 'Normalized FileName: ' + path # Collect the Kobo metadata authors_list = [a.strip() for a in authors.split('&')] if authors is not None else [_('Unknown')] @@ -2144,7 +2144,7 @@ class KOBOTOUCH(KOBO): else: debug_print("KoboTouch:books - Book in mtadata.calibre, on file system but not database - bl[idx].title:'%s'"%bl[idx].title) - # print "count found in cache: %d, count of files in metadata: %d, need_sync: %s" % \ + # print 'count found in cache: %d, count of files in metadata: %d, need_sync: %s' % \ # (len(bl_cache), len(bl), need_sync) # Bypassing the KOBO sync_booklists as that does things we don't need to do # Also forcing sync to see if this solves issues with updating shelves and matching books. @@ -2204,11 +2204,11 @@ class KOBOTOUCH(KOBO): else: path = self._main_prefix + KOBO_ROOT_DIR_NAME + '/kepub/' + path else: # Should never get here, but, just in case... - # if path.startswith("file:///mnt/onboard/"): + # if path.startswith('file:///mnt/onboard/'): path = path.replace('file:///mnt/onboard/', self._main_prefix) path = path.replace('file:///mnt/sd/', self._card_a_prefix) path = path.replace('/mnt/onboard/', self._main_prefix) - # print "Internal: " + path + # print 'Internal: ' + path return path diff --git a/src/calibre/ebooks/chm/reader.py b/src/calibre/ebooks/chm/reader.py index cf3c02b0e8..2d6607eddc 100644 --- a/src/calibre/ebooks/chm/reader.py +++ b/src/calibre/ebooks/chm/reader.py @@ -141,7 +141,7 @@ class CHMReader(CHMFile): else: frag = None name = self._deentity(li.object('param', {'name': 'Name'})[0]['value']) - # print "========>", name + # print '========>', name toc.add_item(href, frag, name, play_order=self._playorder) self._playorder += 1 if li.ul: diff --git a/src/calibre/ebooks/conversion/plugins/chm_input.py b/src/calibre/ebooks/conversion/plugins/chm_input.py index 267e1725a4..d65a112d7b 100644 --- a/src/calibre/ebooks/conversion/plugins/chm_input.py +++ b/src/calibre/ebooks/conversion/plugins/chm_input.py @@ -127,10 +127,10 @@ class CHMInput(InputFormatPlugin): strip_encoding_pats=True, resolve_entities=True)[0] hhcroot = html.fromstring(hhcdata) toc = self._process_nodes(hhcroot) - # print("=============================") - # print("Printing hhcroot") + # print('=============================') + # print('Printing hhcroot') # print(etree.tostring(hhcroot, pretty_print=True)) - # print("=============================") + # print('=============================') log.debug('Found %d section nodes' % toc.count()) htmlpath = os.path.splitext(hhcpath)[0] + '.html' base = os.path.dirname(os.path.abspath(htmlpath)) diff --git a/src/calibre/ebooks/conversion/preprocess.py b/src/calibre/ebooks/conversion/preprocess.py index bd843c082b..fcf8347dc2 100644 --- a/src/calibre/ebooks/conversion/preprocess.py +++ b/src/calibre/ebooks/conversion/preprocess.py @@ -143,20 +143,20 @@ class DocAnalysis: maxLineLength=1900 # Discard larger than this to stay in range buckets=20 # Each line is divided into a bucket based on length - # print("there are "+str(len(lines))+" lines") + # print('there are '+str(len(lines))+' lines') # max = 0 # for line in self.lines: # l = len(line) # if l > max: # max = l - # print("max line found is "+str(max)) + # print('max line found is '+str(max)) # Build the line length histogram hRaw = [0 for i in range(0,buckets)] for line in self.lines: l = len(line) if l > minLineLength and l < maxLineLength: l = int(l // 100) - # print("adding "+str(l)) + # print('adding '+str(l)) hRaw[l]+=1 # Normalize the histogram into percents @@ -165,8 +165,8 @@ class DocAnalysis: h = [float(count)/totalLines for count in hRaw] else: h = [] - # print("\nhRaw histogram lengths are: "+str(hRaw)) - # print(" percents are: "+str(h)+"\n") + # print('\nhRaw histogram lengths are: '+str(hRaw)) + # print(' percents are: '+str(h)+'\n') # Find the biggest bucket maxValue = 0 @@ -175,10 +175,10 @@ class DocAnalysis: maxValue = h[i] if maxValue < percent: - # print("Line lengths are too variable. Not unwrapping.") + # print('Line lengths are too variable. Not unwrapping.') return False else: - # print(str(maxValue)+" of the lines were in one bucket") + # print(str(maxValue)+' of the lines were in one bucket') return True @@ -528,7 +528,7 @@ class HTMLPreProcessor: docanalysis = DocAnalysis('pdf', html) length = docanalysis.line_length(getattr(self.extra_opts, 'unwrap_factor')) if length: - # print("The pdf line length returned is " + str(length)) + # print('The pdf line length returned is ' + str(length)) # unwrap em/en dashes end_rules.append((re.compile( r'(?<=.{%i}[–—])\s*

\s*(?=[\[a-z\d])' % length), lambda match: '')) diff --git a/src/calibre/ebooks/conversion/utils.py b/src/calibre/ebooks/conversion/utils.py index 915ff89d05..28184f8330 100644 --- a/src/calibre/ebooks/conversion/utils.py +++ b/src/calibre/ebooks/conversion/utils.py @@ -628,7 +628,7 @@ class HeuristicProcessor: def check_paragraph(self, content): content = re.sub('\\s*]*>\\s*', '', content) if re.match('.*["\'.!?:]$', content): - # print "detected this as a paragraph" + # print 'detected this as a paragraph' return True else: return False @@ -641,9 +641,9 @@ class HeuristicProcessor: html = re.sub(']*>', '', html) def convert_styles(match): - # print "raw styles are: "+match.group('styles') + # print 'raw styles are: '+match.group('styles') content = match.group('content') - # print "raw content is: "+match.group('content') + # print 'raw content is: '+match.group('content') image = match.group('image') is_paragraph = False @@ -668,12 +668,12 @@ class HeuristicProcessor: else: styles = match.group('styles').split(';') is_paragraph = self.check_paragraph(content) - # print "styles for this line are: "+str(styles) + # print 'styles for this line are: '+str(styles) split_styles = [] for style in styles: - # print "style is: "+str(style) + # print 'style is: '+str(style) newstyle = style.split(':') - # print "newstyle is: "+str(newstyle) + # print 'newstyle is: '+str(newstyle) split_styles.append(newstyle) styles = split_styles for style, setting in styles: @@ -710,18 +710,18 @@ class HeuristicProcessor: self.log.debug('padding bottom is: ' + str(setting[2])) self.log.debug('padding left is: ' +str(setting[3])) - # print "text-align is: "+str(text_align) - # print "\n***\nline is:\n "+str(match.group(0))+'\n' + # print 'text-align is: '+str(text_align) + # print '\n***\nline is:\n '+str(match.group(0))+'\n' if debugabby: - # print "this line is a paragraph = "+str(is_paragraph)+", previous line was "+str(self.previous_was_paragraph) + # print 'this line is a paragraph = '+str(is_paragraph)+', previous line was '+str(self.previous_was_paragraph) self.log.debug('styles for this line were:', styles) self.log.debug('newline is:') self.log.debug(blockquote_open_loop+blockquote_close_loop+ paragraph_before+'

'+content+'

'+paragraph_after+'\n\n\n\n\n') - # print "is_paragraph is "+str(is_paragraph)+", previous_was_paragraph is "+str(self.previous_was_paragraph) + # print 'is_paragraph is '+str(is_paragraph)+', previous_was_paragraph is '+str(self.previous_was_paragraph) self.previous_was_paragraph = is_paragraph - # print "previous_was_paragraph is now set to "+str(self.previous_was_paragraph)+"\n\n\n" + # print 'previous_was_paragraph is now set to '+str(self.previous_was_paragraph)+'\n\n\n' return blockquote_open_loop+blockquote_close_loop+paragraph_before+'

'+content+'

'+paragraph_after html = abbyy_line.sub(convert_styles, html) diff --git a/src/calibre/ebooks/hyphenate.py b/src/calibre/ebooks/hyphenate.py index 5fc27b9ee3..13718f1cd5 100644 --- a/src/calibre/ebooks/hyphenate.py +++ b/src/calibre/ebooks/hyphenate.py @@ -1,4 +1,4 @@ -""" Hyphenation, using Frank Liang's algorithm. +''' Hyphenation, using Frank Liang's algorithm. This module provides a single function to hyphenate words. hyphenate_word takes a string (the word), and returns a list of parts that can be separated by hyphens. @@ -12,7 +12,7 @@ Ned Batchelder, July 2007. This Python code is in the public domain. -""" +''' import re diff --git a/src/calibre/ebooks/lit/mssha1.py b/src/calibre/ebooks/lit/mssha1.py index b1a8419d4b..3370484862 100644 --- a/src/calibre/ebooks/lit/mssha1.py +++ b/src/calibre/ebooks/lit/mssha1.py @@ -283,12 +283,12 @@ class mssha1: return ''.join(['%02x' % c for c in bytearray(self.digest())]) def copy(self): - """Return a clone object. + '''Return a clone object. Return a copy ('clone') of the md5 object. This can be used to efficiently compute the digests of strings that share a common initial substring. - """ + ''' return copy.deepcopy(self) diff --git a/src/calibre/ebooks/lrf/meta.py b/src/calibre/ebooks/lrf/meta.py index 789b293930..367e06a964 100644 --- a/src/calibre/ebooks/lrf/meta.py +++ b/src/calibre/ebooks/lrf/meta.py @@ -122,7 +122,7 @@ class xml_attr_field: self.attr= attr def __get__(self, obj, typ=None): - """ Return the data in this field or '' if the field is empty """ + ''' Return the data in this field or '' if the field is empty ''' document = obj.info elems = document.getElementsByTagName(self.tag_name) if len(elems): @@ -170,7 +170,7 @@ class xml_field: self.parent = parent def __get__(self, obj, typ=None): - """ Return the data in this field or '' if the field is empty """ + ''' Return the data in this field or '' if the field is empty ''' document = obj.info elems = document.getElementsByTagName(self.tag_name) diff --git a/src/calibre/ebooks/lrf/pylrs/pylrf.py b/src/calibre/ebooks/lrf/pylrs/pylrf.py index bce911d114..4d23412d62 100644 --- a/src/calibre/ebooks/lrf/pylrs/pylrf.py +++ b/src/calibre/ebooks/lrf/pylrs/pylrf.py @@ -397,7 +397,7 @@ class LrfTag: if p is None: return - # print " Writing tag", self.name + # print ' Writing tag', self.name for f in self.format: if isinstance(f, dict): p = f[p] @@ -565,7 +565,7 @@ class LrfObject: dotscode))) def write(self, lrf, encoding=None): - # print "Writing object", self.name + # print 'Writing object', self.name LrfTag('ObjectStart', (self.objId, self.type)).write(lrf) for tag in self.tags: diff --git a/src/calibre/ebooks/lrf/pylrs/pylrs.py b/src/calibre/ebooks/lrf/pylrs/pylrs.py index f7d958f300..9a473e17f0 100644 --- a/src/calibre/ebooks/lrf/pylrs/pylrs.py +++ b/src/calibre/ebooks/lrf/pylrs/pylrs.py @@ -357,7 +357,7 @@ class LrsObject: class Book(Delegator): - """ + ''' Main class for any lrs or lrf. All objects must be appended to the Book class in some way or another in order to be rendered as an LRS or LRF file. @@ -396,7 +396,7 @@ class Book(Delegator): Override the default SetDefault. There are several other settings -- see the BookInfo class for more. - """ + ''' def __init__(self, textstyledefault=None, blockstyledefault=None, pagestyledefault=None, @@ -1344,7 +1344,7 @@ class Page(LrsObject, LrsContainer): if hasattr(content, 'getReferencedObjIds'): pageContent.update(content.getReferencedObjIds()) - # print "page contents:", pageContent + # print 'page contents:', pageContent # ObjectList not needed and causes slowdown in SONY LRF renderer # p.appendLrfTag(LrfTag("ObjectList", pageContent)) p.appendLrfTag(LrfTag('Link', self.pageStyle.objId)) @@ -1485,7 +1485,7 @@ class TextBlock(LrsObject, LrsContainer): class Paragraph(LrsContainer): - """ + ''' Note:

alone does not make a paragraph. Only a CR inserted into a text block right after a

makes a real paragraph. Two Paragraphs appended in a row act like a single Paragraph. @@ -1493,7 +1493,7 @@ class Paragraph(LrsContainer): Also note that there are few autoappenders for Paragraph (and the things that can go in it.) It's less confusing (to me) to use explicit .append methods to build up the text stream. - """ + ''' def __init__(self, text=None): LrsContainer.__init__(self, [Text, CR, DropCaps, CharButton, @@ -1620,7 +1620,7 @@ class Button(LrsObject, LrsContainer): def toLrf(self, lrfWriter): (refobj, refpage) = self.findJumpToRefs() - # print "Button writing JumpTo refobj=", jumpto.refobj, ", and refpage=", jumpto.refpage + # print 'Button writing JumpTo refobj=', jumpto.refobj, ', and refpage=', jumpto.refpage button = LrfObject('Button', self.objId) button.appendLrfTag(LrfTag('buttonflags', 0x10)) # pushbutton button.appendLrfTag(LrfTag('PushButtonStart')) diff --git a/src/calibre/ebooks/metadata/topaz.py b/src/calibre/ebooks/metadata/topaz.py index ce0f0eb848..8973712fc4 100644 --- a/src/calibre/ebooks/metadata/topaz.py +++ b/src/calibre/ebooks/metadata/topaz.py @@ -281,7 +281,7 @@ class MetadataUpdater: offset += 1 self.md_header['num_recs'] = ord(self.data[offset:offset+1]) offset += 1 - # print "self.md_header: %s" % self.md_header + # print 'self.md_header: %s' % self.md_header self.metadata = {} self.md_seq = [] diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index 1a7a5e3f63..842bb269ad 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -642,13 +642,13 @@ class DirContainer: class Metadata: - """A collection of OEB data model metadata. + '''A collection of OEB data model metadata. Provides access to the list of items associated with a particular metadata term via the term's local name using either Python container or attribute syntax. Return an empty list for any terms with no currently associated metadata items. - """ + ''' DC_TERMS = {'contributor', 'coverage', 'creator', 'date', 'description', 'format', 'identifier', 'language', @@ -910,7 +910,7 @@ class Manifest: ''' class Item: - """An OEB data model book content file. + '''An OEB data model book content file. Provides the following data members for accessing the file content and metadata associated with this particular file. @@ -927,7 +927,7 @@ class Manifest: primary linear reading order and `False` for textual content items which are not (such as footnotes). Meaningless for items which have a :attr:`spine_position` of `None`. - """ + ''' def __init__(self, oeb, id, href, media_type, fallback=None, loader=str, data=None): @@ -1033,7 +1033,7 @@ class Manifest: @property def data(self): - """Provides MIME type sensitive access to the manifest + '''Provides MIME type sensitive access to the manifest entry's associated content. - XHTML, HTML, and variant content is parsed as necessary to @@ -1044,7 +1044,7 @@ class Manifest: CSS DOM stylesheet. - All other content is returned as a :class:`str` or :class:`bytes` object with no special parsing. - """ + ''' data = self._data if data is None: data = self.data_as_bytes_or_none @@ -1177,7 +1177,7 @@ class Manifest: self.hrefs = {} def add(self, id, href, media_type, fallback=None, loader=None, data=None): - """Add a new item to the book manifest. + '''Add a new item to the book manifest. The item's :param:`id`, :param:`href`, and :param:`media_type` are all required. A :param:`fallback` item-id is required for any items with a @@ -1185,7 +1185,7 @@ class Manifest: item's data itself may be provided with :param:`data`, or a loader function for the data may be provided with :param:`loader`, or the item's data may later be set manually via the :attr:`data` attribute. - """ + ''' item = self.Item( self.oeb, id, href, media_type, fallback, loader, data) self.items.add(item) @@ -1293,13 +1293,13 @@ class Manifest: class Spine: - """Collection of manifest items composing an OEB data model book's main + '''Collection of manifest items composing an OEB data model book's main textual content. The spine manages which manifest items compose the book's main textual content and the sequence in which they appear. Provides Python container access as a list-like object. - """ + ''' def __init__(self, oeb): self.oeb = oeb @@ -1684,14 +1684,14 @@ class TOC: class PageList: - """Collection of named "pages" to mapped positions within an OEB data model + '''Collection of named "pages" to mapped positions within an OEB data model book's textual content. Provides list-like access to the pages. - """ + ''' class Page: - """Represents a mapping between a page name and a position within + '''Represents a mapping between a page name and a position within the book content. Provides the following instance data attributes: @@ -1705,7 +1705,7 @@ class PageList: fashion in print, such as the cover and title pages). :attr:`klass`: Optional semantic class of this page. :attr:`id`: Optional unique identifier for this page. - """ + ''' TYPES = {'front', 'normal', 'special'} def __init__(self, name, href, type='normal', klass=None, id=None): @@ -1847,7 +1847,7 @@ class OEBBook: return cls(encoding=encoding, pretty_print=pretty_print) def translate(self, text): - """Translate :param:`text` into the book's primary language.""" + '''Translate :param:`text` into the book's primary language.''' lang = str(self.metadata.language[0]) lang = lang.split('-', 1)[0].lower() return translate(lang, text) @@ -1887,11 +1887,11 @@ class OEBBook: return fix_data(data) def to_opf1(self): - """Produce OPF 1.2 representing the book's metadata and structure. + '''Produce OPF 1.2 representing the book's metadata and structure. Returns a dictionary in which the keys are MIME types and the values are tuples of (default) filenames and lxml.etree element structures. - """ + ''' package = etree.Element('package', attrib={'unique-identifier': self.uid.id}) self.metadata.to_opf1(package) @@ -1967,11 +1967,11 @@ class OEBBook: return ncx def to_opf2(self, page_map=False): - """Produce OPF 2.0 representing the book's metadata and structure. + '''Produce OPF 2.0 representing the book's metadata and structure. Returns a dictionary in which the keys are MIME types and the values are tuples of (default) filenames and lxml.etree element structures. - """ + ''' results = {} package = etree.Element(OPF('package'), attrib={'version': '2.0', 'unique-identifier': self.uid.id}, diff --git a/src/calibre/ebooks/readability/readability.py b/src/calibre/ebooks/readability/readability.py index 2aebf16d5d..e1195efcce 100644 --- a/src/calibre/ebooks/readability/readability.py +++ b/src/calibre/ebooks/readability/readability.py @@ -315,7 +315,7 @@ class Document: if not REGEXES['divToPElementsRe'].search(str(''.join(map(tounicode, list(elem))))): # self.debug("Altering %s to p" % (describe(elem))) elem.tag = 'p' - # print("Fixed element "+describe(elem)) + # print('Fixed element '+describe(elem)) for elem in self.tags(self.html, 'div'): if elem.text and elem.text.strip(): @@ -323,7 +323,7 @@ class Document: p.text = elem.text elem.text = None elem.insert(0, p) - # print("Appended "+tounicode(p)+" to "+describe(elem)) + # print('Appended '+tounicode(p)+' to '+describe(elem)) for pos, child in reversed(list(enumerate(elem))): if child.tail and child.tail.strip(): @@ -331,7 +331,7 @@ class Document: p.text = child.tail child.tail = None elem.insert(pos + 1, p) - # print("Inserted "+tounicode(p)+" to "+describe(elem)) + # print('Inserted '+tounicode(p)+' to '+describe(elem)) if child.tag == 'br': # print('Dropped
at '+describe(elem)) child.drop_tree() diff --git a/src/calibre/ebooks/rtf2xml/ParseRtf.py b/src/calibre/ebooks/rtf2xml/ParseRtf.py index cfcf8c8297..8abfbe9c1e 100644 --- a/src/calibre/ebooks/rtf2xml/ParseRtf.py +++ b/src/calibre/ebooks/rtf2xml/ParseRtf.py @@ -142,7 +142,7 @@ class ParseRtf: char_data='', default_encoding='cp1252', ): - """ + ''' Requires: 'file' --file to parse 'char_data' --file containing character maps @@ -157,7 +157,7 @@ class ParseRtf: 'check_brackets' -- make sure the brackets match up after each run through a file. Only for debugging. Returns: Nothing - """ + ''' self.__file = in_file self.__out_file = out_file @@ -210,14 +210,14 @@ class ParseRtf: return 1 def parse_rtf(self): - """ + ''' Parse the file by calling on other classes. Requires: Nothing Returns: A parsed file in XML, either to standard output or to a file, depending on the value of 'output' when the instance was created. - """ + ''' self.__temp_file = self.__make_temp_file(self.__file) # if the self.__deb_dir is true, then create a copy object, # set the directory to write to, remove files, and copy diff --git a/src/calibre/ebooks/rtf2xml/add_brackets.py b/src/calibre/ebooks/rtf2xml/add_brackets.py index f41df1c120..55ef9a0d7f 100644 --- a/src/calibre/ebooks/rtf2xml/add_brackets.py +++ b/src/calibre/ebooks/rtf2xml/add_brackets.py @@ -35,7 +35,7 @@ class AddBrackets: copy=None, run_level=1, ): - """ + ''' Required: 'file'--file to parse Optional: @@ -44,7 +44,7 @@ class AddBrackets: directory from which the script is run.) Returns: nothing - """ + ''' self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy diff --git a/src/calibre/ebooks/rtf2xml/body_styles.py b/src/calibre/ebooks/rtf2xml/body_styles.py index c1c77167fa..f9208ab625 100644 --- a/src/calibre/ebooks/rtf2xml/body_styles.py +++ b/src/calibre/ebooks/rtf2xml/body_styles.py @@ -34,7 +34,7 @@ class BodyStyles: bug_handler, copy=None, run_level=1,): - """ + ''' Required: 'file'--file to parse 'table_data' -- a dictionary for each table. @@ -44,7 +44,7 @@ class BodyStyles: directory from which the script is run.) Returns: nothing - """ + ''' self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy diff --git a/src/calibre/ebooks/rtf2xml/colors.py b/src/calibre/ebooks/rtf2xml/colors.py index 4cd666e4dd..a310c35a82 100644 --- a/src/calibre/ebooks/rtf2xml/colors.py +++ b/src/calibre/ebooks/rtf2xml/colors.py @@ -31,7 +31,7 @@ class Colors: copy=None, run_level=1 ): - """ + ''' Required: 'file'--file to parse Optional: @@ -40,7 +40,7 @@ class Colors: directory from which the script is run.) Returns: nothing - """ + ''' self.__file = in_file self.__copy = copy self.__bug_handler = bug_handler @@ -92,12 +92,12 @@ class Colors: nothing Logic: get the hex number from the line and add it to the color string. - ''' + ''' hex_num = line[-3:-1] self.__color_string += hex_num def __blue_func(self, line): - """ + ''' Requires: line Returns: @@ -108,7 +108,7 @@ class Colors: as the key, and the hex number as the value. Write an empty tag with the hex number and number as attributes. Add one to the color number. Reset the color string to '#' - """ + ''' hex_num = line[-3:-1] self.__color_string += hex_num self.__color_dict[self.__color_num] = self.__color_string @@ -130,7 +130,7 @@ class Colors: change the state to after the color table. Otherwise, get a function by passing the self.__token_info to the state dictionary. - ''' + ''' # mi'. So read each token one at a time, and split them by '>'. - """ + ''' # mi info = line[17:-1] tokens = info.split('<') @@ -140,9 +140,9 @@ class ConvertToTags: self.__write_extra_new_line() def __empty_att_func(self, line): - """ + ''' Same as the __open_att_func, except a '/' is placed at the end of the tag. - """ + ''' # mi info = line[17:-1] tokens = info.split('<') @@ -260,7 +260,7 @@ class ConvertToTags: attributes. a closed function for closed tags. an empty tag function. - ''' + ''' self.__initiate_values() with open_for_write(self.__write_to) as self.__write_obj: self.__write_dec() diff --git a/src/calibre/ebooks/rtf2xml/delete_info.py b/src/calibre/ebooks/rtf2xml/delete_info.py index c6415932d0..fb924fb2a0 100644 --- a/src/calibre/ebooks/rtf2xml/delete_info.py +++ b/src/calibre/ebooks/rtf2xml/delete_info.py @@ -95,8 +95,8 @@ class DeleteInfo: return True def __delete_func(self,line): - """Handle lines when in delete state. Don't print out lines - unless the state has ended.""" + '''Handle lines when in delete state. Don't print out lines + unless the state has ended.''' if self.__delete_count == self.__cb_count: self.__state = 'default' if self.__write_cb: diff --git a/src/calibre/ebooks/rtf2xml/field_strings.py b/src/calibre/ebooks/rtf2xml/field_strings.py index 01533cd4ae..9e1f50acca 100644 --- a/src/calibre/ebooks/rtf2xml/field_strings.py +++ b/src/calibre/ebooks/rtf2xml/field_strings.py @@ -182,7 +182,7 @@ class FieldStrings: self.__link_switch = re.compile(r'\\l\s{1,}(.*?)\s') def process_string(self, my_string, type): - """ + ''' Requires: my_string --the string to parse. type -- the type of string. @@ -195,7 +195,7 @@ class FieldStrings: resulting list. This item is the field's type. Check for the action in the field instructions dictionary for further parsing. If no action is found, print out an error message. - """ + ''' changed_string = '' lines = my_string.split('\n') for line in lines: @@ -770,7 +770,7 @@ class FieldStrings: return [None, None, the_string] def __symbol_func(self, field_name, name, line): - """ + ''' Requires: field_name --first name in the string. name -- the changed name according to the dictionary. @@ -792,7 +792,7 @@ class FieldStrings: string, and make this string the last item in a list. The first item in the list is the simple word 'symbol', which tells me that I don't really have field, but UTF-8 data. - """ + ''' num = '' font = '' font_size = '' diff --git a/src/calibre/ebooks/rtf2xml/fields_large.py b/src/calibre/ebooks/rtf2xml/fields_large.py index 9356ebcbc6..dd61fcb727 100644 --- a/src/calibre/ebooks/rtf2xml/fields_large.py +++ b/src/calibre/ebooks/rtf2xml/fields_large.py @@ -20,7 +20,7 @@ from . import open_for_read, open_for_write class FieldsLarge: - r""" + r''' ========================= Logic ========================= @@ -92,7 +92,7 @@ Examples language="1024">1 - """ + ''' def __init__(self, in_file, @@ -100,7 +100,7 @@ Examples copy=None, run_level=1, ): - """ + ''' Required: 'file'--file to parse Optional: @@ -109,7 +109,7 @@ Examples directory from which the script is run.) Returns: nothing - """ + ''' self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy @@ -244,7 +244,7 @@ Examples self.__sec_in_field[-1] = 1 def __found_field_instruction_func(self, line): - """ + ''' Requires: line -- line to parse Returns: @@ -252,13 +252,13 @@ Examples Change the state to field instruction. Set the open bracket count of the beginning of this field so you know when it ends. Set the closed bracket count to 0 so you don't prematureley exit this state. - """ + ''' self.__state = 'field_instruction' self.__field_instruction_count = self.__ob_count self.__cb_count = 0 def __field_instruction_func(self, line): - """ + ''' Requires: line --line to parse Returns: @@ -267,7 +267,7 @@ Examples Collect all the lines until the end of the field is reached. Process these lines with the module rtr.field_strings. Check if the field instruction is 'Symbol' (really UTF-8). - """ + ''' if self.__cb_count == self.__field_instruction_count: # The closing bracket should be written, since the opening bracket # was written diff --git a/src/calibre/ebooks/rtf2xml/fields_small.py b/src/calibre/ebooks/rtf2xml/fields_small.py index 392de17bd8..35f8ccd22c 100644 --- a/src/calibre/ebooks/rtf2xml/fields_small.py +++ b/src/calibre/ebooks/rtf2xml/fields_small.py @@ -21,7 +21,7 @@ from . import open_for_read, open_for_write class FieldsSmall: - """ + ''' ================= Purpose ================= @@ -36,7 +36,7 @@ is found, store the opening bracket count in a variable. Collect all the text until the closing bracket entry is found. Send the string to the module field_strings to process it. Write the processed string to the output file. - """ + ''' def __init__(self, in_file, @@ -44,7 +44,7 @@ file. copy=None, run_level=1, ): - """ + ''' Required: 'file'--file to parse Optional: @@ -53,7 +53,7 @@ file. directory from which the script is run.) Returns: nothing - """ + ''' self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy @@ -119,7 +119,7 @@ file. self.__write_obj.write(line) def __found_bookmark_func(self, line, tag): - """ + ''' Requires: line --the line to parse Returns: @@ -128,7 +128,7 @@ file. This function is called when a bookmark is found. The opening bracket count is stored int eh beginning bracket count. The state is changed to 'bookmark.' - """ + ''' self.__beg_bracket_count = self.__ob_count self.__cb_count = 0 self.__state = 'bookmark' @@ -164,7 +164,7 @@ file. self.__text_string += line[17:-1] def __parse_index_func(self, my_string): - """ + ''' Requires: my_string --string to parse type --type of string @@ -179,7 +179,7 @@ file. sub entry element. If the token is a pargrah ending, ignore it, since I don't won't paragraphs within toc or index entries. - """ + ''' my_string, see_string = self.__index_see_func(my_string) my_string, bookmark_string = self.__index_bookmark_func(my_string) italics, bold = self.__index__format_func(my_string) @@ -385,7 +385,7 @@ file. return my_changed_string def __found_toc_index_func(self, line, tag): - """ + ''' Requires: line --the line to parse Returns: @@ -394,7 +394,7 @@ file. This function is called when a toc or index entry is found. The opening bracket count is stored in the beginning bracket count. The state is changed to 'toc_index.' - """ + ''' self.__beg_bracket_count = self.__ob_count self.__cb_count = 0 self.__state = 'toc_index' diff --git a/src/calibre/ebooks/rtf2xml/fonts.py b/src/calibre/ebooks/rtf2xml/fonts.py index 8cca144fe2..73080aa1c2 100644 --- a/src/calibre/ebooks/rtf2xml/fonts.py +++ b/src/calibre/ebooks/rtf2xml/fonts.py @@ -31,7 +31,7 @@ class Fonts: copy=None, run_level=1, ): - """ + ''' Required: 'file'--file to parse 'default_font_num'--the default font number @@ -41,7 +41,7 @@ class Fonts: directory from which the script is run.) Returns: nothing - """ + ''' self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy @@ -86,7 +86,7 @@ class Fonts: self.__write_obj.write(line) def __font_table_func(self, line): - """ + ''' Requires: line Returns: @@ -99,7 +99,7 @@ class Fonts: font to the default font (in case there is no number provided, in which case RTF assumes the number will be the default font.) Reset the test string (for the font name) to '' - """ + ''' if self.__token_info == 'mi 0: if self.__state[-1] == 'in_row_def': self.__state.pop() @@ -330,7 +330,7 @@ class Table: self.__row_dict['header'] = 'true' def __start_cell_func(self, line): - """ + ''' Required: line -- the line of text Returns: @@ -341,7 +341,7 @@ class Table: Write value => attributes for key=> value pop the self.__cell_list. Otherwise, print out a cell tag. - """ + ''' self.__state.append('in_cell') # self.__cell_list = [] if len(self.__cell_list) > 0: @@ -361,7 +361,7 @@ class Table: self.__cells_in_row += 1 def __start_row_func(self, line): - """ + ''' Required: line -- the line of text Returns: @@ -369,7 +369,7 @@ class Table: Logic: Append 'in_row' for states Write value => attributes for key=> value - """ + ''' self.__state.append('in_row') self.__write_obj.write('mi tag, or None in case of failure. Requires that PIL is installed. @@ -85,7 +85,7 @@ def getimagesize(url): ... #doctest: +ELLIPSIS, +SKIP 'width="..." height="..."' - """ + ''' from PIL import ImageFile @@ -274,11 +274,11 @@ class Textile: self.html_type = 'xhtml' def textile(self, text, rel=None, head_offset=0, html_type='xhtml'): - """ + ''' >>> import textile >>> textile.textile('some textile') u'\\t

some textile

' - """ + ''' self.html_type = html_type # text = type(u'')(text) @@ -298,7 +298,7 @@ class Textile: return text def pba(self, input, element=None): - """ + ''' Parse block attributes. >>> t = Textile() @@ -338,7 +338,7 @@ class Textile: >>> t.pba('[fr]') ' lang="fr"' - """ + ''' style = [] aclass = '' lang = '' @@ -420,7 +420,7 @@ class Textile: return ''.join(result) def hasRawText(self, text): - """ + ''' checks whether the text has text not already enclosed by a block tag >>> t = Textile() @@ -430,17 +430,17 @@ class Textile: >>> t.hasRawText(' why yes, yes it does') True - """ + ''' r = re.compile(r'<(p|blockquote|div|form|table|ul|ol|pre|h\d)[^>]*?>.*', re.S).sub('', text.strip()).strip() r = re.compile(r'<(hr|br)[^>]*?/>').sub('', r) return '' != r def table(self, text): - r""" + r''' >>> t = Textile() >>> t.table('|one|two|three|\n|a|b|c|') '\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t
onetwothree
abc
\n\n' - """ + ''' text = text + '\n\n' pattern = re.compile(r'^(?:table(_?%(s)s%(a)s%(c)s)\. ?\n)?^(%(a)s%(c)s\.? ?\|.*\|)\n\n' % {'s':self.s, 'a':self.a, 'c':self.c}, re.S|re.M|re.U) return pattern.sub(self.fTable, text) @@ -476,11 +476,11 @@ class Textile: return '\t\n{}\n\t\n\n'.format(tatts, '\n'.join(rows)) def lists(self, text): - """ + ''' >>> t = Textile() >>> t.lists("* one\\n* two\\n* three") '\\t
    \\n\\t\\t
  • one
  • \\n\\t\\t
  • two
  • \\n\\t\\t
  • three
  • \\n\\t
' - """ + ''' pattern = re.compile(r'^([#*]+%s .*)$(?![^#*])' % self.c, re.U|re.M|re.S) return pattern.sub(self.fList, text) @@ -537,11 +537,11 @@ class Textile: return f'<{match.group(1)}{match.group(2)}>{content}{match.group(4)}' def block(self, text, head_offset=0): - """ + ''' >>> t = Textile() >>> t.block('h1. foobar baby') '\\t

foobar baby

' - """ + ''' if not self.lite: tre = '|'.join(self.btag) else: @@ -612,7 +612,7 @@ class Textile: return '\n\n'.join(out) def fBlock(self, tag, atts, ext, cite, content): - """ + ''' >>> t = Textile() >>> t.fBlock("bq", "", None, "", "Hello BlockQuote") ('\\t
\\n', '\\t\\t

', 'Hello BlockQuote', '

', '\\n\\t
') @@ -625,7 +625,7 @@ class Textile: >>> t.fBlock("h1", "", None, "", "foobar") ('', '\\t

', 'foobar', '

', '') - """ + ''' atts = self.pba(atts) o1 = o2 = c2 = c1 = '' @@ -678,11 +678,11 @@ class Textile: return o1, o2, content, c2, c1 def footnoteRef(self, text): - """ + ''' >>> t = Textile() >>> t.footnoteRef('foo[1] ') # doctest: +ELLIPSIS 'foo1 ' - """ + ''' return re.sub(r'\b\[([0-9]+)\](\s)?', self.footnoteID, text) def footnoteID(self, match): @@ -695,7 +695,7 @@ class Textile: return f'{id}{t}' def glyphs(self, text): - """ + ''' >>> t = Textile() >>> t.glyphs("apostrophe's") @@ -716,7 +716,7 @@ class Textile: >>> t.glyphs("

Cat's Cradle by Vonnegut

") '

Cat’s Cradle by Vonnegut

' - """ + ''' # fix: hackish text = re.sub(r'"\Z', '" ', text) @@ -798,12 +798,12 @@ class Textile: return id def retrieve(self, text): - """ + ''' >>> t = Textile() >>> id = t.shelve("foobar") >>> t.retrieve(id) 'foobar' - """ + ''' while True: old = text for k, v in self.shelf.items(): @@ -850,11 +850,11 @@ class Textile: return text.rstrip('\n') def links(self, text): - """ + ''' >>> t = Textile() >>> t.links('fooobar "Google":http://google.com/foobar/ and hello world "flickr":http://flickr.com/photos/jsamsa/ ') # doctest: +ELLIPSIS 'fooobar ... and hello world ...' - """ + ''' text = self.macros_only(text) punct = '!"#$%&\'*+,-./:;=?@\\^_`|~' @@ -906,11 +906,11 @@ class Textile: return ''.join([pre, out, post]) def span(self, text): - """ + ''' >>> t = Textile() >>> t.span(r"hello %(bob)span *strong* and **bold**% goodbye") 'hello span strong and bold goodbye' - """ + ''' qtags = (r'\*\*', r'\*', r'\?\?', r'\-', r'__', r'_', r'%', r'\+', r'~', r'\^') pnct = ".,\"'?!;:" @@ -955,11 +955,11 @@ class Textile: return out def image(self, text): - """ + ''' >>> t = Textile() >>> t.image('!/imgs/myphoto.jpg!:http://jsamsa.com') '' - """ + ''' pattern = re.compile(r''' (?:[\[{])? # pre \! # opening ! @@ -1058,17 +1058,17 @@ class Textile: def textile(text, head_offset=0, html_type='xhtml', encoding=None, output=None): - """ + ''' this function takes additional parameters: head_offset - offset to apply to heading levels (default: 0) html_type - 'xhtml' or 'html' style tags (default: 'xhtml') - """ + ''' return Textile().textile(text, head_offset=head_offset, html_type=html_type) def textile_restricted(text, lite=True, noimage=True, html_type='xhtml'): - """ + ''' Restricted version of Textile designed for weblog comments and other untrusted input. @@ -1083,7 +1083,7 @@ def textile_restricted(text, lite=True, noimage=True, html_type='xhtml'): When noimage=True is set (the default): Image tags are disabled. - """ + ''' return Textile(restricted=True, lite=lite, noimage=noimage).textile(text, rel='nofollow', html_type=html_type) diff --git a/src/calibre/gui2/markdown_syntax_highlighter.py b/src/calibre/gui2/markdown_syntax_highlighter.py index 696a55d2b3..0d4cd071b2 100644 --- a/src/calibre/gui2/markdown_syntax_highlighter.py +++ b/src/calibre/gui2/markdown_syntax_highlighter.py @@ -186,7 +186,7 @@ class MarkdownHighlighter(QSyntaxHighlighter): prev = prevBlock.text() prevAscii = str(prev.replace('\u2029','\n')) if self.offset == 0 and prevAscii.strip(): - #print "Its a header" + #print 'Its a header' prevCursor.select(QTextCursor.SelectionType.LineUnderCursor) #prevCursor.setCharFormat(self.MARKDOWN_KWS_FORMAT['Header']) formatRange = QTextLayout.FormatRange() diff --git a/src/calibre/gui2/preferences/create_custom_column.py b/src/calibre/gui2/preferences/create_custom_column.py index 77df94d50a..6409b099ef 100644 --- a/src/calibre/gui2/preferences/create_custom_column.py +++ b/src/calibre/gui2/preferences/create_custom_column.py @@ -841,7 +841,7 @@ class CreateCustomColumn(QDialog): class CreateNewCustomColumn: - """ + ''' Provide an API to create new custom columns. Usage: @@ -942,7 +942,7 @@ class CreateNewCustomColumn: The method returns Result.MUST_RESTART if further calibre configuration has been blocked. You can check for this situation in advance by calling must_restart(). - """ + ''' class Result(Enum): COLUMN_ADDED = 0 @@ -1058,7 +1058,7 @@ class CreateNewCustomColumn: return (self.Result.CANCELED, _('Canceled')) def current_columns(self): - """ + ''' Return the currently defined custom columns Return the currently defined custom columns including the ones that haven't @@ -1075,20 +1075,20 @@ class CreateNewCustomColumn: Columns that already exist will have additional attributes that this class doesn't use. See calibre.library.field_metadata.add_custom_field() for the complete list. - """ + ''' # deepcopy to prevent users from changing it. The new MappingProxyType # isn't enough because only the top-level dict is immutable, not the # items in the dict. return copy.deepcopy(self.custcols) def current_headings(self): - """ + ''' Return the currently defined column headings Return the column headings including the ones that haven't yet been created. It is a dict. The key is the heading, the value is the lookup name having that heading. - """ + ''' return {v['name']:('#' + v['label']) for v in self.custcols.values()} def must_restart(self): diff --git a/src/calibre/library/catalogs/epub_mobi_builder.py b/src/calibre/library/catalogs/epub_mobi_builder.py index 7be0bedd60..6161d6c84d 100644 --- a/src/calibre/library/catalogs/epub_mobi_builder.py +++ b/src/calibre/library/catalogs/epub_mobi_builder.py @@ -207,7 +207,7 @@ class CatalogBuilder: ''' key() functions ''' def _kf_author_to_author_sort(self, author): - """ Compute author_sort value from author + ''' Compute author_sort value from author Tokenize author string, return capitalized string with last token first @@ -216,7 +216,7 @@ class CatalogBuilder: Return: (str): 'Smith, john' - """ + ''' tokens = author.split() tokens = tokens[-1:] + tokens[:-1] if len(tokens) > 1: @@ -224,7 +224,7 @@ class CatalogBuilder: return ' '.join(tokens).capitalize() def _kf_books_by_author_sorter_author(self, book): - """ Generate book sort key with computed author_sort. + ''' Generate book sort key with computed author_sort. Generate a sort key of computed author_sort, title. Used to look for author_sort mismatches. @@ -237,7 +237,7 @@ class CatalogBuilder: Return: (str): sort key - """ + ''' if not book['series']: key = '{} {}'.format(self._kf_author_to_author_sort(book['author']), capitalize(book['title_sort'])) @@ -460,7 +460,7 @@ class CatalogBuilder: (self.thumbs_path, float(cached_thumb_width))) def convert_html_entities(self, s): - """ Convert string containing HTML entities to its unicode equivalent. + ''' Convert string containing HTML entities to its unicode equivalent. Convert a string containing HTML entities of the form '&' or '&97;' to a normalized unicode string. E.g., 'AT&T' converted to 'AT&T'. @@ -470,7 +470,7 @@ class CatalogBuilder: Return: s (str): converted string - """ + ''' return replace_entities(s) def copy_catalog_resources(self): @@ -884,7 +884,7 @@ class CatalogBuilder: raise EmptyCatalogException(error_msg) def fetch_books_to_catalog(self): - """ Populate self.books_to_catalog from database + ''' Populate self.books_to_catalog from database Create self.books_to_catalog from filtered database. Keys: @@ -917,7 +917,7 @@ class CatalogBuilder: Returns: True: Successful False: Empty data, (check filter restrictions) - """ + ''' def _populate_title(record): ''' populate this_title with massaged metadata ''' @@ -1334,7 +1334,7 @@ class CatalogBuilder: return tag_list def format_ncx_text(self, description, dest=None): - """ Massage NCX text for Kindle. + ''' Massage NCX text for Kindle. Convert HTML entities for proper display on Kindle, convert '&' to '&' (Kindle fails). @@ -1345,7 +1345,7 @@ class CatalogBuilder: Return: (str): massaged, possibly truncated description - """ + ''' # Kindle TOC descriptions won't render certain characters # Fix up massaged = xml_replace_entities(str(description)) @@ -1388,7 +1388,7 @@ class CatalogBuilder: return re.sub(r'\W', '', ascii_text(author)) def generate_format_args(self, book): - """ Generate the format args for template substitution. + ''' Generate the format args for template substitution. self.load_section_templates imports string formatting templates of the form 'by_*_template.py' for use in the various sections. The templates are designed to use @@ -1399,7 +1399,7 @@ class CatalogBuilder: Return: (dict): formatted args for templating - """ + ''' series_index = str(book['series_index']) if series_index.endswith('.0'): series_index = series_index[:-2] @@ -2032,7 +2032,7 @@ class CatalogBuilder: bookmarked_books = [] for bm_book in self.bookmarked_books: book = self.bookmarked_books[bm_book] - # print "bm_book: %s" % bm_book + # print 'bm_book: %s' % bm_book book[1]['bookmark_timestamp'] = book[0].timestamp try: book[1]['percent_read'] = min(float(100 * book[0].last_read / book[0].book_length), 100) @@ -2139,7 +2139,7 @@ class CatalogBuilder: master_genre_list = [] for genre_tag_set in genre_list: for (index, genre) in enumerate(genre_tag_set): - # print "genre: %s \t genre_tag_set[genre]: %s" % (genre, genre_tag_set[genre]) + # print 'genre: %s \t genre_tag_set[genre]: %s' % (genre, genre_tag_set[genre]) # Create sorted_authors[0] = friendly, [1] = author_sort for NCX creation authors = [] @@ -3396,7 +3396,7 @@ class CatalogBuilder: for book in self.books_by_date_range: book_time = datetime.datetime(book['timestamp'].year, book['timestamp'].month, book['timestamp'].day) if (today_time - book_time).days <= date_range_limit: - # print "generate_ncx_by_date_added: %s added %d days ago" % (book['title'], (today_time-book_time).days) + # print 'generate_ncx_by_date_added: %s added %d days ago' % (book['title'], (today_time-book_time).days) current_titles_list.append(book['title']) else: break @@ -3505,7 +3505,7 @@ class CatalogBuilder: for book in self.bookmarked_books_by_date_read: bookmark_time = utcfromtimestamp(book['bookmark_timestamp']) if (today_time - bookmark_time).days <= date_range_limit: - # print "generate_ncx_by_date_added: %s added %d days ago" % (book['title'], (today_time-book_time).days) + # print 'generate_ncx_by_date_added: %s added %d days ago' % (book['title'], (today_time-book_time).days) current_titles_list.append(book['title']) else: break @@ -3609,7 +3609,7 @@ class CatalogBuilder: self.generate_ncx_subsection(navPointTag, sec_id, sec_text, content_src, cm_tags) def generate_opf(self): - """ Generate the OPF file. + ''' Generate the OPF file. Start with header template, construct manifest, spine and guide. @@ -3624,7 +3624,7 @@ class CatalogBuilder: Outputs: opts.basename + '.opf' (file): written - """ + ''' self.update_progress_full_step(_('Generating OPF')) lang = get_lang() or 'en' @@ -3798,7 +3798,7 @@ class CatalogBuilder: raise RuntimeError def generate_sort_title(self, title): - """ Generates a sort string from title. + ''' Generates a sort string from title. Based on trunk title_sort algorithm, but also accommodates series numbers by padding with leading zeroes to force proper numeric @@ -3810,7 +3810,7 @@ class CatalogBuilder: Return: (str): sort string - """ + ''' from calibre.ebooks.metadata import title_sort from calibre.library.catalogs.utils import NumberToText @@ -4077,7 +4077,7 @@ class CatalogBuilder: return profile def get_prefix_rules(self): - """ Convert opts.prefix_rules to dict. + ''' Convert opts.prefix_rules to dict. Convert opts.prefix_rules to dict format. The model for a prefix rule is ('','<#source_field_lookup>','','') @@ -4087,7 +4087,7 @@ class CatalogBuilder: Return: (list): list of prefix_rules dicts - """ + ''' pr = [] if self.opts.prefix_rules: try: @@ -4309,7 +4309,7 @@ class CatalogBuilder: return books_by_author def update_progress_full_step(self, description): - """ Update calibre's job status UI. + ''' Update calibre's job status UI. Call ProgessReporter() with updates. @@ -4318,7 +4318,7 @@ class CatalogBuilder: Result: (UI): Jobs UI updated - """ + ''' self.current_step += 1 self.progress_string = description @@ -4336,7 +4336,7 @@ class CatalogBuilder: self.opts.log(log_msg) def update_progress_micro_step(self, description, micro_step_pct): - """ Update calibre's job status UI. + ''' Update calibre's job status UI. Called from steps requiring more time: generate_html_descriptions() @@ -4348,7 +4348,7 @@ class CatalogBuilder: Results: (UI): Jobs UI updated - """ + ''' step_range = 100 / self.total_steps self.progress_string = description diff --git a/src/calibre/srv/http_request.py b/src/calibre/srv/http_request.py index be01a891aa..c07941841e 100644 --- a/src/calibre/srv/http_request.py +++ b/src/calibre/srv/http_request.py @@ -24,7 +24,7 @@ HTTP_METHODS = {'HEAD', 'GET', 'PUT', 'POST', 'TRACE', 'DELETE', 'OPTIONS'} def parse_request_uri(uri): - """Parse a Request-URI into (scheme, authority, path). + '''Parse a Request-URI into (scheme, authority, path). Note that Request-URI's must be one of:: @@ -42,7 +42,7 @@ def parse_request_uri(uri): path_segments = segment *( "/" segment ) segment = *pchar *( ";" param ) param = *pchar - """ + ''' if uri == b'*': return None, None, uri diff --git a/src/calibre/utils/bibtex.py b/src/calibre/utils/bibtex.py index 2f0af82271..e5fa805ead 100644 --- a/src/calibre/utils/bibtex.py +++ b/src/calibre/utils/bibtex.py @@ -1,4 +1,4 @@ -""" Collection of python utility-methodes commonly used by other +''' Collection of python utility-methodes commonly used by other bibliograph packages. From http://pypi.python.org/pypi/bibliograph.core/ from Tom Gross @@ -58,7 +58,7 @@ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - """ +''' __author__ = 'sengian ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/utils/ffml_processor.py b/src/calibre/utils/ffml_processor.py index 711bb58561..56fbf8682a 100644 --- a/src/calibre/utils/ffml_processor.py +++ b/src/calibre/utils/ffml_processor.py @@ -337,7 +337,7 @@ class FFMLProcessor: return self.tree_to_html(tree, 0) def document_to_summary_html(self, document, name, safe=True): - """ + ''' Given a document in the Formatter Function Markup Language (FFML), return that document's summary in HTML format. @@ -349,7 +349,7 @@ class FFMLProcessor: :return: a string containing the HTML - """ + ''' document = document.strip() sum_tag = document.find('[/]') if sum_tag > 0: @@ -453,7 +453,7 @@ class FFMLProcessor: return doc def document_to_summary_rst(self, document, name, indent=0, prefix=None, safe=True): - """ + ''' Given a document in the Formatter Function Markup Language (FFML), return that document's summary in RST (sphinx reStructuredText) format. @@ -471,7 +471,7 @@ class FFMLProcessor: :return: a string containing the RST text - """ + ''' document = document.strip() sum_tag = document.find('[/]') if sum_tag > 0: diff --git a/src/calibre/utils/imghdr.py b/src/calibre/utils/imghdr.py index 9b822b1c04..129fa599ed 100644 --- a/src/calibre/utils/imghdr.py +++ b/src/calibre/utils/imghdr.py @@ -175,7 +175,7 @@ def png(h): @test def gif(h): - """GIF ('87 and '89 variants)""" + '''GIF ('87 and '89 variants)''' if h[:6] in (b'GIF87a', b'GIF89a'): return 'gif' diff --git a/src/calibre/utils/smartypants.py b/src/calibre/utils/smartypants.py index b3bcbe8799..e2cf4d46a3 100644 --- a/src/calibre/utils/smartypants.py +++ b/src/calibre/utils/smartypants.py @@ -526,14 +526,14 @@ def smartyPants(text, attr='1'): def educateQuotes(text): - """ + ''' Parameter: String. Returns: The string, with "educated" curly quote HTML entities. Example input: "Isn't this fun?" Example output: “Isn’t this fun?” - """ + ''' punct_class = r'''[!"#\$\%'()*+,-.\/:;<=>?\@\[\\\]\^_`{|}~]''' @@ -572,12 +572,12 @@ def educateQuotes(text): # meaningful # Special case for Quotes at end of line with a preceding space (may change just to end of line) - # text = re.sub(r"""(?<=\s)"$""", r"""”""", text) - # text = re.sub(r"""(?<=\s)'$""", r"""’""", text) + # text = re.sub(r'''(?<=\s)"$''', r'''”''', text) + # text = re.sub(r'''(?<=\s)'$''', r'''’''', text) # Special case for Quotes at beginning of line with a space - multiparagraph quoted text: - # text = re.sub(r"""^"(?=\s)""", r"""“""", text) - # text = re.sub(r"""^'(?=\s)""", r"""‘""", text) + # text = re.sub(r'''^"(?=\s)''', r'''“''', text) + # text = re.sub(r'''^'(?=\s)''', r'''‘''', text) close_class = r'''[^\ \t\r\n\[\{\(\-]''' dec_dashes = r'''–|—''' @@ -654,13 +654,13 @@ def educateQuotes(text): def educateBackticks(text): - """ + ''' Parameter: String. Returns: The string, with ``backticks'' -style double quotes translated into HTML curly quote entities. Example input: ``Isn't this fun?'' Example output: “Isn't this fun?” - """ + ''' text = re.sub(r'''``''', r'''“''', text) text = re.sub(r"""''""", r'''”''', text) @@ -668,14 +668,14 @@ def educateBackticks(text): def educateSingleBackticks(text): - """ + ''' Parameter: String. Returns: The string, with `backticks' -style single quotes translated into HTML curly quote entities. Example input: `Isn't this fun?' Example output: ‘Isn’t this fun?’ - """ + ''' text = re.sub(r'''`''', r'''‘''', text) text = re.sub(r"""'""", r'''’''', text) @@ -710,7 +710,7 @@ def educateDashesOldSchool(text): def educateDashesOldSchoolInverted(text): - """ + ''' Parameter: String. Returns: The string, with each instance of "--" translated to @@ -723,7 +723,7 @@ def educateDashesOldSchoolInverted(text): common than en-dashes, and so it sort of makes sense that the shortcut should be shorter to type. (Thanks to Aaron Swartz for the idea.) - """ + ''' text = re.sub(r'''---''', r'''–''', text) # em text = re.sub(r'''--''', r'''—''', text) # en return text @@ -769,7 +769,7 @@ def stupefyEntities(text): def processEscapes(text): - r""" + r''' Parameter: String. Returns: The string, with after processing the following backslash escape sequences. This is useful if you want to force a "dumb" @@ -783,7 +783,7 @@ def processEscapes(text): \. . \- - \` ` - """ + ''' text = re.sub(r'''\\\\''', r'''\''', text) text = re.sub(r'''\\"''', r'''"''', text) text = re.sub(r"""\\'""", r''''''', text) @@ -795,7 +795,7 @@ def processEscapes(text): def _tokenize(html): - """ + ''' Parameter: String containing HTML markup. Returns: Reference to an array of the tokens comprising the input string. Each token is either a tag (possibly with nested, @@ -806,15 +806,15 @@ def _tokenize(html): Based on the _tokenize() subroutine from Brad Choate's MTRegex plugin. - """ + ''' tokens = [] # depth = 6 # nested_tags = "|".join(['(?:<(?:[^<>]',] * depth) + (')*>)' * depth) - # match = r"""(?: ) | # comments + # match = r'''(?: ) | # comments # (?: <\? .*? \?> ) | # directives - # %s # nested tags """ % (nested_tags,) + # %s # nested tags ''' % (nested_tags,) tag_soup = re.compile(r'''([^<]*)(<[^>]*>)''') token_match = tag_soup.search(html) diff --git a/src/calibre/utils/smtplib.py b/src/calibre/utils/smtplib.py index 15f148dcd5..f9c07146ad 100644 --- a/src/calibre/utils/smtplib.py +++ b/src/calibre/utils/smtplib.py @@ -82,13 +82,13 @@ class SMTPServerDisconnected(SMTPException): class SMTPResponseException(SMTPException): - """Base class for all exceptions that include an SMTP error code. + '''Base class for all exceptions that include an SMTP error code. These exceptions are generated in some instances when the SMTP server returns an error code. The error code is stored in the `smtp_code' attribute of the error, and the `smtp_error' attribute is set to the error message. - """ + ''' def __init__(self, code, msg): self.smtp_code = code @@ -97,11 +97,11 @@ class SMTPResponseException(SMTPException): class SMTPSenderRefused(SMTPResponseException): - """Sender address refused. + '''Sender address refused. In addition to the attributes set by on all SMTPResponseException exceptions, this sets `sender' to the string that the SMTP refused. - """ + ''' def __init__(self, code, msg, sender): self.smtp_code = code @@ -111,12 +111,12 @@ class SMTPSenderRefused(SMTPResponseException): class SMTPRecipientsRefused(SMTPException): - """All recipient addresses refused. + '''All recipient addresses refused. The errors for each recipient are accessible through the attribute 'recipients', which is a dictionary of exactly the same sort as SMTP.sendmail() returns. - """ + ''' def __init__(self, recipients): self.recipients = recipients @@ -124,7 +124,7 @@ class SMTPRecipientsRefused(SMTPException): class SMTPDataError(SMTPResponseException): - """The SMTP server didn't accept the data.""" + '''The SMTP server didn't accept the data.''' class SMTPConnectError(SMTPResponseException): @@ -136,11 +136,11 @@ class SMTPHeloError(SMTPResponseException): class SMTPAuthenticationError(SMTPResponseException): - """Authentication error. + '''Authentication error. Most probably the server didn't accept the username/password combination provided. - """ + ''' def quoteaddr(addr): @@ -172,11 +172,11 @@ def _addr_only(addrstring): def quotedata(data): - """Quote data for email. + '''Quote data for email. Double leading '.', and change Unix newline '\\n', or Mac '\\r' into Internet CRLF end-of-line. - """ + ''' return re.sub(r'(?m)^\.', '..', re.sub(r'(?:\r\n|\n|\r(?!\n))', CRLF, data)) @@ -216,7 +216,7 @@ else: class SMTP: - """This class manages a connection to an SMTP or ESMTP server. + '''This class manages a connection to an SMTP or ESMTP server. SMTP Objects: SMTP objects have the following attributes: helo_resp @@ -243,7 +243,7 @@ class SMTP: See each method's docstrings for details. In general, there is a method of the same name to perform each SMTP command. There is also a method called 'sendmail' that will do an entire mail transaction. - """ + ''' debuglevel = 0 file = None helo_resp = None @@ -255,7 +255,7 @@ class SMTP: def __init__(self, host='', port=0, local_hostname=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, debug_to=partial(print, file=stderr)): - """Initialize a new instance. + '''Initialize a new instance. If specified, `host' is the name of the remote host to which to connect. If specified, `port' specifies the port to which to connect. @@ -266,7 +266,7 @@ class SMTP: specifies where debug output is written to. By default it is written to sys.stderr. You should pass in a print function of your own to control where debug output is written. - """ + ''' self._host = host self.timeout = timeout self.debug = debug_to @@ -312,7 +312,7 @@ class SMTP: return socket.create_connection((host, port), timeout) def connect(self, host='localhost', port=0): - """Connect to a host on a given port. + '''Connect to a host on a given port. If the hostname ends with a colon (`:') followed by a number, and there is no port specified, that suffix will be stripped off and the @@ -321,7 +321,7 @@ class SMTP: Note: This method is automatically invoked by __init__, if a host is specified during instantiation. - """ + ''' if not port and (host.find(':') == host.rfind(':')): i = host.rfind(':') if i >= 0: @@ -342,7 +342,7 @@ class SMTP: return (code, msg) def send(self, str): - """Send `str' to the server.""" + '''Send `str' to the server.''' if self.debuglevel > 0: raw = repr(str) self.debug('send:', raw) @@ -364,7 +364,7 @@ class SMTP: self.send(str) def getreply(self): - """Get a reply from the server. + '''Get a reply from the server. Returns a tuple consisting of: @@ -375,7 +375,7 @@ class SMTP: responses are converted to a single, multiline string). Raises SMTPServerDisconnected if end-of-file is reached. - """ + ''' resp = [] if self.file is None: self.file = self.sock.makefile('rb') @@ -417,20 +417,20 @@ class SMTP: # std smtp commands def helo(self, name=''): - """SMTP 'helo' command. + '''SMTP 'helo' command. Hostname to send for this command defaults to the FQDN of the local host. - """ + ''' self.putcmd('helo', name or self.local_hostname) (code, msg) = self.getreply() self.helo_resp = msg return (code, msg) def ehlo(self, name=''): - """ SMTP 'ehlo' command. + ''' SMTP 'ehlo' command. Hostname to send for this command defaults to the FQDN of the local host. - """ + ''' self.esmtp_features = {} self.putcmd(self.ehlo_msg, name or self.local_hostname) (code, msg) = self.getreply() @@ -481,21 +481,21 @@ class SMTP: return opt.lower() in self.esmtp_features def help(self, args=''): - """SMTP 'help' command. - Returns help text from server.""" + '''SMTP 'help' command. + Returns help text from server.''' self.putcmd('help', args) return self.getreply()[1] def rset(self): - """SMTP 'rset' command -- resets session.""" + '''SMTP 'rset' command -- resets session.''' return self.docmd('rset') def noop(self): - """SMTP 'noop' command -- doesn't do anything :>""" + '''SMTP 'noop' command -- doesn't do anything :>''' return self.docmd('noop') def mail(self, sender, options=[]): - """SMTP 'mail' command -- begins mail xfer session.""" + '''SMTP 'mail' command -- begins mail xfer session.''' optionlist = '' if options and self.does_esmtp: optionlist = ' ' + ' '.join(options) @@ -503,7 +503,7 @@ class SMTP: return self.getreply() def rcpt(self, recip, options=[]): - """SMTP 'rcpt' command -- indicates 1 recipient for this mail.""" + '''SMTP 'rcpt' command -- indicates 1 recipient for this mail.''' optionlist = '' if options and self.does_esmtp: optionlist = ' ' + ' '.join(options) @@ -511,13 +511,13 @@ class SMTP: return self.getreply() def data(self, msg): - """SMTP 'DATA' command -- sends message data to server. + '''SMTP 'DATA' command -- sends message data to server. Automatically quotes lines beginning with a period per rfc821. Raises SMTPDataError if there is an unexpected reply to the DATA command; the return value from this method is the final response code received when the all data is sent. - """ + ''' self.putcmd('data') (code, repl) = self.getreply() if self.debuglevel > 0: @@ -536,21 +536,21 @@ class SMTP: return (code, msg) def verify(self, address): - """SMTP 'verify' command -- checks for address validity.""" + '''SMTP 'verify' command -- checks for address validity.''' self.putcmd('vrfy', _addr_only(address)) return self.getreply() # a.k.a. vrfy = verify def expn(self, address): - """SMTP 'expn' command -- expands a mailing list.""" + '''SMTP 'expn' command -- expands a mailing list.''' self.putcmd('expn', _addr_only(address)) return self.getreply() # some useful methods def ehlo_or_helo_if_needed(self): - """Call self.ehlo() and/or self.helo() if needed. + '''Call self.ehlo() and/or self.helo() if needed. If there has been no previous EHLO or HELO command this session, this method tries ESMTP EHLO first. @@ -559,7 +559,7 @@ class SMTP: SMTPHeloError The server didn't reply properly to the helo greeting. - """ + ''' if self.helo_resp is None and self.ehlo_resp is None: if not (200 <= self.ehlo()[0] <= 299): (code, resp) = self.helo() @@ -567,7 +567,7 @@ class SMTP: raise SMTPHeloError(code, resp) def login(self, user, password): - """Log in on an SMTP server that requires authentication. + '''Log in on an SMTP server that requires authentication. The arguments are: - user: The user name to authenticate with. @@ -586,7 +586,7 @@ class SMTP: password combination. SMTPException No suitable authentication method was found. - """ + ''' def encode_cram_md5(challenge, user, password): challenge = base64.decodestring(challenge) @@ -646,7 +646,7 @@ class SMTP: return (code, resp) def starttls(self, context=None): - """Puts the connection to the SMTP server into TLS mode. + '''Puts the connection to the SMTP server into TLS mode. If there has been no previous EHLO or HELO command this session, this method tries ESMTP EHLO first. @@ -661,7 +661,7 @@ class SMTP: SMTPHeloError The server didn't reply properly to the helo greeting. - """ + ''' self.ehlo_or_helo_if_needed() if not self.has_extn('starttls'): raise SMTPException('STARTTLS extension not supported by server.') @@ -744,8 +744,8 @@ class SMTP: of the four addresses, and one was rejected, with the error code 550. If all addresses are accepted, then the method will return an empty dictionary. - """ + self.ehlo_or_helo_if_needed() esmtp_opts = [] if self.does_esmtp: @@ -805,13 +805,13 @@ class SMTP: if _have_ssl: class SMTP_SSL(SMTP): - """ This is a subclass derived from SMTP that connects over an SSL encrypted + ''' This is a subclass derived from SMTP that connects over an SSL encrypted socket (to use this class you need a socket module that was compiled with SSL support). If host is not specified, '' (the local host) is used. If port is omitted, the standard SMTP-over-SSL port (465) is used. keyfile and certfile are also optional - they can contain a PEM formatted private key and certificate chain file for the SSL connection. - """ + ''' default_port = SMTP_SSL_PORT @@ -841,7 +841,7 @@ LMTP_PORT = 2003 class LMTP(SMTP): - """LMTP - Local Mail Transfer Protocol + '''LMTP - Local Mail Transfer Protocol The LMTP protocol, which is very similar to ESMTP, is heavily based on the standard SMTP client. It's common to use Unix sockets for LMTP, @@ -851,7 +851,7 @@ class LMTP(SMTP): Authentication is supported, using the regular SMTP mechanism. When using a Unix socket, LMTP generally don't support or require any - authentication, but your mileage might vary.""" + authentication, but your mileage might vary.''' ehlo_msg = 'lhlo' diff --git a/src/calibre/utils/threadpool.py b/src/calibre/utils/threadpool.py index 06ad3495c0..4c9d501f34 100644 --- a/src/calibre/utils/threadpool.py +++ b/src/calibre/utils/threadpool.py @@ -1,4 +1,4 @@ -"""Easy to use object-oriented thread pool framework. +'''Easy to use object-oriented thread pool framework. A thread pool is an object that maintains a pool of worker threads to perform time consuming operations in parallel. It assigns jobs to the threads @@ -28,7 +28,7 @@ Basic usage: See the end of the module code for a brief, annotated usage example. Website : http://chrisarndt.de/en/software/python/threadpool/ -""" +''' __all__ = [ 'makeRequests', @@ -239,7 +239,7 @@ class ThreadPool: def makeRequests(callable, args_list, callback=None, exc_callback=None): - """Create several work requests for same callable with different arguments. + '''Create several work requests for same callable with different arguments. Convenience function for creating several work requests for the same callable where each invocation of the callable receives different values @@ -251,7 +251,7 @@ def makeRequests(callable, args_list, callback=None, exc_callback=None): non-tuple argument. See docstring for WorkRequest for info on callback and exc_callback. - """ + ''' requests = [] for item in args_list: diff --git a/src/calibre/utils/titlecase.py b/src/calibre/utils/titlecase.py index fa5bf665a7..a134736bca 100644 --- a/src/calibre/utils/titlecase.py +++ b/src/calibre/utils/titlecase.py @@ -43,7 +43,7 @@ def lang(): def titlecase(text): - """ + ''' Titlecases input text This filter changes all words to Title Caps, and attempts to be clever @@ -52,7 +52,7 @@ def titlecase(text): The list of "SMALL words" which are not capped comes from the New York Times Manual of Style, plus 'vs' and 'v'. - """ + ''' all_caps = icu_upper(text) == text diff --git a/src/calibre/utils/wordcount.py b/src/calibre/utils/wordcount.py index 66464664d6..460c892104 100644 --- a/src/calibre/utils/wordcount.py +++ b/src/calibre/utils/wordcount.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -""" +''' Get word, character, and Asian character counts 1. Get a word count as a dictionary: @@ -22,7 +22,7 @@ properties counted: Sourced from: http://ginstrom.com/scribbles/2008/05/17/counting-words-etc-in-an-html-file-with-python/ http://ginstrom.com/scribbles/2007/10/06/counting-words-characters-and-asian-characters-with-python/ -""" +''' __version__ = 0.1 __author__ = 'Ryan Ginstrom' diff --git a/src/calibre/utils/zipfile.py b/src/calibre/utils/zipfile.py index 1e988efdd7..6b94abe609 100644 --- a/src/calibre/utils/zipfile.py +++ b/src/calibre/utils/zipfile.py @@ -913,8 +913,8 @@ class ZipFile: self.write(filename, arcname, compress_type) def replacestr(self, zinfo, byts): - """Delete zinfo.filename, and write a new file into the archive. The - contents is the string 'bytes'.""" + '''Delete zinfo.filename, and write a new file into the archive. The + contents is the string 'bytes'.''' self.delete(zinfo.filename) self.writestr(zinfo, byts) @@ -988,7 +988,7 @@ class ZipFile: return zinfo.filename def getinfo(self, name): - """Return the instance of ZipInfo given 'name'.""" + '''Return the instance of ZipInfo given 'name'.''' info = self.NameToInfo.get(name) if info is None: raise KeyError( @@ -1010,7 +1010,7 @@ class ZipFile: return zef.read_raw() def open(self, name, mode='r', pwd=None): - """Return file-like object for 'name'.""" + '''Return file-like object for 'name'.''' if mode not in ('r', 'U', 'rU'): raise RuntimeError('open() requires mode "r", "U", or "rU"') if not self.fp: @@ -1083,11 +1083,11 @@ class ZipFile: return ZipExtFile(zef_file, mode, zinfo, zd) def extract(self, member, path=None, pwd=None): - """Extract a member from the archive to the current working directory, + '''Extract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately as possible. `member' may be a filename or a ZipInfo object. You can specify a different directory using `path'. - """ + ''' if not isinstance(member, ZipInfo): member = self.getinfo(member) @@ -1097,11 +1097,11 @@ class ZipFile: return self._extract_member(member, path, pwd) def extractall(self, path=None, members=None, pwd=None): - """Extract all members from the archive to the current working + '''Extract all members from the archive to the current working directory. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by namelist(). - """ + ''' if members is None: members = self.namelist() @@ -1113,9 +1113,9 @@ class ZipFile: self.extract(zipinfo, path, pwd) def _extract_member(self, member, targetpath, pwd): - """Extract the ZipInfo object 'member' to a physical + '''Extract the ZipInfo object 'member' to a physical file on the path targetpath. - """ + ''' # build the destination pathname, replacing # forward slashes to platform specific separators. # Strip trailing path separator, unless it represents the root. @@ -1293,9 +1293,9 @@ class ZipFile: def writestr(self, zinfo_or_arcname, byts, permissions=0o600, compression=ZIP_DEFLATED, raw_bytes=False): - """Write a file into the archive. The contents is the string + '''Write a file into the archive. The contents is the string 'byts'. 'zinfo_or_arcname' is either a ZipInfo instance or - the name of the file in the archive.""" + the name of the file in the archive.''' assert not raw_bytes or (raw_bytes and isinstance(zinfo_or_arcname, ZipInfo)) if not isinstance(byts, bytes): diff --git a/src/calibre/web/feeds/templates.py b/src/calibre/web/feeds/templates.py index e546703d07..9e63d330e8 100644 --- a/src/calibre/web/feeds/templates.py +++ b/src/calibre/web/feeds/templates.py @@ -330,7 +330,7 @@ class TouchscreenFeedTemplate(Template): navbar_t.append(navbar_tr) top_navbar = navbar_t bottom_navbar = copy.copy(navbar_t) - # print "\n%s\n" % etree.tostring(navbar_t, pretty_print=True) + # print '\n%s\n' % etree.tostring(navbar_t, pretty_print=True) # Build the page head = HEAD(TITLE(feed.title)) @@ -423,6 +423,6 @@ class TouchscreenNavBarTemplate(Template): navbar_tr.append(TD(attrs('article_next'),link)) navbar_t.append(navbar_tr) navbar.append(navbar_t) - # print "\n%s\n" % etree.tostring(navbar, pretty_print=True) + # print '\n%s\n' % etree.tostring(navbar, pretty_print=True) self.root = HTML(head, BODY(navbar)) diff --git a/src/odf/attrconverters.py b/src/odf/attrconverters.py index f27c18f199..1d362c750f 100644 --- a/src/odf/attrconverters.py +++ b/src/odf/attrconverters.py @@ -209,9 +209,9 @@ def cnv_namespacedToken(attribute, arg, element): def cnv_NCName(attribute, arg, element): - """ NCName is defined in http://www.w3.org/TR/REC-xml-names/#NT-NCName + ''' NCName is defined in http://www.w3.org/TR/REC-xml-names/#NT-NCName Essentially an XML name minus ':' - """ + ''' if isinstance(arg, string_or_bytes): return make_NCName(arg) else: diff --git a/src/odf/element.py b/src/odf/element.py index 740cbff9a9..27bba375b3 100644 --- a/src/odf/element.py +++ b/src/odf/element.py @@ -279,12 +279,12 @@ class CDATASection(Text, Childless): class Element(Node): - """ Creates a arbitrary element and is intended to be subclassed not used on its own. + ''' Creates a arbitrary element and is intended to be subclassed not used on its own. This element is the base of every element it defines a class which resembles a xml-element. The main advantage of this kind of implementation is that you don't have to create a toXML method for every different object. Every element consists of an attribute, optional subelements, optional text and optional cdata. - """ + ''' nodeType = Node.ELEMENT_NODE namespaces = {} # Due to shallow copy this is a static variable @@ -438,12 +438,12 @@ class Element(Node): self.setAttrNS(allowed_attrs[i][0], allowed_attrs[i][1], value) def setAttrNS(self, namespace, localpart, value): - """ Add an attribute to the element + ''' Add an attribute to the element In case you need to add an attribute the library doesn't know about then you must provide the full qualified name It will not check that the attribute is legal according to the schema. Must overwrite, If attribute already exists. - """ + ''' c = AttrConverters() self.attributes[(namespace, localpart)] = c.convert((namespace, localpart), value, self) diff --git a/src/odf/namespaces.py b/src/odf/namespaces.py index df1ea676a2..32b66c63a9 100644 --- a/src/odf/namespaces.py +++ b/src/odf/namespaces.py @@ -24,7 +24,7 @@ CHARTNS = 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0' CHARTOOONS = 'http://openoffice.org/2010/chart' CONFIGNS = 'urn:oasis:names:tc:opendocument:xmlns:config:1.0' CSS3TNS = 'http://www.w3.org/TR/css3-text/' -# DBNS = u"http://openoffice.org/2004/database" +# DBNS = u'http://openoffice.org/2004/database' DBNS = 'urn:oasis:names:tc:opendocument:xmlns:database:1.0' DCNS = 'http://purl.org/dc/elements/1.1/' DOMNS = 'http://www.w3.org/2001/xml-events' diff --git a/src/odf/odf2moinmoin.py b/src/odf/odf2moinmoin.py index 18c86d3934..5ad46a4905 100644 --- a/src/odf/odf2moinmoin.py +++ b/src/odf/odf2moinmoin.py @@ -182,7 +182,7 @@ class ODF2MoinMoin: def processFontDeclarations(self, fontDecl): ''' Extracts necessary font information from a font-declaration element. - ''' + ''' for fontFace in fontDecl.getElementsByTagName('style:font-face'): if fontFace.getAttribute('style:font-pitch') == 'fixed': self.fixedFonts.append(fontFace.getAttribute('style:name')) diff --git a/src/odf/odf2xhtml.py b/src/odf/odf2xhtml.py index d628ac1eba..5fc575f1e8 100644 --- a/src/odf/odf2xhtml.py +++ b/src/odf/odf2xhtml.py @@ -134,13 +134,13 @@ class StyleToCSS: } def save_font(self, name, family, generic): - """ It is possible that the HTML browser doesn't know how to + ''' It is possible that the HTML browser doesn't know how to show a particular font. Fortunately ODF provides generic fallbacks. Unfortunately they are not the same as CSS2. CSS2: serif, sans-serif, cursive, fantasy, monospace ODF: roman, swiss, modern, decorative, script, system This method put the font and fallback into a dictionary - """ + ''' htmlgeneric = 'sans-serif' if generic == 'roman': htmlgeneric = 'serif' @@ -157,10 +157,10 @@ class StyleToCSS: self.fontdict[name] = (family, htmlgeneric) def c_drawfillimage(self, ruleset, sdict, rule, val): - """ Fill a figure with an image. Since CSS doesn't let you resize images + ''' Fill a figure with an image. Since CSS doesn't let you resize images this should really be implemented as an absolutely position with a width and a height - """ + ''' sdict['background-image'] = "url('%s')" % self.fillimages[val] def c_fo(self, ruleset, sdict, rule, val): @@ -278,22 +278,22 @@ class StyleToCSS: sdict['left'] = ruleset[(SVGNS,'x')] def c_page_width(self, ruleset, sdict, rule, val): - """ Set width of box + ''' Set width of box HTML doesn't really have a page-width. It is always 100% of the browser width - """ + ''' sdict['width'] = val def c_text_underline_style(self, ruleset, sdict, rule, val): - """ Set underline decoration + ''' Set underline decoration HTML doesn't really have a page-width. It is always 100% of the browser width - """ + ''' if val and val != 'none': sdict['text-decoration'] = 'underline' def c_text_line_through_style(self, ruleset, sdict, rule, val): - """ Set underline decoration + ''' Set underline decoration HTML doesn't really have a page-width. It is always 100% of the browser width - """ + ''' if val and val != 'none': sdict['text-decoration'] = 'line-through' @@ -302,9 +302,9 @@ class StyleToCSS: sdict['height'] = val def convert_styles(self, ruleset): - """ Rule is a tuple of (namespace, name). If the namespace is '' then + ''' Rule is a tuple of (namespace, name). If the namespace is '' then it is already CSS2 - """ + ''' sdict = {} for rule,val in ruleset.items(): if rule[0] == '': @@ -766,9 +766,9 @@ class ODF2XHTML(handler.ContentHandler): self.cs.fillimages[name] = imghref def rewritelink(self, imghref): - """ Intended to be overloaded if you don't store your pictures + ''' Intended to be overloaded if you don't store your pictures in a Pictures subfolder - """ + ''' return imghref def s_draw_image(self, tag, attrs): @@ -980,10 +980,10 @@ dl.notes dd:last-of-type { page-break-after: avoid } ''' ''' def s_office_presentation(self, tag, attrs): - """ For some odd reason, OpenOffice Impress doesn't define a default-style + ''' For some odd reason, OpenOffice Impress doesn't define a default-style for the 'paragraph'. We therefore force a standard when we see it is a presentation - """ + ''' self.styledict['p'] = {(FONS,'font-size'): '24pt'} self.styledict['presentation'] = {(FONS,'font-size'): '24pt'} self.html_body(tag, attrs) @@ -1039,12 +1039,12 @@ dl.notes dd:last-of-type { page-break-after: avoid } self.currentstyle = None def s_style_font_face(self, tag, attrs): - """ It is possible that the HTML browser doesn't know how to + ''' It is possible that the HTML browser doesn't know how to show a particular font. Luckily ODF provides generic fallbacks Unfortunately they are not the same as CSS2. CSS2: serif, sans-serif, cursive, fantasy, monospace ODF: roman, swiss, modern, decorative, script, system - """ + ''' name = attrs[(STYLENS,'name')] family = attrs[(SVGNS,'font-family')] generic = attrs.get((STYLENS,'font-family-generic'),'') @@ -1086,10 +1086,10 @@ dl.notes dd:last-of-type { page-break-after: avoid } self.styledict[self.currentstyle] = {} def s_style_page_layout(self, tag, attrs): - """ Collect the formatting for the page layout style. + ''' Collect the formatting for the page layout style. This won't work in CSS 2.1, as page identifiers are not allowed. It is legal in CSS3, but the rest of the application doesn't specify when to use what page layout - """ + ''' name = attrs[(STYLENS,'name')] name = name.replace('.','_') self.currentstyle = '.PL-' + name @@ -1319,10 +1319,10 @@ dl.notes dd:last-of-type { page-break-after: avoid } self.purgedata() def s_text_list(self, tag, attrs): - """ Start a list (
    or
      ) + ''' Start a list (
        or
          ) To know which level we're at, we have to count the number of elements on the tagstack. - """ + ''' name = attrs.get((TEXTNS,'style-name')) continue_numbering = attrs.get((TEXTNS, 'continue-numbering')) == 'true' continue_list = attrs.get((TEXTNS, 'continue-list')) @@ -1391,10 +1391,10 @@ dl.notes dd:last-of-type { page-break-after: avoid } self.purgedata() def s_text_list_level_style_bullet(self, tag, attrs): - """ CSS doesn't have the ability to set the glyph + ''' CSS doesn't have the ability to set the glyph to a particular character, so we just go through the available glyphs - """ + ''' name = self.tagstack.rfindattr((STYLENS,'name')) level = attrs[(TEXTNS,'level')] self.prevstyle = self.currentstyle @@ -1649,10 +1649,10 @@ dl.notes dd:last-of-type { page-break-after: avoid } return res def save(self, outputfile, addsuffix=False): - """ Save the HTML under the filename. + ''' Save the HTML under the filename. If the filename is '-' then save to stdout We have the last style filename in self.stylefilename - """ + ''' if outputfile == '-': import sys # Added by Kovid outputfp = sys.stdout diff --git a/src/odf/opendocument.py b/src/odf/opendocument.py index e804a93942..f53bb370cb 100644 --- a/src/odf/opendocument.py +++ b/src/odf/opendocument.py @@ -226,9 +226,9 @@ class OpenDocument: return xml.getvalue() def __manifestxml(self): - """ Generates the manifest.xml file + ''' Generates the manifest.xml file The self.manifest isn't available unless the document is being saved - """ + ''' xml=PolyglotBytesIO() xml.write(_XMLPROLOGUE) self.manifest.toXml(0,xml) @@ -313,11 +313,11 @@ class OpenDocument: return xml.getvalue() def addPicture(self, filename, mediatype=None, content=None): - """ Add a picture + ''' Add a picture It uses the same convention as OOo, in that it saves the picture in the zipfile in the subdirectory 'Pictures' If passed a file ptr, mediatype must be set - """ + ''' if content is None: if mediatype is None: mediatype, encoding = mimetypes.guess_type(filename) @@ -337,12 +337,12 @@ class OpenDocument: return manifestfn def addPictureFromFile(self, filename, mediatype=None): - """ Add a picture + ''' Add a picture It uses the same convention as OOo, in that it saves the picture in the zipfile in the subdirectory 'Pictures'. If mediatype is not given, it will be guessed from the filename extension. - """ + ''' if mediatype is None: mediatype, encoding = mimetypes.guess_type(filename) if mediatype is None: @@ -358,12 +358,12 @@ class OpenDocument: return manifestfn def addPictureFromString(self, content, mediatype): - """ Add a picture + ''' Add a picture It uses the same convention as OOo, in that it saves the picture in the zipfile in the subdirectory 'Pictures'. The content variable is a string that contains the binary image data. The mediatype indicates the image format. - """ + ''' ext = mimetypes.guess_extension(mediatype) manifestfn = f'Pictures/{(time.time()*10000000000):0.0f}{ext}' self.Pictures[manifestfn] = (IS_IMAGE, content, mediatype) @@ -420,9 +420,9 @@ class OpenDocument: self.meta.addElement(meta.Generator(text=TOOLSVERSION)) def save(self, outputfile, addsuffix=False): - """ Save the document under the filename. + ''' Save the document under the filename. If the filename is '-' then save to stdout - """ + ''' if outputfile == '-': outputfp = zipfile.ZipFile(sys.stdout,'w') else: @@ -529,9 +529,9 @@ class OpenDocument: # Document's DOM methods def createElement(self, element): - """ Inconvenient interface to create an element, but follows XML-DOM. + ''' Inconvenient interface to create an element, but follows XML-DOM. Does not allow attributes as argument, therefore can't check grammar. - """ + ''' return element(check_grammar=False) def createTextNode(self, data): diff --git a/src/odf/teletype.py b/src/odf/teletype.py index 182962e3fa..95a8f36b42 100644 --- a/src/odf/teletype.py +++ b/src/odf/teletype.py @@ -17,14 +17,14 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -""" +''' Class for handling whitespace properly in OpenDocument. While it is possible to use getTextContent() and setTextContent() to extract or create ODF content, these won't extract or create the appropriate , , or elements. This module takes care of that problem. -""" +''' from .element import Node @@ -38,12 +38,12 @@ class WhitespaceText: self.spaceCount = 0 def addTextToElement(self, odfElement, s): - """ Process an input string, inserting + ''' Process an input string, inserting elements for '\t', elements for '\n', and elements for runs of more than one blank. These will be added to the given element. - """ + ''' i = 0 ch = ' ' diff --git a/src/qt/__main__.py b/src/qt/__main__.py index 379eac9a82..8951c2e582 100644 --- a/src/qt/__main__.py +++ b/src/qt/__main__.py @@ -85,6 +85,6 @@ with open(f'{base}/__init__.py', 'w') as f: def __getattr__(name): if name in top_level_module_names: import importlib - return importlib.import_module("{QT_WRAPPER}." + name) + return importlib.import_module('{QT_WRAPPER}.' + name) raise AttributeError(name) ''', end='', file=f)