diff --git a/cssutils/_fetch.py b/cssutils/_fetch.py index ab96ee9a..31986cae 100644 --- a/cssutils/_fetch.py +++ b/cssutils/_fetch.py @@ -18,7 +18,7 @@ log = errorhandler.ErrorHandler() -@functools.lru_cache() +@functools.lru_cache def _get_version(): try: return metadata.version('cssutils') diff --git a/cssutils/css/csscharsetrule.py b/cssutils/css/csscharsetrule.py index 57b95169..aedd5e52 100644 --- a/cssutils/css/csscharsetrule.py +++ b/cssutils/css/csscharsetrule.py @@ -60,16 +60,10 @@ def __init__( self._readonly = readonly def __repr__(self): - return "cssutils.css.{}(encoding={!r})".format( - self.__class__.__name__, self.encoding - ) + return f"cssutils.css.{self.__class__.__name__}(encoding={self.encoding!r})" def __str__(self): - return "".format( - self.__class__.__name__, - self.encoding, - id(self), - ) + return f"" def _getCssText(self): """The parsable textual representation.""" diff --git a/cssutils/css/csscomment.py b/cssutils/css/csscomment.py index f152d4b4..408afb11 100644 --- a/cssutils/css/csscomment.py +++ b/cssutils/css/csscomment.py @@ -34,16 +34,10 @@ def __init__( self._readonly = readonly def __repr__(self): - return "cssutils.css.{}(cssText={!r})".format( - self.__class__.__name__, self.cssText - ) + return f"cssutils.css.{self.__class__.__name__}(cssText={self.cssText!r})" def __str__(self): - return "".format( - self.__class__.__name__, - self.cssText, - id(self), - ) + return f"" def _getCssText(self): """Return serialized property cssText.""" diff --git a/cssutils/css/cssfontfacerule.py b/cssutils/css/cssfontfacerule.py index c9accdae..b56f722b 100644 --- a/cssutils/css/cssfontfacerule.py +++ b/cssutils/css/cssfontfacerule.py @@ -54,18 +54,10 @@ def __init__( self._readonly = readonly def __repr__(self): - return "cssutils.css.{}(style={!r})".format( - self.__class__.__name__, - self.style.cssText, - ) + return f"cssutils.css.{self.__class__.__name__}(style={self.style.cssText!r})" def __str__(self): - return "".format( - self.__class__.__name__, - self.style.cssText, - self.valid, - id(self), - ) + return f"" def _getCssText(self): """Return serialized property cssText.""" diff --git a/cssutils/css/cssimportrule.py b/cssutils/css/cssimportrule.py index 1d5802dd..1697cea9 100644 --- a/cssutils/css/cssimportrule.py +++ b/cssutils/css/cssimportrule.py @@ -77,25 +77,14 @@ def __repr__(self): mediaText = self.media.mediaText else: mediaText = None - return "cssutils.css.{}(href={!r}, mediaText={!r}, name={!r})".format( - self.__class__.__name__, - self.href, - mediaText, - self.name, - ) + return f"cssutils.css.{self.__class__.__name__}(href={self.href!r}, mediaText={mediaText!r}, name={self.name!r})" def __str__(self): if self._usemedia: mediaText = self.media.mediaText else: mediaText = None - return "".format( - self.__class__.__name__, - self.href, - mediaText, - self.name, - id(self), - ) + return f"" _usemedia = property( lambda self: self.media.mediaText not in ('', 'all'), diff --git a/cssutils/css/cssmediarule.py b/cssutils/css/cssmediarule.py index f275a9a7..5567d70f 100644 --- a/cssutils/css/cssmediarule.py +++ b/cssutils/css/cssmediarule.py @@ -49,17 +49,10 @@ def __init__( self._readonly = readonly def __repr__(self): - return "cssutils.css.{}(mediaText={!r})".format( - self.__class__.__name__, - self.media.mediaText, - ) + return f"cssutils.css.{self.__class__.__name__}(mediaText={self.media.mediaText!r})" def __str__(self): - return "".format( - self.__class__.__name__, - self.media.mediaText, - id(self), - ) + return f"" def _getCssText(self): """Return serialized property cssText.""" diff --git a/cssutils/css/cssnamespacerule.py b/cssutils/css/cssnamespacerule.py index 7c8cba27..7a2aa510 100644 --- a/cssutils/css/cssnamespacerule.py +++ b/cssutils/css/cssnamespacerule.py @@ -91,20 +91,11 @@ def __init__( self._readonly = readonly def __repr__(self): - return "cssutils.css.{}(namespaceURI={!r}, prefix={!r})".format( - self.__class__.__name__, - self.namespaceURI, - self.prefix, - ) + return f"cssutils.css.{self.__class__.__name__}(namespaceURI={self.namespaceURI!r}, prefix={self.prefix!r})" def __str__(self): return ( - "".format( - self.__class__.__name__, - self.namespaceURI, - self.prefix, - id(self), - ) + f"" ) def _getCssText(self): diff --git a/cssutils/css/csspagerule.py b/cssutils/css/csspagerule.py index acfeb517..953aa634 100644 --- a/cssutils/css/csspagerule.py +++ b/cssutils/css/csspagerule.py @@ -95,11 +95,7 @@ def __init__( self._readonly = readonly def __repr__(self): - return "cssutils.css.{}(selectorText={!r}, style={!r})".format( - self.__class__.__name__, - self.selectorText, - self.style.cssText, - ) + return f"cssutils.css.{self.__class__.__name__}(selectorText={self.selectorText!r}, style={self.style.cssText!r})" def __str__(self): return ( diff --git a/cssutils/css/cssrule.py b/cssutils/css/cssrule.py index ab32b4c9..2fd30adc 100644 --- a/cssutils/css/cssrule.py +++ b/cssutils/css/cssrule.py @@ -80,9 +80,7 @@ def _setAtkeyword(self, keyword): self._keyword = keyword else: self._log.error( - '{}: Invalid atkeyword for this rule: {!r}'.format( - self.atkeyword, keyword - ), + f'{self.atkeyword}: Invalid atkeyword for this rule: {keyword!r}', error=xml.dom.InvalidModificationErr, ) diff --git a/cssutils/css/cssstyledeclaration.py b/cssutils/css/cssstyledeclaration.py index d4339261..bdf336fa 100644 --- a/cssutils/css/cssstyledeclaration.py +++ b/cssutils/css/cssstyledeclaration.py @@ -209,12 +209,7 @@ def __repr__(self): ) def __str__(self): - return "".format( - self.__class__.__name__, - self.length, - len(self.getProperties(all=True)), - id(self), - ) + return f"" def __nnames(self): """Return iterator for all different names in order as set diff --git a/cssutils/css/cssstylerule.py b/cssutils/css/cssstylerule.py index a585e0d1..08a8226e 100644 --- a/cssutils/css/cssstylerule.py +++ b/cssutils/css/cssstylerule.py @@ -58,11 +58,7 @@ def __repr__(self): st = (self.selectorText, self._namespaces) else: st = self.selectorText - return "cssutils.css.{}(selectorText={!r}, style={!r})".format( - self.__class__.__name__, - st, - self.style.cssText, - ) + return f"cssutils.css.{self.__class__.__name__}(selectorText={st!r}, style={self.style.cssText!r})" def __str__(self): return ( diff --git a/cssutils/css/cssstylesheet.py b/cssutils/css/cssstylesheet.py index 41fdbc4c..b4bc4c6b 100644 --- a/cssutils/css/cssstylesheet.py +++ b/cssutils/css/cssstylesheet.py @@ -80,12 +80,7 @@ def __repr__(self): mediaText = self.media.mediaText else: mediaText = None - return "cssutils.css.{}(href={!r}, media={!r}, title={!r})".format( - self.__class__.__name__, - self.href, - mediaText, - self.title, - ) + return f"cssutils.css.{self.__class__.__name__}(href={self.href!r}, media={mediaText!r}, title={self.title!r})" def __str__(self): if self.media: diff --git a/cssutils/css/cssunknownrule.py b/cssutils/css/cssunknownrule.py index e82e5c25..3aa28aa7 100644 --- a/cssutils/css/cssunknownrule.py +++ b/cssutils/css/cssunknownrule.py @@ -34,16 +34,10 @@ def __init__( self._readonly = readonly def __repr__(self): - return "cssutils.css.{}(cssText={!r})".format( - self.__class__.__name__, self.cssText - ) + return f"cssutils.css.{self.__class__.__name__}(cssText={self.cssText!r})" def __str__(self): - return "".format( - self.__class__.__name__, - self.cssText, - id(self), - ) + return f"" def _getCssText(self): """Return serialized property cssText.""" diff --git a/cssutils/css/cssvalue.py b/cssutils/css/cssvalue.py index a521398c..c88e7849 100644 --- a/cssutils/css/cssvalue.py +++ b/cssutils/css/cssvalue.py @@ -561,12 +561,7 @@ def __init__(self, cssText=None, parent=None, readonly=False): def __str__(self): return ( - "".format( - self.__class__.__name__, - self.primitiveTypeString, - self.cssText, - id(self), - ) + f"" ) _unitnames = [ @@ -1137,12 +1132,7 @@ def __repr__(self): return f"cssutils.css.{self.__class__.__name__}({self.cssText!r})" def __str__(self): - return "".format( - self.__class__.__name__, - self.colorType, - self.cssText, - id(self), - ) + return f"" def _setCssText(self, cssText): self._checkReadonly() @@ -1318,12 +1308,7 @@ def __repr__(self): return f"cssutils.css.{self.__class__.__name__}({self.cssText!r})" def __str__(self): - return "".format( - self.__class__.__name__, - self.name, - self.value, - id(self), - ) + return f"" def _setCssText(self, cssText): self._checkReadonly() diff --git a/cssutils/css/cssvariablesdeclaration.py b/cssutils/css/cssvariablesdeclaration.py index ab6aa53c..c5e1c107 100644 --- a/cssutils/css/cssvariablesdeclaration.py +++ b/cssutils/css/cssvariablesdeclaration.py @@ -51,16 +51,10 @@ def __init__(self, cssText='', parentRule=None, readonly=False): self._readonly = readonly def __repr__(self): - return "cssutils.css.{}(cssText={!r})".format( - self.__class__.__name__, self.cssText - ) + return f"cssutils.css.{self.__class__.__name__}(cssText={self.cssText!r})" def __str__(self): - return "".format( - self.__class__.__name__, - self.length, - id(self), - ) + return f"" def __contains__(self, variableName): """Check if a variable is in variable declaration block. diff --git a/cssutils/css/cssvariablesrule.py b/cssutils/css/cssvariablesrule.py index f1bda283..ddc87960 100644 --- a/cssutils/css/cssvariablesrule.py +++ b/cssutils/css/cssvariablesrule.py @@ -69,11 +69,7 @@ def __init__( self._readonly = readonly def __repr__(self): - return "cssutils.css.{}(mediaText={!r}, variables={!r})".format( - self.__class__.__name__, - self._media.mediaText, - self.variables.cssText, - ) + return f"cssutils.css.{self.__class__.__name__}(mediaText={self._media.mediaText!r}, variables={self.variables.cssText!r})" def __str__(self): return ( diff --git a/cssutils/css/marginrule.py b/cssutils/css/marginrule.py index 12a87c82..2f6a556b 100644 --- a/cssutils/css/marginrule.py +++ b/cssutils/css/marginrule.py @@ -102,9 +102,7 @@ def _setMargin(self, margin): if n not in MarginRule.margins: self._log.error( - 'Invalid margin @keyword for this {} rule: {!r}'.format( - self.margin, margin - ), + f'Invalid margin @keyword for this {self.margin} rule: {margin!r}', error=xml.dom.InvalidModificationErr, ) @@ -123,11 +121,7 @@ def _setMargin(self, margin): atkeyword = margin def __repr__(self): - return "cssutils.css.{}(margin={!r}, style={!r})".format( - self.__class__.__name__, - self.margin, - self.style.cssText, - ) + return f"cssutils.css.{self.__class__.__name__}(margin={self.margin!r}, style={self.style.cssText!r})" def __str__(self): return "" % ( diff --git a/cssutils/css/property.py b/cssutils/css/property.py index e0b88ba7..5d4d3eae 100644 --- a/cssutils/css/property.py +++ b/cssutils/css/property.py @@ -81,23 +81,10 @@ def __init__( self.priority = priority def __repr__(self): - return "cssutils.css.{}(name={!r}, value={!r}, priority={!r})".format( - self.__class__.__name__, - self.literalname, - self.propertyValue.cssText, - self.priority, - ) + return f"cssutils.css.{self.__class__.__name__}(name={self.literalname!r}, value={self.propertyValue.cssText!r}, priority={self.priority!r})" def __str__(self): - return "<{}.{} object name={!r} value={!r} priority={!r} valid={!r} at 0x{:x}>".format( - self.__class__.__module__, - self.__class__.__name__, - self.name, - self.propertyValue.cssText, - self.priority, - self.valid, - id(self), - ) + return f"<{self.__class__.__module__}.{self.__class__.__name__} object name={self.name!r} value={self.propertyValue.cssText!r} priority={self.priority!r} valid={self.valid!r} at 0x{id(self):x}>" def _isValidating(self): """Return True if validation is enabled.""" diff --git a/cssutils/css/value.py b/cssutils/css/value.py index b9c4c8c0..2a4d2de6 100644 --- a/cssutils/css/value.py +++ b/cssutils/css/value.py @@ -260,13 +260,7 @@ def __repr__(self): def __str__(self): return ( - "".format( - self.__class__.__name__, - self.type, - self.value, - self.cssText, - id(self), - ) + f"" ) def _setCssText(self, cssText): @@ -611,14 +605,7 @@ class URIValue(Value): _uri = Value._value def __str__(self): - return "".format( - self.__class__.__name__, - self.type, - self.value, - self.uri, - self.cssText, - id(self), - ) + return f"" def _setCssText(self, cssText): self._checkReadonly() @@ -795,9 +782,7 @@ class CSSCalc(CSSFunction): _functionName = 'CSSCalc' def __str__(self): - return "".format( - self.__class__.__name__, id(self) - ) + return f"" def _setCssText(self, cssText): self._checkReadonly() @@ -878,12 +863,7 @@ class CSSVariable(CSSFunction): _fallback = None def __str__(self): - return "".format( - self.__class__.__name__, - self.name, - self.value, - id(self), - ) + return f"" def _setCssText(self, cssText): self._checkReadonly() diff --git a/cssutils/prodparser.py b/cssutils/prodparser.py index feb52f51..4be27127 100644 --- a/cssutils/prodparser.py +++ b/cssutils/prodparser.py @@ -121,12 +121,7 @@ def nextProd(self, token): raise Exhausted('Extra token') def __repr__(self): - return "".format( - self.__class__.__name__, - self.__str__(), - self.optional, - id(self), - ) + return f"" def __str__(self): return 'Choice(%s)' % ', '.join([str(x) for x in self._prods]) @@ -241,12 +236,7 @@ def nextProd(self, token): raise Exhausted('Extra token') def __repr__(self): - return "".format( - self.__class__.__name__, - self.__str__(), - self.optional, - id(self), - ) + return f"" def __str__(self): return 'Sequence(%s)' % ', '.join([str(x) for x in self._prods]) @@ -361,11 +351,7 @@ def __str__(self): return self._name def __repr__(self): - return "".format( - self.__class__.__name__, - self._name, - id(self), - ) + return f"" # global tokenizer as there is only one! diff --git a/cssutils/stylesheets/medialist.py b/cssutils/stylesheets/medialist.py index 35f14a9b..6c14725b 100644 --- a/cssutils/stylesheets/medialist.py +++ b/cssutils/stylesheets/medialist.py @@ -56,17 +56,10 @@ def __init__(self, mediaText=None, parentRule=None, readonly=False): self._readonly = readonly def __repr__(self): - return "cssutils.stylesheets.{}(mediaText={!r})".format( - self.__class__.__name__, - self.mediaText, - ) + return f"cssutils.stylesheets.{self.__class__.__name__}(mediaText={self.mediaText!r})" def __str__(self): - return "".format( - self.__class__.__name__, - self.mediaText, - id(self), - ) + return f"" def __iter__(self): for item in self._seq: diff --git a/cssutils/stylesheets/mediaquery.py b/cssutils/stylesheets/mediaquery.py index d2ec75ad..2362bb60 100644 --- a/cssutils/stylesheets/mediaquery.py +++ b/cssutils/stylesheets/mediaquery.py @@ -68,17 +68,10 @@ def __init__(self, mediaText=None, readonly=False, _partof=False): self._readonly = readonly def __repr__(self): - return "cssutils.stylesheets.{}(mediaText={!r})".format( - self.__class__.__name__, - self.mediaText, - ) + return f"cssutils.stylesheets.{self.__class__.__name__}(mediaText={self.mediaText!r})" def __str__(self): - return "".format( - self.__class__.__name__, - self.mediaText, - id(self), - ) + return f"" def _getMediaText(self): return cssutils.ser.do_stylesheets_mediaquery(self) diff --git a/cssutils/tests/test_codec.py b/cssutils/tests/test_codec.py index bf00958a..8fffbd0f 100644 --- a/cssutils/tests/test_codec.py +++ b/cssutils/tests/test_codec.py @@ -73,16 +73,16 @@ def test_detectencoding_str(self): "utf-32", True, ) - assert codec.detectencoding_str('\x00'.encode()) == (None, False) - assert codec.detectencoding_str('\x00\x33'.encode()) == ("utf-8", False) - assert codec.detectencoding_str('\x00\x00'.encode()) == (None, False) - assert codec.detectencoding_str('\x00\x00\x33'.encode()) == ("utf-8", False) + assert codec.detectencoding_str(b'\x00') == (None, False) + assert codec.detectencoding_str(b'\x00\x33') == ("utf-8", False) + assert codec.detectencoding_str(b'\x00\x00') == (None, False) + assert codec.detectencoding_str(b'\x00\x00\x33') == ("utf-8", False) assert codec.detectencoding_str(b'\x00\x00\xfe') == ( None, False, ) - assert codec.detectencoding_str('\x00\x00\x00\x33'.encode()) == ("utf-8", False) - assert codec.detectencoding_str('\x00\x00\x00@'.encode()) == ( + assert codec.detectencoding_str(b'\x00\x00\x00\x33') == ("utf-8", False) + assert codec.detectencoding_str(b'\x00\x00\x00@') == ( "utf-32-be", False, ) @@ -91,12 +91,12 @@ def test_detectencoding_str(self): True, ) assert codec.detectencoding_str(b'@') == (None, False) - assert codec.detectencoding_str('@\x33'.encode()) == ("utf-8", False) - assert codec.detectencoding_str('@\x00'.encode()) == (None, False) - assert codec.detectencoding_str('@\x00\x33'.encode()) == ("utf-8", False) - assert codec.detectencoding_str('@\x00\x00'.encode()) == (None, False) - assert codec.detectencoding_str('@\x00\x00\x33'.encode()) == ("utf-8", False) - assert codec.detectencoding_str('@\x00\x00\x00'.encode()) == ( + assert codec.detectencoding_str(b'@\x33') == ("utf-8", False) + assert codec.detectencoding_str(b'@\x00') == (None, False) + assert codec.detectencoding_str(b'@\x00\x33') == ("utf-8", False) + assert codec.detectencoding_str(b'@\x00\x00') == (None, False) + assert codec.detectencoding_str(b'@\x00\x00\x33') == ("utf-8", False) + assert codec.detectencoding_str(b'@\x00\x00\x00') == ( "utf-32-le", False, ) diff --git a/cssutils/tests/test_parse.py b/cssutils/tests/test_parse.py index 4ce1ffe9..effb897f 100644 --- a/cssutils/tests/test_parse.py +++ b/cssutils/tests/test_parse.py @@ -425,9 +425,9 @@ def test_escapes(self): sheet = cssutils.parseString(css) assert ( sheet.cssText - == r'''C\x { + == br'''C\x { c\x: C\x !important - }'''.encode() + }''' ) css = r'\ x{\ x :\ x ;y:1} ' diff --git a/cssutils/util.py b/cssutils/util.py index 7c0f789d..66c43e45 100644 --- a/cssutils/util.py +++ b/cssutils/util.py @@ -593,14 +593,7 @@ def __str__(self): else: vals.append(repr(v)) - return "".format( - self.__module__, - self.__class__.__name__, - len(self), - vals, - self._readonly, - id(self), - ) + return f"" def __delitem__(self, i): del self._seq[i] @@ -696,14 +689,7 @@ def __init__(self, value, type, line=None, col=None): col = property(lambda self: self.__col) def __repr__(self): - return "{}.{}(value={!r}, type={!r}, line={!r}, col={!r})".format( - self.__module__, - self.__class__.__name__, - self.__value, - self.__type, - self.__line, - self.__col, - ) + return f"{self.__module__}.{self.__class__.__name__}(value={self.__value!r}, type={self.__type!r}, line={self.__line!r}, col={self.__col!r})" class ListSeq: @@ -872,11 +858,7 @@ def prefixForNamespaceURI(self, namespaceURI): raise IndexError('NamespaceURI %s not found.' % namespaceURI) def __str__(self): - return "".format( - self.__class__.__name__, - str(self.parentStyleSheet), - id(self), - ) + return f"" class _SimpleNamespaces(_Namespaces): @@ -899,11 +881,7 @@ def namespaces(self): return self.__namespaces def __str__(self): - return "".format( - self.__class__.__name__, - self.namespaces, - id(self), - ) + return f"" def __repr__(self): return f"cssutils.util.{self.__class__.__name__}({self.namespaces!r})" diff --git a/encutils/__init__.py b/encutils/__init__.py index efd7c6a2..9a4ddc07 100644 --- a/encutils/__init__.py +++ b/encutils/__init__.py @@ -142,13 +142,7 @@ def __str__(self): return '' def __repr__(self): - return "<{}.{} object encoding={!r} mismatch={} at 0x{:x}>".format( - self.__class__.__module__, - self.__class__.__name__, - self.encoding, - self.mismatch, - id(self), - ) + return f"<{self.__class__.__module__}.{self.__class__.__name__} object encoding={self.encoding!r} mismatch={self.mismatch} at 0x{id(self):x}>" def buildlog( diff --git a/tools/try.py b/tools/try.py index 8af7e0ec..d6f3167a 100644 --- a/tools/try.py +++ b/tools/try.py @@ -741,9 +741,7 @@ def f(url): if vi.cssValueType == vi.CSS_VARIABLE: if vi.value: print( - '+ CSSValueList: Replacing {!r} with {!r}'.format( - p.value, vi.value - ) + f'+ CSSValueList: Replacing {p.value!r} with {vi.value!r}' ) newvalue.append(vi.value) else: