From 4719971bdd6bf4ca94c37e2153d1f8c4b69fe7c6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 30 Mar 2024 11:35:36 -0400 Subject: [PATCH] Ruff reformat --- cssutils/_fetch.py | 1 + cssutils/_fetchgae.py | 1 + cssutils/css/__init__.py | 1 + cssutils/css/csscharsetrule.py | 1 + cssutils/css/csscomment.py | 1 + cssutils/css/cssfontfacerule.py | 1 + cssutils/css/cssimportrule.py | 1 + cssutils/css/cssmediarule.py | 1 + cssutils/css/cssnamespacerule.py | 4 +- cssutils/css/csspagerule.py | 1 + cssutils/css/cssproperties.py | 1 + cssutils/css/cssrule.py | 1 + cssutils/css/cssrulelist.py | 1 + cssutils/css/cssstyledeclaration.py | 1 + cssutils/css/cssstylerule.py | 6 ++- cssutils/css/cssstylesheet.py | 1 + cssutils/css/cssunknownrule.py | 1 + cssutils/css/cssvalue.py | 1 + cssutils/css/cssvariablesdeclaration.py | 1 + cssutils/css/cssvariablesrule.py | 1 + cssutils/css/marginrule.py | 3 +- cssutils/css/property.py | 1 + cssutils/css/selector.py | 1 + cssutils/css/selectorlist.py | 1 + cssutils/css/value.py | 1 + cssutils/css2productions.py | 1 + cssutils/cssproductions.py | 3 +- cssutils/errorhandler.py | 2 + cssutils/helper.py | 3 +- cssutils/parse.py | 1 + cssutils/prodparser.py | 1 + cssutils/profiles.py | 66 ++++++++++++------------- cssutils/script.py | 4 +- cssutils/scripts/csscapture.py | 1 + cssutils/scripts/csscombine.py | 1 + cssutils/scripts/cssparse.py | 3 +- cssutils/serialize.py | 17 +++---- cssutils/stylesheets/__init__.py | 1 + cssutils/stylesheets/medialist.py | 1 + cssutils/stylesheets/mediaquery.py | 1 + cssutils/stylesheets/stylesheet.py | 1 + cssutils/stylesheets/stylesheetlist.py | 1 + cssutils/tests/test_csscomment.py | 10 ++-- cssutils/tests/test_cssfontfacerule.py | 16 +++--- cssutils/tests/test_cssimportrule.py | 44 ++++++++--------- cssutils/tests/test_cssnamespacerule.py | 24 +++++---- cssutils/tests/test_csspagerule.py | 24 +++++---- cssutils/tests/test_cssstylerule.py | 18 +++---- cssutils/tests/test_cssstylesheet.py | 4 +- cssutils/tests/test_cssutils.py | 3 +- cssutils/tests/test_cssvalue.py | 1 - cssutils/tests/test_encutils.py | 25 +++++----- cssutils/tests/test_marginrule.py | 18 +++---- cssutils/tests/test_parse.py | 3 +- cssutils/tests/test_selector.py | 1 + cssutils/tests/test_util.py | 1 - cssutils/tokenize2.py | 4 +- cssutils/util.py | 4 +- encutils/__init__.py | 9 +--- examples/cssencodings.py | 1 + examples/properties_with_same_name.py | 4 +- examples/style.py | 1 + examples/testutil.py | 1 + examples/website.py | 1 + 64 files changed, 187 insertions(+), 173 deletions(-) diff --git a/cssutils/_fetch.py b/cssutils/_fetch.py index 41a7de28..9c6f5668 100644 --- a/cssutils/_fetch.py +++ b/cssutils/_fetch.py @@ -1,4 +1,5 @@ """Default URL reading functions""" + __all__ = ['_defaultFetcher'] import functools diff --git a/cssutils/_fetchgae.py b/cssutils/_fetchgae.py index b823075b..8b3d130f 100644 --- a/cssutils/_fetchgae.py +++ b/cssutils/_fetchgae.py @@ -1,4 +1,5 @@ """GAE specific URL reading functions""" + __all__ = ['_defaultFetcher'] # raises ImportError of not on GAE diff --git a/cssutils/css/__init__.py b/cssutils/css/__init__.py index fb829c99..25e5f3bf 100644 --- a/cssutils/css/__init__.py +++ b/cssutils/css/__init__.py @@ -26,6 +26,7 @@ todo - RGBColor, Rect, Counter """ + __all__ = [ 'CSSStyleSheet', 'CSSRuleList', diff --git a/cssutils/css/csscharsetrule.py b/cssutils/css/csscharsetrule.py index 56c1e1db..a0e537f1 100644 --- a/cssutils/css/csscharsetrule.py +++ b/cssutils/css/csscharsetrule.py @@ -1,4 +1,5 @@ """CSSCharsetRule implements DOM Level 2 CSS CSSCharsetRule.""" + __all__ = ['CSSCharsetRule'] import codecs diff --git a/cssutils/css/csscomment.py b/cssutils/css/csscomment.py index 01e6828d..9a8f4dd3 100644 --- a/cssutils/css/csscomment.py +++ b/cssutils/css/csscomment.py @@ -3,6 +3,7 @@ class only. Implements CSSRule which is also extended for a CSSComment rule type. """ + __all__ = ['CSSComment'] from . import cssrule diff --git a/cssutils/css/cssfontfacerule.py b/cssutils/css/cssfontfacerule.py index 3c3244bb..c7420444 100644 --- a/cssutils/css/cssfontfacerule.py +++ b/cssutils/css/cssfontfacerule.py @@ -3,6 +3,7 @@ From cssutils 0.9.6 additions from CSS Fonts Module Level 3 are added http://www.w3.org/TR/css3-fonts/. """ + __all__ = ['CSSFontFaceRule'] from .cssstyledeclaration import CSSStyleDeclaration diff --git a/cssutils/css/cssimportrule.py b/cssutils/css/cssimportrule.py index e3d4af57..d9915a3b 100644 --- a/cssutils/css/cssimportrule.py +++ b/cssutils/css/cssimportrule.py @@ -1,5 +1,6 @@ """CSSImportRule implements DOM Level 2 CSS CSSImportRule plus the ``name`` property from http://www.w3.org/TR/css3-cascade/#cascading.""" + __all__ = ['CSSImportRule'] from . import cssrule diff --git a/cssutils/css/cssmediarule.py b/cssutils/css/cssmediarule.py index e9ce7369..19d7684d 100644 --- a/cssutils/css/cssmediarule.py +++ b/cssutils/css/cssmediarule.py @@ -1,4 +1,5 @@ """CSSMediaRule implements DOM Level 2 CSS CSSMediaRule.""" + __all__ = ['CSSMediaRule'] from . import cssrule diff --git a/cssutils/css/cssnamespacerule.py b/cssutils/css/cssnamespacerule.py index 01fb4cf8..4af372a9 100644 --- a/cssutils/css/cssnamespacerule.py +++ b/cssutils/css/cssnamespacerule.py @@ -1,5 +1,5 @@ -"""CSSNamespaceRule currently implements http://dev.w3.org/csswg/css3-namespace/ -""" +"""CSSNamespaceRule currently implements http://dev.w3.org/csswg/css3-namespace/""" + __all__ = ['CSSNamespaceRule'] from . import cssrule diff --git a/cssutils/css/csspagerule.py b/cssutils/css/csspagerule.py index 0684d0c8..fa83c7cb 100644 --- a/cssutils/css/csspagerule.py +++ b/cssutils/css/csspagerule.py @@ -1,4 +1,5 @@ """CSSPageRule implements DOM Level 2 CSS CSSPageRule.""" + __all__ = ['CSSPageRule'] from itertools import chain diff --git a/cssutils/css/cssproperties.py b/cssutils/css/cssproperties.py index 44a8a6ec..18500de1 100644 --- a/cssutils/css/cssproperties.py +++ b/cssutils/css/cssproperties.py @@ -46,6 +46,7 @@ and the version is "2.0". """ + __all__ = ['CSS2Properties'] import cssutils.profiles diff --git a/cssutils/css/cssrule.py b/cssutils/css/cssrule.py index 1f2fb195..3b701733 100644 --- a/cssutils/css/cssrule.py +++ b/cssutils/css/cssrule.py @@ -1,4 +1,5 @@ """CSSRule implements DOM Level 2 CSS CSSRule.""" + __all__ = ['CSSRule'] import cssutils diff --git a/cssutils/css/cssrulelist.py b/cssutils/css/cssrulelist.py index 86c1885d..17e08e03 100644 --- a/cssutils/css/cssrulelist.py +++ b/cssutils/css/cssrulelist.py @@ -1,5 +1,6 @@ """CSSRuleList implements DOM Level 2 CSS CSSRuleList. Partly also http://dev.w3.org/csswg/cssom/#the-cssrulelist.""" + __all__ = ['CSSRuleList'] diff --git a/cssutils/css/cssstyledeclaration.py b/cssutils/css/cssstyledeclaration.py index 3ac12421..a33502a2 100644 --- a/cssutils/css/cssstyledeclaration.py +++ b/cssutils/css/cssstyledeclaration.py @@ -49,6 +49,7 @@ background: no-repeat left url() #fff -> background: #fff url() no-repeat left """ + __all__ = ['CSSStyleDeclaration', 'Property'] from .cssproperties import CSS2Properties diff --git a/cssutils/css/cssstylerule.py b/cssutils/css/cssstylerule.py index e98d0e5c..79193ae5 100644 --- a/cssutils/css/cssstylerule.py +++ b/cssutils/css/cssstylerule.py @@ -1,4 +1,5 @@ """CSSStyleRule implements DOM Level 2 CSS CSSStyleRule.""" + __all__ = ['CSSStyleRule'] from .cssstyledeclaration import CSSStyleDeclaration @@ -156,8 +157,9 @@ def _setCssText(self, cssText): # noqa: C901 ) else: braceorEOFtoken = styletokens.pop() - val, typ = self._tokenvalue(braceorEOFtoken), self._type( - braceorEOFtoken + val, typ = ( + self._tokenvalue(braceorEOFtoken), + self._type(braceorEOFtoken), ) if val != '}' and typ != 'EOF': ok = False diff --git a/cssutils/css/cssstylesheet.py b/cssutils/css/cssstylesheet.py index 3ebfe976..c8aa3735 100644 --- a/cssutils/css/cssstylesheet.py +++ b/cssutils/css/cssstylesheet.py @@ -7,6 +7,7 @@ TODO: - ownerRule and ownerNode """ + __all__ = ['CSSStyleSheet'] from cssutils.helper import Deprecated diff --git a/cssutils/css/cssunknownrule.py b/cssutils/css/cssunknownrule.py index 23558c2b..8ad2c7ad 100644 --- a/cssutils/css/cssunknownrule.py +++ b/cssutils/css/cssunknownrule.py @@ -1,4 +1,5 @@ """CSSUnknownRule implements DOM Level 2 CSS CSSUnknownRule.""" + __all__ = ['CSSUnknownRule'] from . import cssrule diff --git a/cssutils/css/cssvalue.py b/cssutils/css/cssvalue.py index a231e499..6a50ac6b 100644 --- a/cssutils/css/cssvalue.py +++ b/cssutils/css/cssvalue.py @@ -5,6 +5,7 @@ - CSSValueList implements DOM Level 2 CSS CSSValueList """ + __all__ = ['CSSValue', 'CSSPrimitiveValue', 'CSSValueList', 'RGBColor', 'CSSVariable'] from cssutils.prodparser import Choice, PreDef, Prod, ProdParser, Sequence diff --git a/cssutils/css/cssvariablesdeclaration.py b/cssutils/css/cssvariablesdeclaration.py index 186bc647..7c022986 100644 --- a/cssutils/css/cssvariablesdeclaration.py +++ b/cssutils/css/cssvariablesdeclaration.py @@ -1,6 +1,7 @@ """CSSVariablesDeclaration http://disruptive-innovations.com/zoo/cssvariables/#mozTocId496530 """ + __all__ = ['CSSVariablesDeclaration'] from cssutils.prodparser import PreDef, Prod, ProdParser, Sequence diff --git a/cssutils/css/cssvariablesrule.py b/cssutils/css/cssvariablesrule.py index 1242ff15..34735e2f 100644 --- a/cssutils/css/cssvariablesrule.py +++ b/cssutils/css/cssvariablesrule.py @@ -1,6 +1,7 @@ """CSSVariables implements (and only partly) experimental `CSS Variables `_ """ + __all__ = ['CSSVariablesRule'] from .cssvariablesdeclaration import CSSVariablesDeclaration diff --git a/cssutils/css/marginrule.py b/cssutils/css/marginrule.py index 7e0fe385..0d88067a 100644 --- a/cssutils/css/marginrule.py +++ b/cssutils/css/marginrule.py @@ -1,4 +1,5 @@ """MarginRule implements DOM Level 2 CSS MarginRule.""" + __all__ = ['MarginRule'] from cssutils.prodparser import Choice, PreDef, Prod, ProdParser, Sequence @@ -170,7 +171,7 @@ def _setCssText(self, cssText): name='@ margin', match=lambda t, v: t == 'ATKEYWORD' and self._normalize(v) in MarginRule.margins, - toStore='margin' + toStore='margin', # TODO? # , exception=xml.dom.InvalidModificationErr ), diff --git a/cssutils/css/property.py b/cssutils/css/property.py index ccfb892e..fbaf107b 100644 --- a/cssutils/css/property.py +++ b/cssutils/css/property.py @@ -1,4 +1,5 @@ """Property is a single CSS property in a CSSStyleDeclaration.""" + __all__ = ['Property'] from cssutils.helper import Deprecated diff --git a/cssutils/css/selector.py b/cssutils/css/selector.py index 22d40edb..7f66a2a2 100644 --- a/cssutils/css/selector.py +++ b/cssutils/css/selector.py @@ -5,6 +5,7 @@ - .contains(selector) - .isSubselector(selector) """ + __all__ = ['Selector'] from cssutils.helper import Deprecated diff --git a/cssutils/css/selectorlist.py b/cssutils/css/selectorlist.py index 968412d7..a3292fad 100644 --- a/cssutils/css/selectorlist.py +++ b/cssutils/css/selectorlist.py @@ -15,6 +15,7 @@ a CSS2 user agent must ignore the whole second line, and not set the color of H3 to red: """ + __all__ = ['SelectorList'] from .selector import Selector diff --git a/cssutils/css/value.py b/cssutils/css/value.py index 25ecebfa..793184a6 100644 --- a/cssutils/css/value.py +++ b/cssutils/css/value.py @@ -3,6 +3,7 @@ DOM Level 2 CSS CSSValue, CSSPrimitiveValue and CSSValueList are **no longer** supported and are replaced by these new classes. """ + __all__ = [ 'PropertyValue', 'Value', diff --git a/cssutils/css2productions.py b/cssutils/css2productions.py index caf8deb3..3eadb95c 100644 --- a/cssutils/css2productions.py +++ b/cssutils/css2productions.py @@ -6,6 +6,7 @@ """ + __all__ = ['CSSProductions', 'MACROS', 'PRODUCTIONS'] # option case-insensitive diff --git a/cssutils/cssproductions.py b/cssutils/cssproductions.py index 46020686..02541266 100644 --- a/cssutils/cssproductions.py +++ b/cssutils/cssproductions.py @@ -10,6 +10,7 @@ CSS2.1: 'nmchar': r'[_a-z0-9-]|{nonascii}|{escape}', CSS3: 'nmchar': r'[_a-z-]|{nonascii}|{escape}', """ + __all__ = ['CSSProductions', 'MACROS', 'PRODUCTIONS'] # a complete list of css3 macros @@ -86,7 +87,7 @@ ('SUBSTRINGMATCH', r'\*\='), ('CDO', r'\<\!\-\-'), ('CDC', r'\-\-\>'), - ('CHAR', r'[^"\']') # MUST always be last + ('CHAR', r'[^"\']'), # MUST always be last # valid ony at start so not checked everytime # ('CHARSET_SYM', r'@charset '), # from Errata includes ending space! # checked specially if fullsheet is parsed diff --git a/cssutils/errorhandler.py b/cssutils/errorhandler.py index cab8e9e5..d249aa68 100644 --- a/cssutils/errorhandler.py +++ b/cssutils/errorhandler.py @@ -13,6 +13,7 @@ - raiseExceptions = [False, True] - setloglevel(loglevel) """ + __all__ = ['ErrorHandler'] import logging @@ -110,6 +111,7 @@ def setLog(self, log): class ErrorHandler(_ErrorHandler): "Singleton, see _ErrorHandler" + instance = None def __init__(self, log=None, defaultloglevel=logging.INFO, raiseExceptions=True): diff --git a/cssutils/helper.py b/cssutils/helper.py index 13ed617c..b967ea4a 100644 --- a/cssutils/helper.py +++ b/cssutils/helper.py @@ -1,5 +1,4 @@ -"""cssutils helper TEST -""" +"""cssutils helper TEST""" import os import re diff --git a/cssutils/parse.py b/cssutils/parse.py index 5cb95e03..f1622207 100644 --- a/cssutils/parse.py +++ b/cssutils/parse.py @@ -1,4 +1,5 @@ """A validating CSSParser""" + __all__ = ['CSSParser'] from .helper import path2url diff --git a/cssutils/prodparser.py b/cssutils/prodparser.py index cb74ae2a..8ef3538b 100644 --- a/cssutils/prodparser.py +++ b/cssutils/prodparser.py @@ -13,6 +13,7 @@ - opt first(), naive impl for now """ + __all__ = ['ProdParser', 'Sequence', 'Choice', 'Prod', 'PreDef'] from .helper import pushtoken diff --git a/cssutils/profiles.py b/cssutils/profiles.py index 9f1ce965..42e88048 100644 --- a/cssutils/profiles.py +++ b/cssutils/profiles.py @@ -114,40 +114,38 @@ def __init__(self, log=None): self._defaultProfiles = None - self.addProfiles( - [ - ( - self.CSS_LEVEL_2, - properties[self.CSS_LEVEL_2], - macros[self.CSS_LEVEL_2], - ), - ( - self.CSS3_BACKGROUNDS_AND_BORDERS, - properties[self.CSS3_BACKGROUNDS_AND_BORDERS], - macros[self.CSS3_BACKGROUNDS_AND_BORDERS], - ), - ( - self.CSS3_BASIC_USER_INTERFACE, - properties[self.CSS3_BASIC_USER_INTERFACE], - macros[self.CSS3_BASIC_USER_INTERFACE], - ), - (self.CSS3_BOX, properties[self.CSS3_BOX], macros[self.CSS3_BOX]), - (self.CSS3_COLOR, properties[self.CSS3_COLOR], macros[self.CSS3_COLOR]), - (self.CSS3_FONTS, properties[self.CSS3_FONTS], macros[self.CSS3_FONTS]), - # new object for font-face only? - ( - self.CSS3_FONT_FACE, - properties[self.CSS3_FONT_FACE], - macros[self.CSS3_FONTS], - ), - ( - self.CSS3_PAGED_MEDIA, - properties[self.CSS3_PAGED_MEDIA], - macros[self.CSS3_PAGED_MEDIA], - ), - (self.CSS3_TEXT, properties[self.CSS3_TEXT], macros[self.CSS3_TEXT]), - ] - ) + self.addProfiles([ + ( + self.CSS_LEVEL_2, + properties[self.CSS_LEVEL_2], + macros[self.CSS_LEVEL_2], + ), + ( + self.CSS3_BACKGROUNDS_AND_BORDERS, + properties[self.CSS3_BACKGROUNDS_AND_BORDERS], + macros[self.CSS3_BACKGROUNDS_AND_BORDERS], + ), + ( + self.CSS3_BASIC_USER_INTERFACE, + properties[self.CSS3_BASIC_USER_INTERFACE], + macros[self.CSS3_BASIC_USER_INTERFACE], + ), + (self.CSS3_BOX, properties[self.CSS3_BOX], macros[self.CSS3_BOX]), + (self.CSS3_COLOR, properties[self.CSS3_COLOR], macros[self.CSS3_COLOR]), + (self.CSS3_FONTS, properties[self.CSS3_FONTS], macros[self.CSS3_FONTS]), + # new object for font-face only? + ( + self.CSS3_FONT_FACE, + properties[self.CSS3_FONT_FACE], + macros[self.CSS3_FONTS], + ), + ( + self.CSS3_PAGED_MEDIA, + properties[self.CSS3_PAGED_MEDIA], + macros[self.CSS3_PAGED_MEDIA], + ), + (self.CSS3_TEXT, properties[self.CSS3_TEXT], macros[self.CSS3_TEXT]), + ]) self.__update_knownNames() diff --git a/cssutils/script.py b/cssutils/script.py index 30f8d6ae..0d0b16de 100644 --- a/cssutils/script.py +++ b/cssutils/script.py @@ -1,5 +1,5 @@ -"""classes and functions used by cssutils scripts -""" +"""classes and functions used by cssutils scripts""" + __all__ = ['CSSCapture', 'csscombine'] import html.parser diff --git a/cssutils/scripts/csscapture.py b/cssutils/scripts/csscapture.py index 5a7cd193..74a7ffe4 100644 --- a/cssutils/scripts/csscapture.py +++ b/cssutils/scripts/csscapture.py @@ -6,6 +6,7 @@ - logger class which handles all cases when no log is given... - saveto: why does urllib2 hang? """ + __all__ = ['CSSCapture'] from cssutils.script import CSSCapture diff --git a/cssutils/scripts/csscombine.py b/cssutils/scripts/csscombine.py index b6d584c7..db4724dd 100644 --- a/cssutils/scripts/csscombine.py +++ b/cssutils/scripts/csscombine.py @@ -50,6 +50,7 @@ } """ + __all__ = ['csscombine'] from cssutils.script import csscombine diff --git a/cssutils/scripts/cssparse.py b/cssutils/scripts/cssparse.py index 9a8f501c..7f61e89f 100644 --- a/cssutils/scripts/cssparse.py +++ b/cssutils/scripts/cssparse.py @@ -1,5 +1,4 @@ -"""utility script to parse given filenames or string -""" +"""utility script to parse given filenames or string""" import cssutils import logging diff --git a/cssutils/serialize.py b/cssutils/serialize.py index ff5775b6..87522b44 100644 --- a/cssutils/serialize.py +++ b/cssutils/serialize.py @@ -1,4 +1,5 @@ """cssutils serializer""" + __all__ = ['CSSSerializer', 'Preferences'] from cssutils.helper import normalize @@ -117,9 +118,9 @@ def __init__(self, **initials): def __repr__(self): return "cssutils.css.{}({})".format( self.__class__.__name__, - ', '.join( - [f'\n {p}={self.__getattribute__(p)!r}' for p in self.__dict__] - ), + ', '.join([ + f'\n {p}={self.__getattribute__(p)!r}' for p in self.__dict__ + ]), ) def __str__(self): @@ -338,12 +339,10 @@ def _indentblock(self, text, level): """ if not self.prefs.lineSeparator: return text - return self.prefs.lineSeparator.join( - [ - f'{level * self.prefs.indent}{line}' - for line in text.split(self.prefs.lineSeparator) - ] - ) + return self.prefs.lineSeparator.join([ + f'{level * self.prefs.indent}{line}' + for line in text.split(self.prefs.lineSeparator) + ]) def _propertyname(self, property, actual): """ diff --git a/cssutils/stylesheets/__init__.py b/cssutils/stylesheets/__init__.py index 81194402..d96ccac1 100644 --- a/cssutils/stylesheets/__init__.py +++ b/cssutils/stylesheets/__init__.py @@ -1,6 +1,7 @@ """Implements Document Object Model Level 2 Style Sheets http://www.w3.org/TR/2000/PR-DOM-Level-2-Style-20000927/stylesheets.html """ + __all__ = ['MediaList', 'MediaQuery', 'StyleSheet', 'StyleSheetList'] from .medialist import MediaList diff --git a/cssutils/stylesheets/medialist.py b/cssutils/stylesheets/medialist.py index a66f58b1..854f73c5 100644 --- a/cssutils/stylesheets/medialist.py +++ b/cssutils/stylesheets/medialist.py @@ -4,6 +4,7 @@ - delete: maybe if deleting from all, replace *all* with all others? - is unknown media an exception? """ + __all__ = ['MediaList'] from cssutils.prodparser import PreDef, Prod, ProdParser, Sequence diff --git a/cssutils/stylesheets/mediaquery.py b/cssutils/stylesheets/mediaquery.py index 938afe48..5fd99de1 100644 --- a/cssutils/stylesheets/mediaquery.py +++ b/cssutils/stylesheets/mediaquery.py @@ -3,6 +3,7 @@ A cssutils implementation, not defined in official DOM. """ + __all__ = ['MediaQuery'] from cssutils.prodparser import Choice, PreDef, Prod, ProdParser, Sequence diff --git a/cssutils/stylesheets/stylesheet.py b/cssutils/stylesheets/stylesheet.py index a6396de2..b2c73691 100644 --- a/cssutils/stylesheets/stylesheet.py +++ b/cssutils/stylesheets/stylesheet.py @@ -1,4 +1,5 @@ """StyleSheet implements DOM Level 2 Style Sheets StyleSheet.""" + __all__ = ['StyleSheet'] import cssutils diff --git a/cssutils/stylesheets/stylesheetlist.py b/cssutils/stylesheets/stylesheetlist.py index f8ed9e42..0ae11e8f 100644 --- a/cssutils/stylesheets/stylesheetlist.py +++ b/cssutils/stylesheets/stylesheetlist.py @@ -1,4 +1,5 @@ """StyleSheetList implements DOM Level 2 Style Sheets StyleSheetList.""" + __all__ = ['StyleSheetList'] diff --git a/cssutils/tests/test_csscomment.py b/cssutils/tests/test_csscomment.py index ef31a49b..7e7e4d9f 100644 --- a/cssutils/tests/test_csscomment.py +++ b/cssutils/tests/test_csscomment.py @@ -27,12 +27,10 @@ def test_csstext(self): '/** / ** //*/': None, } self.do_equal_r(tests) # set cssText - tests.update( - { - '/*x': '/*x*/', - '\n /*': '/**/', - } - ) + tests.update({ + '/*x': '/*x*/', + '\n /*': '/**/', + }) self.do_equal_p(tests) # parse tests = { diff --git a/cssutils/tests/test_cssfontfacerule.py b/cssutils/tests/test_cssfontfacerule.py index ba4e188b..665093a7 100644 --- a/cssutils/tests/test_cssfontfacerule.py +++ b/cssutils/tests/test_cssfontfacerule.py @@ -84,15 +84,13 @@ def test_cssText(self): '@font-face }': xml.dom.SyntaxErr, } self.do_raise_p(tests) # parse - tests.update( - { - '@font-face {': xml.dom.SyntaxErr, # no } - # trailing - '@font-face {}1': xml.dom.SyntaxErr, - '@font-face {}/**/': xml.dom.SyntaxErr, - '@font-face {} ': xml.dom.SyntaxErr, - } - ) + tests.update({ + '@font-face {': xml.dom.SyntaxErr, # no } + # trailing + '@font-face {}1': xml.dom.SyntaxErr, + '@font-face {}/**/': xml.dom.SyntaxErr, + '@font-face {} ': xml.dom.SyntaxErr, + }) self.do_raise_r(tests) # set cssText def test_style(self): diff --git a/cssutils/tests/test_cssimportrule.py b/cssutils/tests/test_cssimportrule.py index 1e429f86..61c533de 100644 --- a/cssutils/tests/test_cssimportrule.py +++ b/cssutils/tests/test_cssimportrule.py @@ -132,15 +132,13 @@ def test_cssText(self): '@import\n\t\f url(\n\t\f "u"\n\t\f )\n\t\f tv\n\t\f "name"\n\t\f ;': '@import url(u) tv "name";', } self.do_equal_r(tests) # set cssText - tests.update( - { - '@import "x.css" tv': '@import "x.css" tv;', - '@import "x.css"': '@import "x.css";', # no ; - "@import 'x.css'": '@import "x.css";', # no ; - '@import url(x.css)': '@import url(x.css);', # no ; - '@import "x;': '@import "x;";', # no "! - } - ) + tests.update({ + '@import "x.css" tv': '@import "x.css" tv;', + '@import "x.css"': '@import "x.css";', # no ; + "@import 'x.css'": '@import "x.css";', # no ; + '@import url(x.css)': '@import url(x.css);', # no ; + '@import "x;': '@import "x;";', # no "! + }) self.do_equal_p(tests) # parse tests = { @@ -154,21 +152,19 @@ def test_cssText(self): '''@import "str" "name" all;''': xml.dom.SyntaxErr, } self.do_raise_p(tests) # parse - tests.update( - { - '@import "x.css"': xml.dom.SyntaxErr, - "@import 'x.css'": xml.dom.SyntaxErr, - '@import url(x.css)': xml.dom.SyntaxErr, - '@import "x.css" tv': xml.dom.SyntaxErr, - '@import "x;': xml.dom.SyntaxErr, - '''@import url("x);''': xml.dom.SyntaxErr, - # trailing - '''@import "x";"a"''': xml.dom.SyntaxErr, - # trailing S or COMMENT - '''@import "x";/**/''': xml.dom.SyntaxErr, - '''@import "x"; ''': xml.dom.SyntaxErr, - } - ) + tests.update({ + '@import "x.css"': xml.dom.SyntaxErr, + "@import 'x.css'": xml.dom.SyntaxErr, + '@import url(x.css)': xml.dom.SyntaxErr, + '@import "x.css" tv': xml.dom.SyntaxErr, + '@import "x;': xml.dom.SyntaxErr, + '''@import url("x);''': xml.dom.SyntaxErr, + # trailing + '''@import "x";"a"''': xml.dom.SyntaxErr, + # trailing S or COMMENT + '''@import "x";/**/''': xml.dom.SyntaxErr, + '''@import "x"; ''': xml.dom.SyntaxErr, + }) self.do_raise_r(tests) # set cssText def test_href(self): diff --git a/cssutils/tests/test_cssnamespacerule.py b/cssutils/tests/test_cssnamespacerule.py index 7009031b..6f56b9be 100644 --- a/cssutils/tests/test_cssnamespacerule.py +++ b/cssutils/tests/test_cssnamespacerule.py @@ -76,8 +76,8 @@ def test_cssText(self): '@namespace/*1*/p/*2*/"u"/*3*/;': '@namespace /*1*/ p /*2*/ "u" /*3*/;', '@namespace p url(u);': '@namespace p "u";', '@namespace p url(\'u\');': '@namespace p "u";', - '@namespace p url(\"u\");': '@namespace p "u";', - '@namespace p url( \"u\" );': '@namespace p "u";', + '@namespace p url("u");': '@namespace p "u";', + '@namespace p url( "u" );': '@namespace p "u";', # comments '@namespace/*1*//*2*/p/*3*//*4*/url(u)/*5*//*6*/;': '@namespace /*1*/ /*2*/ p /*3*/ /*4*/ "u" /*5*/ /*6*/;', '@namespace/*1*//*2*/p/*3*//*4*/"u"/*5*//*6*/;': '@namespace /*1*/ /*2*/ p /*3*/ /*4*/ "u" /*5*/ /*6*/;', @@ -105,17 +105,15 @@ def test_cssText(self): '@namespace p "u";EXTRA': xml.dom.SyntaxErr, } self.do_raise_p(tests) # parse - tests.update( - { - '@namespace p url(x)': xml.dom.SyntaxErr, # missing ; - '@namespace p "u"': xml.dom.SyntaxErr, # missing ; - # trailing - '@namespace "u"; ': xml.dom.SyntaxErr, - '@namespace "u";/**/': xml.dom.SyntaxErr, - '@namespace p "u"; ': xml.dom.SyntaxErr, - '@namespace p "u";/**/': xml.dom.SyntaxErr, - } - ) + tests.update({ + '@namespace p url(x)': xml.dom.SyntaxErr, # missing ; + '@namespace p "u"': xml.dom.SyntaxErr, # missing ; + # trailing + '@namespace "u"; ': xml.dom.SyntaxErr, + '@namespace "u";/**/': xml.dom.SyntaxErr, + '@namespace p "u"; ': xml.dom.SyntaxErr, + '@namespace p "u";/**/': xml.dom.SyntaxErr, + }) def _do(test): cssutils.css.CSSNamespaceRule(cssText=test) diff --git a/cssutils/tests/test_csspagerule.py b/cssutils/tests/test_csspagerule.py index a269d0da..03bba1ff 100644 --- a/cssutils/tests/test_csspagerule.py +++ b/cssutils/tests/test_csspagerule.py @@ -125,19 +125,17 @@ def test_cssText(self): '@page :left }': xml.dom.SyntaxErr, } self.do_raise_p(tests) # parse - tests.update( - { - # false selector - '@page :right :left {}': xml.dom.SyntaxErr, # no } - '@page :right X {}': xml.dom.SyntaxErr, # no } - '@page X Y {}': xml.dom.SyntaxErr, # no } - '@page :left {': xml.dom.SyntaxErr, # no } - # trailing - '@page :left {}1': xml.dom.SyntaxErr, # no } - '@page :left {}/**/': xml.dom.SyntaxErr, # no } - '@page :left {} ': xml.dom.SyntaxErr, # no } - } - ) + tests.update({ + # false selector + '@page :right :left {}': xml.dom.SyntaxErr, # no } + '@page :right X {}': xml.dom.SyntaxErr, # no } + '@page X Y {}': xml.dom.SyntaxErr, # no } + '@page :left {': xml.dom.SyntaxErr, # no } + # trailing + '@page :left {}1': xml.dom.SyntaxErr, # no } + '@page :left {}/**/': xml.dom.SyntaxErr, # no } + '@page :left {} ': xml.dom.SyntaxErr, # no } + }) self.do_raise_r(tests) # set cssText def test_cssText2(self): diff --git a/cssutils/tests/test_cssstylerule.py b/cssutils/tests/test_cssstylerule.py index 2628a05a..5b24d3e0 100644 --- a/cssutils/tests/test_cssstylerule.py +++ b/cssutils/tests/test_cssstylerule.py @@ -150,16 +150,14 @@ def test_cssText(self): '''a }''': xml.dom.SyntaxErr, } self.do_raise_p(tests) # parse - tests.update( - { - '''/*x*/''': xml.dom.SyntaxErr, - '''a {''': xml.dom.SyntaxErr, - # trailing - '''a {}x''': xml.dom.SyntaxErr, - '''a {/**/''': xml.dom.SyntaxErr, - '''a {} ''': xml.dom.SyntaxErr, - } - ) + tests.update({ + '''/*x*/''': xml.dom.SyntaxErr, + '''a {''': xml.dom.SyntaxErr, + # trailing + '''a {}x''': xml.dom.SyntaxErr, + '''a {/**/''': xml.dom.SyntaxErr, + '''a {} ''': xml.dom.SyntaxErr, + }) self.do_raise_r(tests) # set cssText def test_selectorList(self): diff --git a/cssutils/tests/test_cssstylesheet.py b/cssutils/tests/test_cssstylesheet.py index cd5d8025..139f7d9e 100644 --- a/cssutils/tests/test_cssstylesheet.py +++ b/cssutils/tests/test_cssstylesheet.py @@ -152,7 +152,7 @@ def test_cssText(self): } x|test { color: green - }""" + }""", # ur'\1 { \2: \3 }': ur'''\x01 { # \x02: \x03 # }''', @@ -203,7 +203,7 @@ def test_cssText(self): } x|test { color: green - }""" + }""", # ur'\1 { \2: \3 }': ur'''\x01 { # \x02: \x03 # }''', diff --git a/cssutils/tests/test_cssutils.py b/cssutils/tests/test_cssutils.py index 2de75d41..0c8e3295 100644 --- a/cssutils/tests/test_cssutils.py +++ b/cssutils/tests/test_cssutils.py @@ -1,6 +1,5 @@ """Testcases for cssutils.css.CSSCharsetRule""" - from . import basetest import codecs import cssutils @@ -379,7 +378,7 @@ def test_resolveImports(self): assert b'\xc3\xa4{color:red}\xc3\xa4{color:green}' == c.cssText c.encoding = 'ascii' - assert br'@charset "ascii";\E4 {color:red}\E4 {color:green}' == c.cssText + assert rb'@charset "ascii";\E4 {color:red}\E4 {color:green}' == c.cssText # b cannot be found m = mock.Mock() diff --git a/cssutils/tests/test_cssvalue.py b/cssutils/tests/test_cssvalue.py index f62d0aff..44fa5538 100644 --- a/cssutils/tests/test_cssvalue.py +++ b/cssutils/tests/test_cssvalue.py @@ -1,6 +1,5 @@ """Testcases for cssutils.css.CSSValue and CSSPrimitiveValue.""" - import xml.dom from . import basetest import cssutils diff --git a/cssutils/tests/test_encutils.py b/cssutils/tests/test_encutils.py index 91cffac8..8e116abc 100644 --- a/cssutils/tests/test_encutils.py +++ b/cssutils/tests/test_encutils.py @@ -1,6 +1,7 @@ """ tests for encutils.py """ + import http.client from io import StringIO @@ -58,16 +59,16 @@ def test_getTextTypeByMediaType(self): def test_getTextType(self): "encutils._getTextType" tests = { - '\x00\x00\xFE\xFF'), diff --git a/cssutils/tests/test_marginrule.py b/cssutils/tests/test_marginrule.py index e8f8203d..20eaaca3 100644 --- a/cssutils/tests/test_marginrule.py +++ b/cssutils/tests/test_marginrule.py @@ -65,16 +65,14 @@ def test_cssText(self): self.do_equal_r(tests) # TODO - tests.update( - { - # false selector - # u'@top-left { color:': xml.dom.SyntaxErr, # no } - # u'@top-left { color': xml.dom.SyntaxErr, # no } - # u'@top-left {': xml.dom.SyntaxErr, # no } - # u'@top-left': xml.dom.SyntaxErr, # no } - # u'@top-left;': xml.dom.SyntaxErr, # no } - } - ) + tests.update({ + # false selector + # u'@top-left { color:': xml.dom.SyntaxErr, # no } + # u'@top-left { color': xml.dom.SyntaxErr, # no } + # u'@top-left {': xml.dom.SyntaxErr, # no } + # u'@top-left': xml.dom.SyntaxErr, # no } + # u'@top-left;': xml.dom.SyntaxErr, # no } + }) # self.do_raise_r(tests) # set cssText diff --git a/cssutils/tests/test_parse.py b/cssutils/tests/test_parse.py index 0ba65936..08b7f6d6 100644 --- a/cssutils/tests/test_parse.py +++ b/cssutils/tests/test_parse.py @@ -1,6 +1,5 @@ """Tests for parsing which does not raise Exceptions normally""" - import xml.dom import cssutils import urllib.error @@ -433,7 +432,7 @@ def test_escapes(self): sheet = cssutils.parseString(css) assert ( sheet.cssText - == br'''\ x { + == rb'''\ x { \ x: \ x; y: 1 }''' diff --git a/cssutils/tests/test_selector.py b/cssutils/tests/test_selector.py index 44b4b60e..fd2a1d51 100644 --- a/cssutils/tests/test_selector.py +++ b/cssutils/tests/test_selector.py @@ -6,6 +6,7 @@ does not validate but works in IE>5 and FF, does it??? """ + import xml.dom import pytest diff --git a/cssutils/tests/test_util.py b/cssutils/tests/test_util.py index 1af37d12..0a877bea 100644 --- a/cssutils/tests/test_util.py +++ b/cssutils/tests/test_util.py @@ -1,6 +1,5 @@ """Testcases for cssutils.util""" - from email.message import Message import re import urllib.request diff --git a/cssutils/tokenize2.py b/cssutils/tokenize2.py index eecbe574..86477e36 100644 --- a/cssutils/tokenize2.py +++ b/cssutils/tokenize2.py @@ -1,5 +1,5 @@ -"""New CSS Tokenizer (a generator) -""" +"""New CSS Tokenizer (a generator)""" + __all__ = ['Tokenizer', 'CSSProductions'] import itertools diff --git a/cssutils/util.py b/cssutils/util.py index 377d24cb..251f8c71 100644 --- a/cssutils/util.py +++ b/cssutils/util.py @@ -1,5 +1,5 @@ -"""base classes and helper functions for css and stylesheets packages -""" +"""base classes and helper functions for css and stylesheets packages""" + __all__ = [] from .helper import normalize diff --git a/encutils/__init__.py b/encutils/__init__.py index 25b74f40..8953c0bf 100644 --- a/encutils/__init__.py +++ b/encutils/__init__.py @@ -39,6 +39,7 @@ - parse @charset of HTML elements? - check for more texttypes if only text given """ + __all__ = [ 'buildlog', 'encodingByMediaType', @@ -129,13 +130,7 @@ def __init__(self): """Initialize all possible properties to ``None``, see class description """ - self.encoding = ( - self.mismatch - ) = ( - self.logtext - ) = ( - self.http_encoding - ) = ( + self.encoding = self.mismatch = self.logtext = self.http_encoding = ( self.http_media_type ) = self.meta_encoding = self.meta_media_type = self.xml_encoding = None diff --git a/examples/cssencodings.py b/examples/cssencodings.py index bf6405a4..a26f9697 100644 --- a/examples/cssencodings.py +++ b/examples/cssencodings.py @@ -3,6 +3,7 @@ example css is in default UTF-8 encoding """ + from cssutils import CSSParser EXPOUT = '''cssText in different encodings, depending on the console some diff --git a/examples/properties_with_same_name.py b/examples/properties_with_same_name.py index 081c3046..049cd474 100644 --- a/examples/properties_with_same_name.py +++ b/examples/properties_with_same_name.py @@ -1,5 +1,5 @@ -"""shows CSSStyleDeclaration multivalue property examples -""" +"""shows CSSStyleDeclaration multivalue property examples""" + import cssutils print("\n**SameNamePropertyList is replaced with style.getProperties() from 0.9.4**") diff --git a/examples/style.py b/examples/style.py index 0d8b7335..7e79b191 100644 --- a/examples/style.py +++ b/examples/style.py @@ -6,6 +6,7 @@ adds css as text to html """ + import codecs import cssutils import sys diff --git a/examples/testutil.py b/examples/testutil.py index bae6c051..fa567baf 100644 --- a/examples/testutil.py +++ b/examples/testutil.py @@ -6,6 +6,7 @@ - EXPOUT: string which contains expected output - EXPERR: string which contains expected error output """ + __all__ = ['TestUtil'] import logging diff --git a/examples/website.py b/examples/website.py index 44d81197..dc773275 100644 --- a/examples/website.py +++ b/examples/website.py @@ -2,6 +2,7 @@ Log output cannot be tested! """ + import cssutils cssutils.ser.prefs.useDefaults()