diff --git a/src/calibre/devices/kindle/driver.py b/src/calibre/devices/kindle/driver.py index 2d713c1177..c3a059493e 100644 --- a/src/calibre/devices/kindle/driver.py +++ b/src/calibre/devices/kindle/driver.py @@ -201,7 +201,7 @@ class KINDLE(USBMS): return bookmarked_books def generate_annotation_html(self, bookmark): - from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag + from calibre.ebooks.BeautifulSoup import BeautifulSoup # Returns
...
last_read_location = bookmark.last_read_location timestamp = datetime.datetime.utcfromtimestamp(bookmark.timestamp) @@ -209,11 +209,11 @@ class KINDLE(USBMS): ka_soup = BeautifulSoup() dtc = 0 - divTag = Tag(ka_soup,'div') + divTag = ka_soup.new_tag('div') divTag['class'] = 'user_annotations' # Add the last-read location - spanTag = Tag(ka_soup, 'span') + spanTag = ka_soup.new_tag('span') spanTag['style'] = 'font-weight:bold' if bookmark.book_format == 'pdf': spanTag.insert(0,BeautifulSoup( @@ -230,7 +230,7 @@ class KINDLE(USBMS): divTag.insert(dtc, spanTag) dtc += 1 - divTag.insert(dtc, Tag(ka_soup,'br')) + divTag.insert(dtc, ka_soup.new_tag('br')) dtc += 1 if bookmark.user_notes: @@ -268,7 +268,6 @@ class KINDLE(USBMS): return ka_soup def add_annotation_to_library(self, db, db_id, annotation): - from calibre.ebooks.BeautifulSoup import Tag from calibre.ebooks.metadata import MetaInformation bm = annotation @@ -288,7 +287,7 @@ class KINDLE(USBMS): if set(mi.tags).intersection(ignore_tags): return if mi.comments: - hrTag = Tag(user_notes_soup,'hr') + hrTag = user_notes_soup.new_tag('hr') hrTag['class'] = 'annotations_divider' user_notes_soup.insert(0, hrTag) diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index e570573f50..9b07496cbb 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -1194,7 +1194,7 @@ class KOBO(USBMS): def generate_annotation_html(self, bookmark): import calendar - from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag + from calibre.ebooks.BeautifulSoup import BeautifulSoup # Returns
...
# last_read_location = bookmark.last_read_location # timestamp = bookmark.timestamp @@ -1218,11 +1218,11 @@ class KOBO(USBMS): # debug_print("Percent read: ", percent_read) ka_soup = BeautifulSoup() dtc = 0 - divTag = Tag(ka_soup,'div') + divTag = ka_soup.new_tag('div') divTag['class'] = 'user_annotations' # Add the last-read location - spanTag = Tag(ka_soup, 'span') + spanTag = ka_soup.new_tag('span') spanTag['style'] = 'font-weight:normal' if bookmark.book_format == 'epub': spanTag.insert(0,BeautifulSoup( @@ -1239,7 +1239,7 @@ class KOBO(USBMS): divTag.insert(dtc, spanTag) dtc += 1 - divTag.insert(dtc, Tag(ka_soup,'br')) + divTag.insert(dtc, ka_soup.new_tag('br')) dtc += 1 if bookmark.user_notes: @@ -1301,7 +1301,6 @@ class KOBO(USBMS): return ka_soup def add_annotation_to_library(self, db, db_id, annotation): - from calibre.ebooks.BeautifulSoup import Tag bm = annotation ignore_tags = {'Catalog', 'Clippings'} @@ -1320,7 +1319,7 @@ class KOBO(USBMS): if set(mi.tags).intersection(ignore_tags): return if mi.comments: - hrTag = Tag(user_notes_soup,'hr') + hrTag = user_notes_soup.new_tag('hr') hrTag['class'] = 'annotations_divider' user_notes_soup.insert(0, hrTag) diff --git a/src/calibre/library/catalogs/epub_mobi_builder.py b/src/calibre/library/catalogs/epub_mobi_builder.py index 44bbc7f166..914404a346 100644 --- a/src/calibre/library/catalogs/epub_mobi_builder.py +++ b/src/calibre/library/catalogs/epub_mobi_builder.py @@ -13,7 +13,7 @@ from calibre import ( from calibre.constants import isosx, cache_dir from calibre.customize.conversion import DummyReporter from calibre.customize.ui import output_profiles -from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag, NavigableString +from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, NavigableString from calibre.ebooks.chardet import substitute_entites from calibre.ebooks.metadata import author_to_author_sort from calibre.library.catalogs import AuthorSortMismatchException, EmptyCatalogException, \ @@ -1352,14 +1352,14 @@ class CatalogBuilder(object): soup = BeautifulSoup('') if self.opts.fmt == 'mobi': - codeTag = Tag(soup, "code") + codeTag = soup.new_tag("code") if prefix_char is None: codeTag.insert(0, NavigableString(' ')) else: codeTag.insert(0, NavigableString(prefix_char)) return codeTag else: - spanTag = Tag(soup, "span") + spanTag = soup.new_tag("span") spanTag['class'] = "prefix" if prefix_char is None: prefix_char = " " @@ -1427,7 +1427,7 @@ class CatalogBuilder(object): btc = 0 - divTag = Tag(soup, "div") + divTag = soup.new_tag("div") dtc = 0 divOpeningTag = None dotc = 0 @@ -1459,13 +1459,13 @@ class CatalogBuilder(object): divRunningTag = None author_count = 0 - divOpeningTag = Tag(soup, 'div') + divOpeningTag = soup.new_tag('div') if dtc > 0: divOpeningTag['class'] = "initial_letter" dotc = 0 - pIndexTag = Tag(soup, "p") + pIndexTag = soup.new_tag("p") pIndexTag['class'] = "author_title_letter_index" - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") # current_letter = self.letter_or_symbol(book['author_sort'][0].upper()) current_letter = self.letter_or_symbol(sort_equivalents[idx]) if current_letter == self.SYMBOLS: @@ -1496,15 +1496,15 @@ class CatalogBuilder(object): divTag.insert(dtc, divRunningTag) dtc += 1 - divRunningTag = Tag(soup, 'div') + divRunningTag = soup.new_tag('div') divRunningTag['class'] = "author_logical_group" drtc = 0 non_series_books = 0 current_series = None - pAuthorTag = Tag(soup, "p") + pAuthorTag = soup.new_tag("p") pAuthorTag['class'] = "author_index" - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") aTag['id'] = "%s" % self.generate_author_anchor(current_author) aTag.insert(0, NavigableString(current_author)) pAuthorTag.insert(0, aTag) @@ -1519,12 +1519,12 @@ class CatalogBuilder(object): if book['series'] and book['series'] != current_series: # Start a new series current_series = book['series'] - pSeriesTag = Tag(soup, 'p') + pSeriesTag = soup.new_tag('p') pSeriesTag['class'] = "series" if self.opts.fmt == 'mobi': pSeriesTag['class'] = "series_mobi" if self.opts.generate_series: - aTag = Tag(soup, 'a') + aTag = soup.new_tag('a') aTag['href'] = "%s.html#%s" % ('BySeries', self.generate_series_anchor(book['series'])) aTag.insert(0, book['series']) pSeriesTag.insert(0, aTag) @@ -1541,18 +1541,18 @@ class CatalogBuilder(object): current_series = None # Add books - pBookTag = Tag(soup, "p") + pBookTag = soup.new_tag("p") pBookTag['class'] = "line_item" ptc = 0 pBookTag.insert(ptc, self.format_prefix(book['prefix'])) ptc += 1 - spanTag = Tag(soup, "span") + spanTag = soup.new_tag("span") spanTag['class'] = "entry" stc = 0 - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if self.opts.generate_descriptions: aTag['href'] = "book_%d.html" % (int(float(book['id']))) @@ -1586,17 +1586,17 @@ class CatalogBuilder(object): # loop ends here - pTag = Tag(soup, "p") + pTag = soup.new_tag("p") pTag['class'] = 'title' ptc = 0 - aTag = Tag(soup, 'a') + aTag = soup.new_tag('a') aTag['id'] = 'section_start' pTag.insert(ptc, aTag) ptc += 1 if not self.generate_for_kindle_mobi: # Kindle don't need this because it shows section titles in Periodical format - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") anchor_name = friendly_name.lower() aTag['id'] = anchor_name.replace(" ", "") pTag.insert(ptc, aTag) @@ -1645,9 +1645,9 @@ class CatalogBuilder(object): # Create a new month anchor date_string = strftime(u'%B %Y', current_date.timetuple()) - pIndexTag = Tag(soup, "p") + pIndexTag = soup.new_tag("p") pIndexTag['class'] = "date_index" - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") aTag['id'] = "bda_%s-%s" % (current_date.year, current_date.month) pIndexTag.insert(0, aTag) pIndexTag.insert(1, NavigableString(date_string)) @@ -1662,9 +1662,9 @@ class CatalogBuilder(object): current_author = new_entry['author'] non_series_books = 0 current_series = None - pAuthorTag = Tag(soup, "p") + pAuthorTag = soup.new_tag("p") pAuthorTag['class'] = "author_index" - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if self.opts.generate_authors: aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generate_author_anchor(current_author)) aTag.insert(0, NavigableString(current_author)) @@ -1676,12 +1676,12 @@ class CatalogBuilder(object): if new_entry['series'] and new_entry['series'] != current_series: # Start a new series current_series = new_entry['series'] - pSeriesTag = Tag(soup, 'p') + pSeriesTag = soup.new_tag('p') pSeriesTag['class'] = "series" if self.opts.fmt == 'mobi': pSeriesTag['class'] = "series_mobi" if self.opts.generate_series: - aTag = Tag(soup, 'a') + aTag = soup.new_tag('a') aTag['href'] = "%s.html#%s" % ('BySeries', self.generate_series_anchor(new_entry['series'])) aTag.insert(0, new_entry['series']) pSeriesTag.insert(0, aTag) @@ -1693,18 +1693,18 @@ class CatalogBuilder(object): current_series = None # Add books - pBookTag = Tag(soup, "p") + pBookTag = soup.new_tag("p") pBookTag['class'] = "line_item" ptc = 0 pBookTag.insert(ptc, self.format_prefix(new_entry['prefix'])) ptc += 1 - spanTag = Tag(soup, "span") + spanTag = soup.new_tag("span") spanTag['class'] = "entry" stc = 0 - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if self.opts.generate_descriptions: aTag['href'] = "book_%d.html" % (int(float(new_entry['id']))) @@ -1734,9 +1734,9 @@ class CatalogBuilder(object): def _add_books_to_html_by_date_range(date_range_list, date_range, dtc): if len(date_range_list): - pIndexTag = Tag(soup, "p") + pIndexTag = soup.new_tag("p") pIndexTag['class'] = "date_index" - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") aTag['id'] = "bda_%s" % date_range.replace(' ', '') pIndexTag.insert(0, aTag) pIndexTag.insert(1, NavigableString(date_range)) @@ -1745,18 +1745,18 @@ class CatalogBuilder(object): for new_entry in date_range_list: # Add books - pBookTag = Tag(soup, "p") + pBookTag = soup.new_tag("p") pBookTag['class'] = "line_item" ptc = 0 pBookTag.insert(ptc, self.format_prefix(new_entry['prefix'])) ptc += 1 - spanTag = Tag(soup, "span") + spanTag = soup.new_tag("span") spanTag['class'] = "entry" stc = 0 - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if self.opts.generate_descriptions: aTag['href'] = "book_%d.html" % (int(float(new_entry['id']))) @@ -1781,8 +1781,8 @@ class CatalogBuilder(object): stc += 1 # Link to author - emTag = Tag(soup, "em") - aTag = Tag(soup, "a") + emTag = soup.new_tag("em") + aTag = soup.new_tag("a") if self.opts.generate_authors: aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generate_author_anchor(new_entry['author'])) aTag.insert(0, NavigableString(new_entry['author'])) @@ -1805,18 +1805,18 @@ class CatalogBuilder(object): btc = 0 - pTag = Tag(soup, "p") + pTag = soup.new_tag("p") pTag['class'] = 'title' ptc = 0 - aTag = Tag(soup, 'a') + aTag = soup.new_tag('a') aTag['id'] = 'section_start' pTag.insert(ptc, aTag) ptc += 1 if not self.generate_for_kindle_mobi: # Kindle don't need this because it shows section titles in Periodical format - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") anchor_name = friendly_name.lower() aTag['id'] = anchor_name.replace(" ", "") @@ -1827,7 +1827,7 @@ class CatalogBuilder(object): body.insert(btc, pTag) btc += 1 - divTag = Tag(soup, "div") + divTag = soup.new_tag("div") dtc = 0 # >>> Books by date range <<< @@ -1904,9 +1904,9 @@ class CatalogBuilder(object): if len(todays_list): # Create a new day anchor date_string = strftime(u'%A, %B %d', current_date.timetuple()) - pIndexTag = Tag(soup, "p") + pIndexTag = soup.new_tag("p") pIndexTag['class'] = "date_index" - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") aTag['name'] = "bdr_%s-%s-%s" % (current_date.year, current_date.month, current_date.day) pIndexTag.insert(0, aTag) pIndexTag.insert(1, NavigableString(date_string)) @@ -1914,7 +1914,7 @@ class CatalogBuilder(object): dtc += 1 for new_entry in todays_list: - pBookTag = Tag(soup, "p") + pBookTag = soup.new_tag("p") pBookTag['class'] = "date_read" ptc = 0 @@ -1922,7 +1922,7 @@ class CatalogBuilder(object): pBookTag.insert(ptc, NavigableString(new_entry['reading_progress'])) ptc += 1 - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if self.opts.generate_descriptions: aTag['href'] = "book_%d.html" % (int(float(new_entry['id']))) aTag.insert(0, escape(new_entry['title'])) @@ -1934,8 +1934,8 @@ class CatalogBuilder(object): ptc += 1 # Link to author - emTag = Tag(soup, "em") - aTag = Tag(soup, "a") + emTag = soup.new_tag("em") + aTag = soup.new_tag("a") if self.opts.generate_authors: aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generate_author_anchor(new_entry['author'])) aTag.insert(0, NavigableString(new_entry['author'])) @@ -1949,9 +1949,9 @@ class CatalogBuilder(object): def _add_books_to_html_by_date_range(date_range_list, date_range, dtc): if len(date_range_list): - pIndexTag = Tag(soup, "p") + pIndexTag = soup.new_tag("p") pIndexTag['class'] = "date_index" - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") aTag['name'] = "bdr_%s" % date_range.replace(' ', '') pIndexTag.insert(0, aTag) pIndexTag.insert(1, NavigableString(date_range)) @@ -1960,7 +1960,7 @@ class CatalogBuilder(object): for new_entry in date_range_list: # Add books - pBookTag = Tag(soup, "p") + pBookTag = soup.new_tag("p") pBookTag['class'] = "date_read" ptc = 0 @@ -1971,7 +1971,7 @@ class CatalogBuilder(object): pBookTag.insert(ptc, NavigableString('%s%s' % (dot_string, empty_dots))) ptc += 1 - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if self.opts.generate_descriptions: aTag['href'] = "book_%d.html" % (int(float(new_entry['id']))) aTag.insert(0, escape(new_entry['title'])) @@ -1983,8 +1983,8 @@ class CatalogBuilder(object): ptc += 1 # Link to author - emTag = Tag(soup, "em") - aTag = Tag(soup, "a") + emTag = soup.new_tag("em") + aTag = soup.new_tag("a") if self.opts.generate_authors: aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generate_author_anchor(new_entry['author'])) aTag.insert(0, NavigableString(new_entry['author'])) @@ -2008,19 +2008,19 @@ class CatalogBuilder(object): btc = 0 # Insert section tag - aTag = Tag(soup, 'a') + aTag = soup.new_tag('a') aTag['name'] = 'section_start' body.insert(btc, aTag) btc += 1 # Insert the anchor - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") anchor_name = friendly_name.lower() aTag['name'] = anchor_name.replace(" ", "") body.insert(btc, aTag) btc += 1 - divTag = Tag(soup, "div") + divTag = soup.new_tag("div") dtc = 0 # self.bookmarked_books: (Bookmark, book) @@ -2197,12 +2197,12 @@ class CatalogBuilder(object): body = soup.find('body') btc = 0 - divTag = Tag(soup, 'div') + divTag = soup.new_tag('div') dtc = 0 # Insert section tag if this is the section start - first article only if section_head: - aTag = Tag(soup, 'a') + aTag = soup.new_tag('a') aTag['id'] = 'section_start' divTag.insert(dtc, aTag) dtc += 1 @@ -2210,7 +2210,7 @@ class CatalogBuilder(object): # btc += 1 # Create an anchor from the tag - aTag = Tag(soup, 'a') + aTag = soup.new_tag('a') aTag['id'] = "Genre_%s" % genre divTag.insert(dtc, aTag) body.insert(btc, divTag) @@ -2231,9 +2231,9 @@ class CatalogBuilder(object): current_author = book['author'] non_series_books = 0 current_series = None - pAuthorTag = Tag(soup, "p") + pAuthorTag = soup.new_tag("p") pAuthorTag['class'] = "author_index" - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if self.opts.generate_authors: aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generate_author_anchor(book['author'])) aTag.insert(0, book['author']) @@ -2245,12 +2245,12 @@ class CatalogBuilder(object): if book['series'] and book['series'] != current_series: # Start a new series current_series = book['series'] - pSeriesTag = Tag(soup, 'p') + pSeriesTag = soup.new_tag('p') pSeriesTag['class'] = "series" if self.opts.fmt == 'mobi': pSeriesTag['class'] = "series_mobi" if self.opts.generate_series: - aTag = Tag(soup, 'a') + aTag = soup.new_tag('a') aTag['href'] = "%s.html#%s" % ('BySeries', self.generate_series_anchor(book['series'])) aTag.insert(0, book['series']) pSeriesTag.insert(0, aTag) @@ -2263,19 +2263,19 @@ class CatalogBuilder(object): current_series = None # Add books - pBookTag = Tag(soup, "p") + pBookTag = soup.new_tag("p") pBookTag['class'] = "line_item" ptc = 0 pBookTag.insert(ptc, self.format_prefix(book['prefix'])) ptc += 1 - spanTag = Tag(soup, "span") + spanTag = soup.new_tag("span") spanTag['class'] = "entry" stc = 0 # Add the book title - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if self.opts.generate_descriptions: aTag['href'] = "book_%d.html" % (int(float(book['id']))) @@ -2354,7 +2354,7 @@ class CatalogBuilder(object): body = soup.find('body') btc = 0 - divTag = Tag(soup, "div") + divTag = soup.new_tag("div") dtc = 0 current_letter = "" current_series = None @@ -2366,9 +2366,9 @@ class CatalogBuilder(object): if self.letter_or_symbol(sort_equivalents[idx]) != current_letter: # Start a new letter with Index letter current_letter = self.letter_or_symbol(sort_equivalents[idx]) - pIndexTag = Tag(soup, "p") + pIndexTag = soup.new_tag("p") pIndexTag['class'] = "series_letter_index" - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if current_letter == self.SYMBOLS: aTag['id'] = self.SYMBOLS + "_series" pIndexTag.insert(0, aTag) @@ -2384,11 +2384,11 @@ class CatalogBuilder(object): # Start a new series series_count += 1 current_series = book['series'] - pSeriesTag = Tag(soup, 'p') + pSeriesTag = soup.new_tag('p') pSeriesTag['class'] = "series" if self.opts.fmt == 'mobi': pSeriesTag['class'] = "series_mobi" - aTag = Tag(soup, 'a') + aTag = soup.new_tag('a') aTag['id'] = self.generate_series_anchor(book['series']) pSeriesTag.insert(0, aTag) pSeriesTag.insert(1, NavigableString('%s' % book['series'])) @@ -2396,7 +2396,7 @@ class CatalogBuilder(object): dtc += 1 # Add books - pBookTag = Tag(soup, "p") + pBookTag = soup.new_tag("p") pBookTag['class'] = "line_item" ptc = 0 @@ -2404,11 +2404,11 @@ class CatalogBuilder(object): pBookTag.insert(ptc, self.format_prefix(book['prefix'])) ptc += 1 - spanTag = Tag(soup, "span") + spanTag = soup.new_tag("span") spanTag['class'] = "entry" stc = 0 - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if self.opts.generate_descriptions: aTag['href'] = "book_%d.html" % (int(float(book['id']))) # Use series, series index if avail else just title @@ -2429,7 +2429,7 @@ class CatalogBuilder(object): stc += 1 # Link to author - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if self.opts.generate_authors: aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generate_author_anchor(escape(' & '.join(book['authors'])))) @@ -2443,17 +2443,17 @@ class CatalogBuilder(object): divTag.insert(dtc, pBookTag) dtc += 1 - pTag = Tag(soup, "p") + pTag = soup.new_tag("p") pTag['class'] = 'title' ptc = 0 - aTag = Tag(soup, 'a') + aTag = soup.new_tag('a') aTag['id'] = 'section_start' pTag.insert(ptc, aTag) ptc += 1 if not self.generate_for_kindle_mobi: # Insert the

tag with book_count at the head - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") anchor_name = friendly_name.lower() aTag['id'] = anchor_name.replace(" ", "") pTag.insert(0, aTag) @@ -2489,17 +2489,17 @@ class CatalogBuilder(object): body = soup.find('body') btc = 0 - pTag = Tag(soup, "p") + pTag = soup.new_tag("p") pTag['class'] = 'title' ptc = 0 - aTag = Tag(soup, 'a') + aTag = soup.new_tag('a') aTag['id'] = 'section_start' pTag.insert(ptc, aTag) ptc += 1 if not self.generate_for_kindle_mobi: # Kindle don't need this because it shows section titles in Periodical format - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") aTag['id'] = "bytitle" pTag.insert(ptc, aTag) ptc += 1 @@ -2508,7 +2508,7 @@ class CatalogBuilder(object): body.insert(btc, pTag) btc += 1 - divTag = Tag(soup, "div") + divTag = soup.new_tag("div") dtc = 0 current_letter = "" @@ -2537,13 +2537,13 @@ class CatalogBuilder(object): if drtc and divRunningTag is not None: divTag.insert(dtc, divRunningTag) dtc += 1 - divRunningTag = Tag(soup, 'div') + divRunningTag = soup.new_tag('div') if dtc > 0: divRunningTag['class'] = "initial_letter" drtc = 0 - pIndexTag = Tag(soup, "p") + pIndexTag = soup.new_tag("p") pIndexTag['class'] = "author_title_letter_index" - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") current_letter = self.letter_or_symbol(sort_equivalents[idx]) if current_letter == self.SYMBOLS: aTag['id'] = self.SYMBOLS + "_titles" @@ -2557,19 +2557,19 @@ class CatalogBuilder(object): drtc += 1 # Add books - pBookTag = Tag(soup, "p") + pBookTag = soup.new_tag("p") pBookTag['class'] = "line_item" ptc = 0 pBookTag.insert(ptc, self.format_prefix(book['prefix'])) ptc += 1 - spanTag = Tag(soup, "span") + spanTag = soup.new_tag("span") spanTag['class'] = "entry" stc = 0 # Link to book - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") if self.opts.generate_descriptions: aTag['href'] = "book_%d.html" % (int(float(book['id']))) @@ -2594,8 +2594,8 @@ class CatalogBuilder(object): stc += 1 # Link to author - emTag = Tag(soup, "em") - aTag = Tag(soup, "a") + emTag = soup.new_tag("em") + aTag = soup.new_tag("a") if self.opts.generate_authors: aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generate_author_anchor(book['author'])) aTag.insert(0, NavigableString(book['author'])) @@ -2696,10 +2696,10 @@ class CatalogBuilder(object): genres = '' if 'genres' in book: _soup = BeautifulSoup('') - genresTag = Tag(_soup, 'p') + genresTag = _soup.new_tag('p') gtc = 0 for (i, tag) in enumerate(sorted(book.get('genres', []))): - aTag = Tag(_soup, 'a') + aTag = _soup.new_tag('a') if self.opts.generate_genres: try: aTag['href'] = "Genre_%s.html" % self.genre_tags_dict[tag] @@ -2729,7 +2729,7 @@ class CatalogBuilder(object): # Thumb _soup = BeautifulSoup('', selfClosingTags=['img']) - thumb = Tag(_soup, "img") + thumb = _soup.new_tag("img") if 'cover' in book and book['cover']: thumb['src'] = "../images/thumbnail_%d.jpg" % int(book['id']) else: @@ -2768,9 +2768,9 @@ class CatalogBuilder(object): body = soup.find('body') btc = 0 # Insert the title anchor for inbound links - aTag = Tag(soup, "a") + aTag = soup.new_tag("a") aTag['id'] = "book%d" % int(book['id']) - divTag = Tag(soup, 'div') + divTag = soup.new_tag('div') divTag.insert(0, aTag) body.insert(btc, divTag) btc += 1 @@ -2812,8 +2812,8 @@ class CatalogBuilder(object): emptyTags = body.findAll('td', attrs={'class': 'empty'}) for mt in emptyTags: - newEmptyTag = Tag(BeautifulSoup(), 'td') - newEmptyTag.insert(0, NavigableString(' ')) + newEmptyTag = soup.new_tag('td') + newEmptyTag.insert(0, '\xa0') mt.replaceWith(newEmptyTag) return soup @@ -2890,10 +2890,10 @@ class CatalogBuilder(object): soup = self.generate_html_empty_header(title) bodyTag = soup.find('body') - pTag = Tag(soup, 'p') + pTag = soup.new_tag('p') pTag['class'] = 'title' bodyTag.insert(0, pTag) - divTag = Tag(soup, 'div') + divTag = soup.new_tag('div') divTag['class'] = 'authors' bodyTag.insert(1, divTag) return soup @@ -2977,50 +2977,50 @@ class CatalogBuilder(object): soup = BeautifulStoneSoup(header, selfClosingTags=['content', 'calibre:meta-img']) ncx = soup.find('ncx') - navMapTag = Tag(soup, 'navMap') + navMapTag = soup.new_tag('navMap') if self.generate_for_kindle_mobi: # Build a top-level navPoint for Kindle periodicals - navPointTag = Tag(soup, 'navPoint') + navPointTag = soup.new_tag('navPoint') navPointTag['class'] = "periodical" navPointTag['id'] = "title" navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(soup, 'navLabel') - textTag = Tag(soup, 'text') + navLabelTag = soup.new_tag('navLabel') + textTag = soup.new_tag('text') textTag.insert(0, NavigableString(self.opts.catalog_title)) navLabelTag.insert(0, textTag) navPointTag.insert(0, navLabelTag) if self.opts.generate_authors: - contentTag = Tag(soup, 'content') + contentTag = soup.new_tag('content') contentTag['src'] = "content/ByAlphaAuthor.html" navPointTag.insert(1, contentTag) elif self.opts.generate_titles: - contentTag = Tag(soup, 'content') + contentTag = soup.new_tag('content') contentTag['src'] = "content/ByAlphaTitle.html" navPointTag.insert(1, contentTag) elif self.opts.generate_series: - contentTag = Tag(soup, 'content') + contentTag = soup.new_tag('content') contentTag['src'] = "content/BySeries.html" navPointTag.insert(1, contentTag) elif self.opts.generate_genres: - contentTag = Tag(soup, 'content') + contentTag = soup.new_tag('content') # contentTag['src'] = "content/ByGenres.html" contentTag['src'] = "%s" % self.genres[0]['file'] navPointTag.insert(1, contentTag) elif self.opts.generate_recently_added: - contentTag = Tag(soup, 'content') + contentTag = soup.new_tag('content') contentTag['src'] = "content/ByDateAdded.html" navPointTag.insert(1, contentTag) elif self.opts.generate_descriptions: # Descriptions only - contentTag = Tag(soup, 'content') + contentTag = soup.new_tag('content') contentTag['src'] = "content/book_%d.html" % int(self.books_by_description[0]['id']) navPointTag.insert(1, contentTag) if self.generate_for_kindle_mobi: - cmiTag = Tag(soup, '%s' % 'calibre:meta-img') + cmiTag = soup.new_tag('calibre:meta-img') cmiTag['id'] = "mastheadImage" cmiTag['src'] = "images/mastheadImage.gif" navPointTag.insert(2, cmiTag) @@ -3055,14 +3055,14 @@ class CatalogBuilder(object): btc = len(body.contents) # Add the section navPoint - navPointTag = Tag(ncx_soup, 'navPoint') + navPointTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointTag['class'] = "section" navPointTag['id'] = "bydescription-ID" navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') section_header = '%s [%d]' % (tocTitle, len(self.books_by_description)) if self.generate_for_kindle_mobi: section_header = tocTitle @@ -3071,7 +3071,7 @@ class CatalogBuilder(object): nptc = 0 navPointTag.insert(nptc, navLabelTag) nptc += 1 - contentTag = Tag(ncx_soup, "content") + contentTag = ncx_soup.new_tag("content") contentTag['src'] = "content/book_%d.html" % int(self.books_by_description[0]['id']) navPointTag.insert(nptc, contentTag) nptc += 1 @@ -3079,14 +3079,14 @@ class CatalogBuilder(object): # Loop over the titles for book in self.books_by_description: - navPointVolumeTag = Tag(ncx_soup, 'navPoint') + navPointVolumeTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointVolumeTag['class'] = "article" navPointVolumeTag['id'] = "book%dID" % int(book['id']) navPointVolumeTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, "navLabel") - textTag = Tag(ncx_soup, "text") + navLabelTag = ncx_soup.new_tag("navLabel") + textTag = ncx_soup.new_tag("text") if book['series']: series_index = str(book['series_index']) if series_index.endswith('.0'): @@ -3119,13 +3119,13 @@ class CatalogBuilder(object): navLabelTag.insert(0, textTag) navPointVolumeTag.insert(0, navLabelTag) - contentTag = Tag(ncx_soup, "content") + contentTag = ncx_soup.new_tag("content") contentTag['src'] = "content/book_%d.html#book%d" % (int(book['id']), int(book['id'])) navPointVolumeTag.insert(1, contentTag) if self.generate_for_kindle_mobi: # Add the author tag - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "author" if book['date']: @@ -3141,7 +3141,7 @@ class CatalogBuilder(object): # Add the description tag if book['short_description']: - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "description" cmTag.insert(0, NavigableString(self.format_ncx_text(book['short_description'], dest='description'))) navPointVolumeTag.insert(3, cmTag) @@ -3187,14 +3187,14 @@ class CatalogBuilder(object): btc = len(body.contents) # --- Construct the 'Books By Series' section --- - navPointTag = Tag(ncx_soup, 'navPoint') + navPointTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointTag['class'] = "section" navPointTag['id'] = "byseries-ID" navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') section_header = '%s [%d]' % (tocTitle, len(self.all_series)) if self.generate_for_kindle_mobi: section_header = tocTitle @@ -3203,7 +3203,7 @@ class CatalogBuilder(object): nptc = 0 navPointTag.insert(nptc, navLabelTag) nptc += 1 - contentTag = Tag(ncx_soup, "content") + contentTag = ncx_soup.new_tag("content") contentTag['src'] = "content/%s.html#section_start" % (output) navPointTag.insert(nptc, contentTag) nptc += 1 @@ -3247,14 +3247,14 @@ class CatalogBuilder(object): # Add *article* entries for each populated series title letter for (i, books) in enumerate(series_by_letter): - navPointByLetterTag = Tag(ncx_soup, 'navPoint') + navPointByLetterTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointByLetterTag['class'] = "article" navPointByLetterTag['id'] = "%sSeries-ID" % (title_letters[i].upper()) navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') if len(title_letters[i]) > 1: fmt_string = _(u"Series beginning with %s") else: @@ -3263,7 +3263,7 @@ class CatalogBuilder(object): (title_letters[i] if len(title_letters[i]) > 1 else title_letters[i]))) navLabelTag.insert(0, textTag) navPointByLetterTag.insert(0, navLabelTag) - contentTag = Tag(ncx_soup, 'content') + contentTag = ncx_soup.new_tag('content') # contentTag['src'] = "content/%s.html#%s_series" % (output, title_letters[i]) if title_letters[i] == self.SYMBOLS: contentTag['src'] = "content/%s.html#%s_series" % (output, self.SYMBOLS) @@ -3273,7 +3273,7 @@ class CatalogBuilder(object): navPointByLetterTag.insert(1, contentTag) if self.generate_for_kindle_mobi: - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "description" cmTag.insert(0, NavigableString(self.format_ncx_text(books, dest='description'))) navPointByLetterTag.insert(2, cmTag) @@ -3318,14 +3318,14 @@ class CatalogBuilder(object): btc = len(body.contents) # --- Construct the 'Books By Title' section --- - navPointTag = Tag(ncx_soup, 'navPoint') + navPointTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointTag['class'] = "section" navPointTag['id'] = "byalphatitle-ID" navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') section_header = '%s [%d]' % (tocTitle, len(self.books_by_title)) if self.generate_for_kindle_mobi: section_header = tocTitle @@ -3334,7 +3334,7 @@ class CatalogBuilder(object): nptc = 0 navPointTag.insert(nptc, navLabelTag) nptc += 1 - contentTag = Tag(ncx_soup, "content") + contentTag = ncx_soup.new_tag("content") contentTag['src'] = "content/%s.html#section_start" % (output) navPointTag.insert(nptc, contentTag) nptc += 1 @@ -3380,14 +3380,14 @@ class CatalogBuilder(object): # Add *article* entries for each populated title letter for (i, books) in enumerate(books_by_letter): - navPointByLetterTag = Tag(ncx_soup, 'navPoint') + navPointByLetterTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointByLetterTag['class'] = "article" navPointByLetterTag['id'] = "%sTitles-ID" % (title_letters[i].upper()) navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') if len(title_letters[i]) > 1: fmt_string = _(u"Titles beginning with %s") else: @@ -3396,7 +3396,7 @@ class CatalogBuilder(object): (title_letters[i] if len(title_letters[i]) > 1 else title_letters[i]))) navLabelTag.insert(0, textTag) navPointByLetterTag.insert(0, navLabelTag) - contentTag = Tag(ncx_soup, 'content') + contentTag = ncx_soup.new_tag('content') if title_letters[i] == self.SYMBOLS: contentTag['src'] = "content/%s.html#%s_titles" % (output, self.SYMBOLS) else: @@ -3404,7 +3404,7 @@ class CatalogBuilder(object): navPointByLetterTag.insert(1, contentTag) if self.generate_for_kindle_mobi: - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "description" cmTag.insert(0, NavigableString(self.format_ncx_text(books, dest='description'))) navPointByLetterTag.insert(2, cmTag) @@ -3449,7 +3449,7 @@ class CatalogBuilder(object): btc = len(body.contents) # --- Construct the 'Books By Author' *section* --- - navPointTag = Tag(ncx_soup, 'navPoint') + navPointTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointTag['class'] = "section" file_ID = "%s" % tocTitle.lower() @@ -3457,8 +3457,8 @@ class CatalogBuilder(object): navPointTag['id'] = "%s-ID" % file_ID navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') section_header = '%s [%d]' % (tocTitle, len(self.individual_authors)) if self.generate_for_kindle_mobi: section_header = tocTitle @@ -3467,7 +3467,7 @@ class CatalogBuilder(object): nptc = 0 navPointTag.insert(nptc, navLabelTag) nptc += 1 - contentTag = Tag(ncx_soup, "content") + contentTag = ncx_soup.new_tag("content") contentTag['src'] = "%s#section_start" % HTML_file navPointTag.insert(nptc, contentTag) nptc += 1 @@ -3503,14 +3503,14 @@ class CatalogBuilder(object): # Add *article* entries for each populated author initial letter # master_author_list{}: [0]:author list [1]:Initial letter for authors_by_letter in master_author_list: - navPointByLetterTag = Tag(ncx_soup, 'navPoint') + navPointByLetterTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointByLetterTag['class'] = "article" navPointByLetterTag['id'] = "%sauthors-ID" % (authors_by_letter[1]) navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') if authors_by_letter[1] == self.SYMBOLS: fmt_string = _(u"Authors beginning with %s") else: @@ -3518,7 +3518,7 @@ class CatalogBuilder(object): textTag.insert(0, NavigableString(fmt_string % authors_by_letter[1])) navLabelTag.insert(0, textTag) navPointByLetterTag.insert(0, navLabelTag) - contentTag = Tag(ncx_soup, 'content') + contentTag = ncx_soup.new_tag('content') if authors_by_letter[1] == self.SYMBOLS: contentTag['src'] = "%s#%s_authors" % (HTML_file, authors_by_letter[1]) else: @@ -3526,7 +3526,7 @@ class CatalogBuilder(object): navPointByLetterTag.insert(1, contentTag) if self.generate_for_kindle_mobi: - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "description" cmTag.insert(0, NavigableString(authors_by_letter[0])) navPointByLetterTag.insert(2, cmTag) @@ -3578,7 +3578,7 @@ class CatalogBuilder(object): btc = len(body.contents) # --- Construct the 'Recently Added' *section* --- - navPointTag = Tag(ncx_soup, 'navPoint') + navPointTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointTag['class'] = "section" file_ID = "%s" % tocTitle.lower() @@ -3586,14 +3586,14 @@ class CatalogBuilder(object): navPointTag['id'] = "%s-ID" % file_ID navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') textTag.insert(0, NavigableString('%s' % tocTitle)) navLabelTag.insert(0, textTag) nptc = 0 navPointTag.insert(nptc, navLabelTag) nptc += 1 - contentTag = Tag(ncx_soup, "content") + contentTag = ncx_soup.new_tag("content") contentTag['src'] = "%s#section_start" % HTML_file navPointTag.insert(nptc, contentTag) nptc += 1 @@ -3623,30 +3623,30 @@ class CatalogBuilder(object): # Add *article* entries for each populated date range # master_date_range_list{}: [0]:titles list [1]:datestr for books_by_date_range in master_date_range_list: - navPointByDateRangeTag = Tag(ncx_soup, 'navPoint') + navPointByDateRangeTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointByDateRangeTag['class'] = "article" navPointByDateRangeTag['id'] = "%s-ID" % books_by_date_range[1].replace(' ', '') navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') textTag.insert(0, NavigableString(books_by_date_range[1])) navLabelTag.insert(0, textTag) navPointByDateRangeTag.insert(0, navLabelTag) - contentTag = Tag(ncx_soup, 'content') + contentTag = ncx_soup.new_tag('content') contentTag['src'] = "%s#bda_%s" % (HTML_file, books_by_date_range[1].replace(' ', '')) navPointByDateRangeTag.insert(1, contentTag) if self.generate_for_kindle_mobi: - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "description" cmTag.insert(0, NavigableString(books_by_date_range[0])) navPointByDateRangeTag.insert(2, cmTag) - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "author" navStr = '%d titles' % books_by_date_range[2] if books_by_date_range[2] > 1 else \ '%d title' % books_by_date_range[2] @@ -3683,30 +3683,30 @@ class CatalogBuilder(object): # master_months_list{}: [0]:titles list [1]:date for books_by_month in master_month_list: datestr = strftime(u'%B %Y', books_by_month[1].timetuple()) - navPointByMonthTag = Tag(ncx_soup, 'navPoint') + navPointByMonthTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointByMonthTag['class'] = "article" navPointByMonthTag['id'] = "bda_%s-%s-ID" % (books_by_month[1].year, books_by_month[1].month) navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') textTag.insert(0, NavigableString(datestr)) navLabelTag.insert(0, textTag) navPointByMonthTag.insert(0, navLabelTag) - contentTag = Tag(ncx_soup, 'content') + contentTag = ncx_soup.new_tag('content') contentTag['src'] = "%s#bda_%s-%s" % (HTML_file, books_by_month[1].year, books_by_month[1].month) navPointByMonthTag.insert(1, contentTag) if self.generate_for_kindle_mobi: - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "description" cmTag.insert(0, NavigableString(books_by_month[0])) navPointByMonthTag.insert(2, cmTag) - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "author" navStr = '%d titles' % books_by_month[2] if books_by_month[2] > 1 else \ '%d title' % books_by_month[2] @@ -3762,7 +3762,7 @@ class CatalogBuilder(object): btc = len(body.contents) # --- Construct the 'Recently Read' *section* --- - navPointTag = Tag(ncx_soup, 'navPoint') + navPointTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointTag['class'] = "section" file_ID = "%s" % tocTitle.lower() @@ -3770,14 +3770,14 @@ class CatalogBuilder(object): navPointTag['id'] = "%s-ID" % file_ID navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') textTag.insert(0, NavigableString('%s' % tocTitle)) navLabelTag.insert(0, textTag) nptc = 0 navPointTag.insert(nptc, navLabelTag) nptc += 1 - contentTag = Tag(ncx_soup, "content") + contentTag = ncx_soup.new_tag("content") contentTag['src'] = "%s#section_start" % HTML_file navPointTag.insert(nptc, contentTag) nptc += 1 @@ -3833,7 +3833,7 @@ class CatalogBuilder(object): # master_day_list{}: [0]:titles list [1]:date for books_by_day in master_day_list: datestr = strftime(u'%A, %B %d', books_by_day[1].timetuple()) - navPointByDayTag = Tag(ncx_soup, 'navPoint') + navPointByDayTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointByDayTag['class'] = "article" navPointByDayTag['id'] = "bdr_%s-%s-%sID" % (books_by_day[1].year, @@ -3841,12 +3841,12 @@ class CatalogBuilder(object): books_by_day[1].day) navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') textTag.insert(0, NavigableString(datestr)) navLabelTag.insert(0, textTag) navPointByDayTag.insert(0, navLabelTag) - contentTag = Tag(ncx_soup, 'content') + contentTag = ncx_soup.new_tag('content') contentTag['src'] = "%s#bdr_%s-%s-%s" % (HTML_file, books_by_day[1].year, books_by_day[1].month, @@ -3855,12 +3855,12 @@ class CatalogBuilder(object): navPointByDayTag.insert(1, contentTag) if self.generate_for_kindle_mobi: - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "description" cmTag.insert(0, NavigableString(books_by_day[0])) navPointByDayTag.insert(2, cmTag) - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "author" navStr = '%d titles' % books_by_day[2] if books_by_day[2] > 1 else \ '%d title' % books_by_day[2] @@ -3905,7 +3905,7 @@ class CatalogBuilder(object): btc = len(body.contents) # --- Construct the 'Books By Genre' *section* --- - navPointTag = Tag(ncx_soup, 'navPoint') + navPointTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointTag['class'] = "section" file_ID = "%s" % tocTitle.lower() @@ -3913,8 +3913,8 @@ class CatalogBuilder(object): navPointTag['id'] = "%s-ID" % file_ID navPointTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, 'navLabel') - textTag = Tag(ncx_soup, 'text') + navLabelTag = ncx_soup.new_tag('navLabel') + textTag = ncx_soup.new_tag('text') section_header = '%s [%d]' % (tocTitle, len(self.genres)) if self.generate_for_kindle_mobi: section_header = tocTitle @@ -3923,21 +3923,21 @@ class CatalogBuilder(object): nptc = 0 navPointTag.insert(nptc, navLabelTag) nptc += 1 - contentTag = Tag(ncx_soup, "content") + contentTag = ncx_soup.new_tag("content") contentTag['src'] = "content/Genre_%s.html#section_start" % self.genres[0]['tag'] navPointTag.insert(nptc, contentTag) nptc += 1 for genre in self.genres: # Add an article for each genre - navPointVolumeTag = Tag(ncx_soup, 'navPoint') + navPointVolumeTag = ncx_soup.new_tag('navPoint') if self.generate_for_kindle_mobi: navPointVolumeTag['class'] = "article" navPointVolumeTag['id'] = "genre-%s-ID" % genre['tag'] navPointVolumeTag['playOrder'] = self.play_order self.play_order += 1 - navLabelTag = Tag(ncx_soup, "navLabel") - textTag = Tag(ncx_soup, "text") + navLabelTag = ncx_soup.new_tag("navLabel") + textTag = ncx_soup.new_tag("text") # GwR *** Can this be optimized? normalized_tag = None @@ -3948,13 +3948,13 @@ class CatalogBuilder(object): textTag.insert(0, self.format_ncx_text(NavigableString(friendly_tag), dest='description')) navLabelTag.insert(0, textTag) navPointVolumeTag.insert(0, navLabelTag) - contentTag = Tag(ncx_soup, "content") + contentTag = ncx_soup.new_tag("content") contentTag['src'] = "content/Genre_%s.html#Genre_%s" % (normalized_tag, normalized_tag) navPointVolumeTag.insert(1, contentTag) if self.generate_for_kindle_mobi: # Build the author tag - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "author" # First - Last author @@ -3967,7 +3967,7 @@ class CatalogBuilder(object): navPointVolumeTag.insert(2, cmTag) # Build the description tag - cmTag = Tag(ncx_soup, '%s' % 'calibre:meta') + cmTag = ncx_soup.new_tag('calibre:meta') cmTag['name'] = "description" if False: @@ -4037,18 +4037,18 @@ class CatalogBuilder(object): metadata = soup.find('metadata') mtc = 0 - titleTag = Tag(soup, "dc:title") + titleTag = soup.new_tag("dc:title") titleTag.insert(0, escape(self.opts.catalog_title)) metadata.insert(mtc, titleTag) mtc += 1 - creatorTag = Tag(soup, "dc:creator") + creatorTag = soup.new_tag("dc:creator") creatorTag.insert(0, self.opts.creator) metadata.insert(mtc, creatorTag) mtc += 1 if self.generate_for_kindle_mobi: - periodicalTag = Tag(soup, "meta") + periodicalTag = soup.new_tag("meta") periodicalTag['name'] = "calibre:publication_type" periodicalTag['content'] = "periodical:default" metadata.insert(mtc, periodicalTag) @@ -4061,14 +4061,14 @@ class CatalogBuilder(object): stc = 0 guide = soup.find('guide') - itemTag = Tag(soup, "item") + itemTag = soup.new_tag("item") itemTag['id'] = "ncx" itemTag['href'] = '%s.ncx' % self.opts.basename itemTag['media-type'] = "application/x-dtbncx+xml" manifest.insert(mtc, itemTag) mtc += 1 - itemTag = Tag(soup, "item") + itemTag = soup.new_tag("item") itemTag['id'] = 'stylesheet' itemTag['href'] = self.stylesheet itemTag['media-type'] = 'text/css' @@ -4076,7 +4076,7 @@ class CatalogBuilder(object): mtc += 1 if self.generate_for_kindle_mobi: - itemTag = Tag(soup, "item") + itemTag = soup.new_tag("item") itemTag['id'] = 'mastheadimage-image' itemTag['href'] = "images/mastheadImage.gif" itemTag['media-type'] = 'image/gif' @@ -4086,7 +4086,7 @@ class CatalogBuilder(object): # Write the thumbnail images, descriptions to the manifest if self.opts.generate_descriptions: for thumb in self.thumbs: - itemTag = Tag(soup, "item") + itemTag = soup.new_tag("item") itemTag['href'] = "images/%s" % (thumb) end = thumb.find('.jpg') itemTag['id'] = "%s-image" % thumb[:end] @@ -4098,7 +4098,7 @@ class CatalogBuilder(object): for file in self.html_filelist_1: # By Author, By Title, By Series, - itemTag = Tag(soup, "item") + itemTag = soup.new_tag("item") start = file.find('/') + 1 end = file.find('.') itemTag['href'] = file @@ -4108,14 +4108,14 @@ class CatalogBuilder(object): mtc += 1 # spine - itemrefTag = Tag(soup, "itemref") + itemrefTag = soup.new_tag("itemref") itemrefTag['idref'] = file[start:end].lower() spine.insert(stc, itemrefTag) stc += 1 # Add genre files to manifest and spine for genre in self.genres: - itemTag = Tag(soup, "item") + itemTag = soup.new_tag("item") start = genre['file'].find('/') + 1 end = genre['file'].find('.') itemTag['href'] = genre['file'] @@ -4125,14 +4125,14 @@ class CatalogBuilder(object): mtc += 1 # spine - itemrefTag = Tag(soup, "itemref") + itemrefTag = soup.new_tag("itemref") itemrefTag['idref'] = genre['file'][start:end].lower() spine.insert(stc, itemrefTag) stc += 1 for file in self.html_filelist_2: # By Date Added, By Date Read - itemTag = Tag(soup, "item") + itemTag = soup.new_tag("item") start = file.find('/') + 1 end = file.find('.') itemTag['href'] = file @@ -4142,14 +4142,14 @@ class CatalogBuilder(object): mtc += 1 # spine - itemrefTag = Tag(soup, "itemref") + itemrefTag = soup.new_tag("itemref") itemrefTag['idref'] = file[start:end].lower() spine.insert(stc, itemrefTag) stc += 1 for book in self.books_by_description: # manifest - itemTag = Tag(soup, "item") + itemTag = soup.new_tag("item") itemTag['href'] = "content/book_%d.html" % int(book['id']) itemTag['id'] = "book%d" % int(book['id']) itemTag['media-type'] = "application/xhtml+xml" @@ -4157,14 +4157,14 @@ class CatalogBuilder(object): mtc += 1 # spine - itemrefTag = Tag(soup, "itemref") + itemrefTag = soup.new_tag("itemref") itemrefTag['idref'] = "book%d" % int(book['id']) spine.insert(stc, itemrefTag) stc += 1 # Guide if self.generate_for_kindle_mobi: - referenceTag = Tag(soup, "reference") + referenceTag = soup.new_tag("reference") referenceTag['type'] = 'masthead' referenceTag['title'] = 'mastheadimage-image' referenceTag['href'] = 'images/mastheadImage.gif' @@ -4665,7 +4665,7 @@ class CatalogBuilder(object): split_ps = comments.split(u'\n\n') tsc = 0 for p in split_ps: - pTag = Tag(soup, 'p') + pTag = soup.new_tag('p') pTag.insert(0, p) soup.insert(tsc, pTag) tsc += 1 @@ -4685,7 +4685,7 @@ class CatalogBuilder(object): for token in all_tokens: if type(token) is NavigableString: if not open_pTag: - pTag = Tag(result, 'p') + pTag = result.new_tag('p') open_pTag = True ptc = 0 pTag.insert(ptc, prepare_string_for_xml(token)) @@ -4693,7 +4693,7 @@ class CatalogBuilder(object): elif token.name in ['br', 'b', 'i', 'em']: if not open_pTag: - pTag = Tag(result, 'p') + pTag = result.new_tag('p') open_pTag = True ptc = 0 pTag.insert(ptc, token) diff --git a/src/calibre/library/comments.py b/src/calibre/library/comments.py index e194584d16..ec4279363f 100644 --- a/src/calibre/library/comments.py +++ b/src/calibre/library/comments.py @@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en' import re from calibre.constants import preferred_encoding -from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag, NavigableString, \ +from calibre.ebooks.BeautifulSoup import BeautifulSoup, NavigableString, \ CData, Comment, Declaration, ProcessingInstruction from calibre import prepare_string_for_xml from calibre.utils.html2text import html2text @@ -95,20 +95,20 @@ def comments_to_html(comments): all_tokens = list(soup.contents) for token in all_tokens: - if type(token) is NavigableString: + if isinstance(token, NavigableString): if not open_pTag: - pTag = Tag(result,'p') + pTag = result.new_tag('p') open_pTag = True ptc = 0 pTag.insert(ptc,prepare_string_for_xml(token)) ptc += 1 - elif type(token) in (CData, Comment, Declaration, - ProcessingInstruction): + elif isinstance(token, (CData, Comment, Declaration, + ProcessingInstruction)): continue elif token.name in ['br', 'b', 'i', 'em', 'strong', 'span', 'font', 'a', 'hr']: if not open_pTag: - pTag = Tag(result,'p') + pTag = result.new_tag('p') open_pTag = True ptc = 0 pTag.insert(ptc, token)