diff --git a/cssutils/_fetch.py b/cssutils/_fetch.py index 9c6f5668..e3c6be9b 100644 --- a/cssutils/_fetch.py +++ b/cssutils/_fetch.py @@ -17,7 +17,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 a0e537f1..6fd7e558 100644 --- a/cssutils/css/csscharsetrule.py +++ b/cssutils/css/csscharsetrule.py @@ -58,16 +58,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 9a8f4dd3..de12fd46 100644 --- a/cssutils/css/csscomment.py +++ b/cssutils/css/csscomment.py @@ -32,16 +32,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 c7420444..e25c440f 100644 --- a/cssutils/css/cssfontfacerule.py +++ b/cssutils/css/cssfontfacerule.py @@ -52,18 +52,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 d9915a3b..f4bbc780 100644 --- a/cssutils/css/cssimportrule.py +++ b/cssutils/css/cssimportrule.py @@ -75,25 +75,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 19d7684d..979b9bfa 100644 --- a/cssutils/css/cssmediarule.py +++ b/cssutils/css/cssmediarule.py @@ -47,17 +47,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 4af372a9..b687b458 100644 --- a/cssutils/css/cssnamespacerule.py +++ b/cssutils/css/cssnamespacerule.py @@ -89,20 +89,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 fa83c7cb..f236f06d 100644 --- a/cssutils/css/csspagerule.py +++ b/cssutils/css/csspagerule.py @@ -93,11 +93,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 3b701733..d74f9b42 100644 --- a/cssutils/css/cssrule.py +++ b/cssutils/css/cssrule.py @@ -79,9 +79,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 558c4956..ce1811b9 100644 --- a/cssutils/css/cssstyledeclaration.py +++ b/cssutils/css/cssstyledeclaration.py @@ -208,12 +208,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 79193ae5..092ff96c 100644 --- a/cssutils/css/cssstylerule.py +++ b/cssutils/css/cssstylerule.py @@ -56,11 +56,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 c8aa3735..f17e4800 100644 --- a/cssutils/css/cssstylesheet.py +++ b/cssutils/css/cssstylesheet.py @@ -78,12 +78,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 8ad2c7ad..3f8650c0 100644 --- a/cssutils/css/cssunknownrule.py +++ b/cssutils/css/cssunknownrule.py @@ -32,16 +32,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 6a50ac6b..23d17122 100644 --- a/cssutils/css/cssvalue.py +++ b/cssutils/css/cssvalue.py @@ -560,12 +560,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 = [ @@ -1136,12 +1131,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() @@ -1317,12 +1307,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 7c022986..0543262a 100644 --- a/cssutils/css/cssvariablesdeclaration.py +++ b/cssutils/css/cssvariablesdeclaration.py @@ -49,16 +49,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 34735e2f..5fe66f06 100644 --- a/cssutils/css/cssvariablesrule.py +++ b/cssutils/css/cssvariablesrule.py @@ -67,11 +67,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 0d88067a..d486a247 100644 --- a/cssutils/css/marginrule.py +++ b/cssutils/css/marginrule.py @@ -100,9 +100,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, ) @@ -121,11 +119,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 fbaf107b..7408506e 100644 --- a/cssutils/css/property.py +++ b/cssutils/css/property.py @@ -80,23 +80,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 793184a6..9fa90e64 100644 --- a/cssutils/css/value.py +++ b/cssutils/css/value.py @@ -259,13 +259,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): @@ -610,14 +604,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() @@ -794,9 +781,7 @@ class CSSCalc(CSSFunction): _functionName = 'CSSCalc' def __str__(self): - return "".format( - self.__class__.__name__, id(self) - ) + return f"" def _setCssText(self, cssText): self._checkReadonly() @@ -877,12 +862,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 8ef3538b..bf1961f2 100644 --- a/cssutils/prodparser.py +++ b/cssutils/prodparser.py @@ -119,12 +119,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]) @@ -239,12 +234,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]) @@ -359,11 +349,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 854f73c5..355e8338 100644 --- a/cssutils/stylesheets/medialist.py +++ b/cssutils/stylesheets/medialist.py @@ -54,17 +54,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 5fd99de1..8ccb231a 100644 --- a/cssutils/stylesheets/mediaquery.py +++ b/cssutils/stylesheets/mediaquery.py @@ -67,17 +67,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 08b7f6d6..e007027a 100644 --- a/cssutils/tests/test_parse.py +++ b/cssutils/tests/test_parse.py @@ -423,9 +423,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 251f8c71..fbbd2998 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 8953c0bf..77226c7a 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 0b4b3b17..02b6f864 100644 --- a/tools/try.py +++ b/tools/try.py @@ -740,9 +740,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: