From 78cadc9c3a5d79f2f767ce4b6a47ae9e6d7274a4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 18 Feb 2009 11:09:37 -0800 Subject: [PATCH] IGN:Set default cssutils log level to WARN and remove various unused imports from ebooks.oeb --- src/calibre/__init__.py | 3 ++- src/calibre/ebooks/oeb/stylizer.py | 9 ++------- src/calibre/ebooks/oeb/transforms/trimmanifest.py | 6 +----- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index 76ae742de9..65998a2928 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -27,7 +27,8 @@ mimetypes.add_type('application/adobe-page-template+xml', '.xpgt') mimetypes.add_type('application/x-font-opentype', '.otf') mimetypes.add_type('application/x-font-truetype', '.ttf') mimetypes.add_type('application/oebps-package+xml', '.opf') - +import cssutils +cssutils.log.setLevel(logging.WARN) def to_unicode(raw, encoding='utf-8', errors='strict'): if isinstance(raw, unicode): diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index b04492a167..5adb1544eb 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -8,15 +8,10 @@ from __future__ import with_statement __license__ = 'GPL v3' __copyright__ = '2008, Marshall T. Vandegrift ' -import sys import os -import locale -import codecs import itertools -import types import re import copy -from itertools import izip from weakref import WeakKeyDictionary from xml.dom import SyntaxErr as CSSSyntaxError import cssutils @@ -25,7 +20,7 @@ from cssutils.css import CSSStyleRule, CSSPageRule, CSSStyleDeclaration, \ from lxml import etree from lxml.cssselect import css_to_xpath, ExpressionError from calibre.ebooks.oeb.base import XHTML, XHTML_NS, CSS_MIME, OEB_STYLES -from calibre.ebooks.oeb.base import XPNSMAP, xpath, barename, urlnormalize +from calibre.ebooks.oeb.base import XPNSMAP, xpath, urlnormalize from calibre.ebooks.oeb.profile import PROFILES from calibre.resources import html_css @@ -163,7 +158,7 @@ class Stylizer(object): for _, _, cssdict, text, _ in rules: try: selector = CSSSelector(text) - except ExpressionError, e: + except ExpressionError: continue for elem in selector(tree): self.style(elem)._update_cssdict(cssdict) diff --git a/src/calibre/ebooks/oeb/transforms/trimmanifest.py b/src/calibre/ebooks/oeb/transforms/trimmanifest.py index a1d28e5a99..c2ff5ab671 100644 --- a/src/calibre/ebooks/oeb/transforms/trimmanifest.py +++ b/src/calibre/ebooks/oeb/transforms/trimmanifest.py @@ -6,13 +6,9 @@ from __future__ import with_statement __license__ = 'GPL v3' __copyright__ = '2008, Marshall T. Vandegrift ' -import sys -import os from itertools import chain from urlparse import urldefrag -from lxml import etree -import cssutils -from calibre.ebooks.oeb.base import XPNSMAP, CSS_MIME, OEB_DOCS +from calibre.ebooks.oeb.base import CSS_MIME, OEB_DOCS from calibre.ebooks.oeb.base import LINK_SELECTORS, CSSURL_RE from calibre.ebooks.oeb.base import urlnormalize