Skip to content

Commit 57179fe

Browse files
committed
Ran pyupgrade to Python 3.7+ (then fade to black).
1 parent 9ea9176 commit 57179fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+516
-561
lines changed

cssutils/_fetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _defaultFetcher(url):
2929
res = urllib.request.urlopen(request)
3030
except urllib.error.HTTPError as e:
3131
# http error, e.g. 404, e can be raised
32-
log.warn('HTTPError opening url=%s: %s %s' % (url, e.code, e.msg), error=e)
32+
log.warn(f'HTTPError opening url={url}: {e.code} {e.msg}', error=e)
3333
except urllib.error.URLError as e:
3434
# URLError like mailto: or other IO errors, e can be raised
3535
log.warn('URLError, %s' % e.reason, error=e)

cssutils/_fetchgae.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _defaultFetcher(url):
4545
try:
4646
r = urlfetch.fetch(url, method=urlfetch.GET)
4747
except urlfetch.Error as e:
48-
log.warn('Error opening url=%r: %s' % (url, e), error=IOError)
48+
log.warn(f'Error opening url={url!r}: {e}', error=IOError)
4949
else:
5050
if r.status_code == 200:
5151
# find mimetype and encoding
@@ -65,6 +65,6 @@ def _defaultFetcher(url):
6565
else:
6666
# TODO: 301 etc
6767
log.warn(
68-
'Error opening url=%r: HTTP status %s' % (url, r.status_code),
68+
f'Error opening url={url!r}: HTTP status {r.status_code}',
6969
error=IOError,
7070
)

cssutils/css/csscharsetrule.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ def __init__(
4646
:param readonly:
4747
defaults to False, not used yet
4848
"""
49-
super(CSSCharsetRule, self).__init__(
50-
parentRule=parentRule, parentStyleSheet=parentStyleSheet
51-
)
49+
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
5250
self._atkeyword = '@charset'
5351

5452
if encoding:
@@ -59,10 +57,12 @@ def __init__(
5957
self._readonly = readonly
6058

6159
def __repr__(self):
62-
return "cssutils.css.%s(encoding=%r)" % (self.__class__.__name__, self.encoding)
60+
return "cssutils.css.{}(encoding={!r})".format(
61+
self.__class__.__name__, self.encoding
62+
)
6363

6464
def __str__(self):
65-
return "<cssutils.css.%s object encoding=%r at 0x%x>" % (
65+
return "<cssutils.css.{} object encoding={!r} at 0x{:x}>".format(
6666
self.__class__.__name__,
6767
self.encoding,
6868
id(self),
@@ -89,7 +89,7 @@ def _setCssText(self, cssText):
8989
- :exc:`~xml.dom.NoModificationAllowedErr`:
9090
Raised if the rule is readonly.
9191
"""
92-
super(CSSCharsetRule, self)._setCssText(cssText)
92+
super()._setCssText(cssText)
9393

9494
wellformed = True
9595
tokenizer = self._tokenize2(cssText)

cssutils/css/csscomment.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ class CSSComment(cssrule.CSSRule):
2222
def __init__(
2323
self, cssText=None, parentRule=None, parentStyleSheet=None, readonly=False
2424
):
25-
super(CSSComment, self).__init__(
26-
parentRule=parentRule, parentStyleSheet=parentStyleSheet
27-
)
25+
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
2826

2927
self._cssText = None
3028
if cssText:
@@ -33,10 +31,12 @@ def __init__(
3331
self._readonly = readonly
3432

3533
def __repr__(self):
36-
return "cssutils.css.%s(cssText=%r)" % (self.__class__.__name__, self.cssText)
34+
return "cssutils.css.{}(cssText={!r})".format(
35+
self.__class__.__name__, self.cssText
36+
)
3737

3838
def __str__(self):
39-
return "<cssutils.css.%s object cssText=%r at 0x%x>" % (
39+
return "<cssutils.css.{} object cssText={!r} at 0x{:x}>".format(
4040
self.__class__.__name__,
4141
self.cssText,
4242
id(self),
@@ -62,7 +62,7 @@ def _setCssText(self, cssText):
6262
- :exc:`~xml.dom.NoModificationAllowedErr`:
6363
Raised if the rule is readonly.
6464
"""
65-
super(CSSComment, self)._setCssText(cssText)
65+
super()._setCssText(cssText)
6666
tokenizer = self._tokenize2(cssText)
6767

6868
commenttoken = self._nexttoken(tokenizer)

cssutils/css/cssfontfacerule.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def __init__(
4040
CSSStyleDeclaration used to hold any font descriptions
4141
for this CSSFontFaceRule
4242
"""
43-
super(CSSFontFaceRule, self).__init__(
44-
parentRule=parentRule, parentStyleSheet=parentStyleSheet
45-
)
43+
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
4644
self._atkeyword = '@font-face'
4745

4846
if style:
@@ -53,13 +51,13 @@ def __init__(
5351
self._readonly = readonly
5452

5553
def __repr__(self):
56-
return "cssutils.css.%s(style=%r)" % (
54+
return "cssutils.css.{}(style={!r})".format(
5755
self.__class__.__name__,
5856
self.style.cssText,
5957
)
6058

6159
def __str__(self):
62-
return "<cssutils.css.%s object style=%r valid=%r at 0x%x>" % (
60+
return "<cssutils.css.{} object style={!r} valid={!r} at 0x{:x}>".format(
6361
self.__class__.__name__,
6462
self.style.cssText,
6563
self.valid,
@@ -85,7 +83,7 @@ def _setCssText(self, cssText):
8583
- :exc:`~xml.dom.NoModificationAllowedErr`:
8684
Raised if the rule is readonly.
8785
"""
88-
super(CSSFontFaceRule, self)._setCssText(cssText)
86+
super()._setCssText(cssText)
8987

9088
tokenizer = self._tokenize2(cssText)
9189
attoken = self._nexttoken(tokenizer, None)

cssutils/css/cssimportrule.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ def __init__(
4242
:param name:
4343
Additional name of imported style sheet
4444
"""
45-
super(CSSImportRule, self).__init__(
46-
parentRule=parentRule, parentStyleSheet=parentStyleSheet
47-
)
45+
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
4846
self._atkeyword = '@import'
4947
self._styleSheet = None
5048

@@ -76,7 +74,7 @@ def __repr__(self):
7674
mediaText = self.media.mediaText
7775
else:
7876
mediaText = None
79-
return "cssutils.css.%s(href=%r, mediaText=%r, name=%r)" % (
77+
return "cssutils.css.{}(href={!r}, mediaText={!r}, name={!r})".format(
8078
self.__class__.__name__,
8179
self.href,
8280
mediaText,
@@ -88,7 +86,7 @@ def __str__(self):
8886
mediaText = self.media.mediaText
8987
else:
9088
mediaText = None
91-
return "<cssutils.css.%s object href=%r mediaText=%r name=%r at 0x%x>" % (
89+
return "<cssutils.css.{} object href={!r} mediaText={!r} name={!r} at 0x{:x}>".format(
9290
self.__class__.__name__,
9391
self.href,
9492
mediaText,
@@ -120,7 +118,7 @@ def _setCssText(self, cssText): # noqa: C901
120118
Raised if the specified CSS string value has a syntax error and
121119
is unparsable.
122120
"""
123-
super(CSSImportRule, self)._setCssText(cssText)
121+
super()._setCssText(cssText)
124122
tokenizer = self._tokenize2(cssText)
125123
attoken = self._nexttoken(tokenizer, None)
126124
if self._type(attoken) != self._prods.IMPORT_SYM:
@@ -314,7 +312,7 @@ def _setHref(self, href):
314312

315313
if cssText is None:
316314
# catched in next except below!
317-
raise IOError('Cannot read Stylesheet.')
315+
raise OSError('Cannot read Stylesheet.')
318316

319317
# contentEncoding with parentStyleSheet.overrideEncoding,
320318
# HTTP or parent
@@ -332,7 +330,7 @@ def _setHref(self, href):
332330
cssText, encodingOverride=encodingOverride, encoding=encoding
333331
)
334332

335-
except (OSError, IOError, ValueError) as e:
333+
except (OSError, ValueError) as e:
336334
self._log.warn(
337335
'CSSImportRule: While processing imported '
338336
'style sheet href=%s: %r' % (self.href, e),

cssutils/css/cssmediarule.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ def __init__(
3333
readonly=False,
3434
):
3535
"""constructor"""
36-
super(CSSMediaRule, self).__init__(
37-
parentRule=parentRule, parentStyleSheet=parentStyleSheet
38-
)
36+
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
3937
self._atkeyword = '@media'
4038

4139
# 1. media
@@ -48,13 +46,13 @@ def __init__(
4846
self._readonly = readonly
4947

5048
def __repr__(self):
51-
return "cssutils.css.%s(mediaText=%r)" % (
49+
return "cssutils.css.{}(mediaText={!r})".format(
5250
self.__class__.__name__,
5351
self.media.mediaText,
5452
)
5553

5654
def __str__(self):
57-
return "<cssutils.css.%s object mediaText=%r at 0x%x>" % (
55+
return "<cssutils.css.{} object mediaText={!r} at 0x{:x}>".format(
5856
self.__class__.__name__,
5957
self.media.mediaText,
6058
id(self),
@@ -85,7 +83,7 @@ def _setCssText(self, cssText): # noqa: C901
8583
Raised if the rule is readonly.
8684
"""
8785
# media "name"? { cssRules }
88-
super(CSSMediaRule, self)._setCssText(cssText)
86+
super()._setCssText(cssText)
8987

9088
# might be (cssText, namespaces)
9189
cssText, namespaces = self._splitNamespacesOff(cssText)

cssutils/css/cssnamespacerule.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ def __init__(
6767
: IDENT
6868
;
6969
"""
70-
super(CSSNamespaceRule, self).__init__(
71-
parentRule=parentRule, parentStyleSheet=parentStyleSheet
72-
)
70+
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
7371
self._atkeyword = '@namespace'
7472
self._prefix = ''
7573
self._namespaceURI = None
@@ -91,18 +89,20 @@ def __init__(
9189
self._readonly = readonly
9290

9391
def __repr__(self):
94-
return "cssutils.css.%s(namespaceURI=%r, prefix=%r)" % (
92+
return "cssutils.css.{}(namespaceURI={!r}, prefix={!r})".format(
9593
self.__class__.__name__,
9694
self.namespaceURI,
9795
self.prefix,
9896
)
9997

10098
def __str__(self):
101-
return "<cssutils.css.%s object namespaceURI=%r prefix=%r at 0x%x>" % (
102-
self.__class__.__name__,
103-
self.namespaceURI,
104-
self.prefix,
105-
id(self),
99+
return (
100+
"<cssutils.css.{} object namespaceURI={!r} prefix={!r} at 0x{:x}>".format(
101+
self.__class__.__name__,
102+
self.namespaceURI,
103+
self.prefix,
104+
id(self),
105+
)
106106
)
107107

108108
def _getCssText(self):
@@ -125,7 +125,7 @@ def _setCssText(self, cssText): # noqa: C901
125125
Raised if the specified CSS string value has a syntax error and
126126
is unparsable.
127127
"""
128-
super(CSSNamespaceRule, self)._setCssText(cssText)
128+
super()._setCssText(cssText)
129129
tokenizer = self._tokenize2(cssText)
130130
attoken = self._nexttoken(tokenizer, None)
131131
if self._type(attoken) != self._prods.NAMESPACE_SYM:

cssutils/css/csspagerule.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ def __init__(
6969
:param style:
7070
CSSStyleDeclaration for this CSSStyleRule
7171
"""
72-
super(CSSPageRule, self).__init__(
73-
parentRule=parentRule, parentStyleSheet=parentStyleSheet
74-
)
72+
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
7573
self._atkeyword = '@page'
7674
self._specificity = (0, 0, 0)
7775

@@ -94,7 +92,7 @@ def __init__(
9492
self._readonly = readonly
9593

9694
def __repr__(self):
97-
return "cssutils.css.%s(selectorText=%r, style=%r)" % (
95+
return "cssutils.css.{}(selectorText={!r}, style={!r})".format(
9896
self.__class__.__name__,
9997
self.selectorText,
10098
self.style.cssText,
@@ -299,7 +297,7 @@ def _setCssText(self, cssText):
299297
- :exc:`~xml.dom.NoModificationAllowedErr`:
300298
Raised if the rule is readonly.
301299
"""
302-
super(CSSPageRule, self)._setCssText(cssText)
300+
super()._setCssText(cssText)
303301

304302
tokenizer = self._tokenize2(cssText)
305303
if self._type(self._nexttoken(tokenizer)) != self._prods.PAGE_SYM:

cssutils/css/cssrule.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class CSSRule(cssutils.util.Base2):
6161

6262
def __init__(self, parentRule=None, parentStyleSheet=None, readonly=False):
6363
"""Set common attributes for all rules."""
64-
super(CSSRule, self).__init__()
64+
super().__init__()
6565
self._parent = parentRule
6666
self._parentRule = parentRule
6767
self._parentStyleSheet = parentStyleSheet
@@ -78,7 +78,9 @@ def _setAtkeyword(self, keyword):
7878
self._keyword = keyword
7979
else:
8080
self._log.error(
81-
'%s: Invalid atkeyword for this rule: %r' % (self.atkeyword, keyword),
81+
'{}: Invalid atkeyword for this rule: {!r}'.format(
82+
self.atkeyword, keyword
83+
),
8284
error=xml.dom.InvalidModificationErr,
8385
)
8486

@@ -160,16 +162,13 @@ class CSSRuleRules(CSSRule):
160162

161163
def __init__(self, parentRule=None, parentStyleSheet=None):
162164

163-
super(CSSRuleRules, self).__init__(
164-
parentRule=parentRule, parentStyleSheet=parentStyleSheet
165-
)
165+
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
166166

167167
self.cssRules = cssutils.css.CSSRuleList()
168168

169169
def __iter__(self):
170170
"""Generator iterating over these rule's cssRules."""
171-
for rule in self._cssRules:
172-
yield rule
171+
yield from self._cssRules
173172

174173
def _setCssRules(self, cssRules):
175174
"Set new cssRules and update contained rules refs."
@@ -257,7 +256,7 @@ def _prepareInsertRule(self, rule, index=None):
257256
and not isinstance(tempsheet.cssRules[0], cssutils.css.CSSRule)
258257
):
259258
self._log.error(
260-
'%s: Invalid Rule: %s' % (self.__class__.__name__, rule)
259+
'{}: Invalid Rule: {}'.format(self.__class__.__name__, rule)
261260
)
262261
return False, False
263262
rule = tempsheet.cssRules[0]
@@ -269,7 +268,9 @@ def _prepareInsertRule(self, rule, index=None):
269268
return True, True
270269

271270
elif not isinstance(rule, cssutils.css.CSSRule):
272-
self._log.error('%s: Not a CSSRule: %s' % (rule, self.__class__.__name__))
271+
self._log.error(
272+
'{}: Not a CSSRule: {}'.format(rule, self.__class__.__name__)
273+
)
273274
return False, False
274275

275276
return rule, index

0 commit comments

Comments
 (0)