Skip to content

Commit

Permalink
Ran pyupgrade to Python 3.7+ (then fade to black).
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jul 12, 2022
1 parent 9ea9176 commit 57179fe
Show file tree
Hide file tree
Showing 57 changed files with 516 additions and 561 deletions.
2 changes: 1 addition & 1 deletion cssutils/_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _defaultFetcher(url):
res = urllib.request.urlopen(request)
except urllib.error.HTTPError as e:
# http error, e.g. 404, e can be raised
log.warn('HTTPError opening url=%s: %s %s' % (url, e.code, e.msg), error=e)
log.warn(f'HTTPError opening url={url}: {e.code} {e.msg}', error=e)
except urllib.error.URLError as e:
# URLError like mailto: or other IO errors, e can be raised
log.warn('URLError, %s' % e.reason, error=e)
Expand Down
4 changes: 2 additions & 2 deletions cssutils/_fetchgae.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _defaultFetcher(url):
try:
r = urlfetch.fetch(url, method=urlfetch.GET)
except urlfetch.Error as e:
log.warn('Error opening url=%r: %s' % (url, e), error=IOError)
log.warn(f'Error opening url={url!r}: {e}', error=IOError)
else:
if r.status_code == 200:
# find mimetype and encoding
Expand All @@ -65,6 +65,6 @@ def _defaultFetcher(url):
else:
# TODO: 301 etc
log.warn(
'Error opening url=%r: HTTP status %s' % (url, r.status_code),
f'Error opening url={url!r}: HTTP status {r.status_code}',
error=IOError,
)
12 changes: 6 additions & 6 deletions cssutils/css/csscharsetrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def __init__(
:param readonly:
defaults to False, not used yet
"""
super(CSSCharsetRule, self).__init__(
parentRule=parentRule, parentStyleSheet=parentStyleSheet
)
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
self._atkeyword = '@charset'

if encoding:
Expand All @@ -59,10 +57,12 @@ def __init__(
self._readonly = readonly

def __repr__(self):
return "cssutils.css.%s(encoding=%r)" % (self.__class__.__name__, self.encoding)
return "cssutils.css.{}(encoding={!r})".format(
self.__class__.__name__, self.encoding
)

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

wellformed = True
tokenizer = self._tokenize2(cssText)
Expand Down
12 changes: 6 additions & 6 deletions cssutils/css/csscomment.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class CSSComment(cssrule.CSSRule):
def __init__(
self, cssText=None, parentRule=None, parentStyleSheet=None, readonly=False
):
super(CSSComment, self).__init__(
parentRule=parentRule, parentStyleSheet=parentStyleSheet
)
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)

self._cssText = None
if cssText:
Expand All @@ -33,10 +31,12 @@ def __init__(
self._readonly = readonly

def __repr__(self):
return "cssutils.css.%s(cssText=%r)" % (self.__class__.__name__, self.cssText)
return "cssutils.css.{}(cssText={!r})".format(
self.__class__.__name__, self.cssText
)

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

commenttoken = self._nexttoken(tokenizer)
Expand Down
10 changes: 4 additions & 6 deletions cssutils/css/cssfontfacerule.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def __init__(
CSSStyleDeclaration used to hold any font descriptions
for this CSSFontFaceRule
"""
super(CSSFontFaceRule, self).__init__(
parentRule=parentRule, parentStyleSheet=parentStyleSheet
)
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
self._atkeyword = '@font-face'

if style:
Expand All @@ -53,13 +51,13 @@ def __init__(
self._readonly = readonly

def __repr__(self):
return "cssutils.css.%s(style=%r)" % (
return "cssutils.css.{}(style={!r})".format(
self.__class__.__name__,
self.style.cssText,
)

def __str__(self):
return "<cssutils.css.%s object style=%r valid=%r at 0x%x>" % (
return "<cssutils.css.{} object style={!r} valid={!r} at 0x{:x}>".format(
self.__class__.__name__,
self.style.cssText,
self.valid,
Expand All @@ -85,7 +83,7 @@ def _setCssText(self, cssText):
- :exc:`~xml.dom.NoModificationAllowedErr`:
Raised if the rule is readonly.
"""
super(CSSFontFaceRule, self)._setCssText(cssText)
super()._setCssText(cssText)

tokenizer = self._tokenize2(cssText)
attoken = self._nexttoken(tokenizer, None)
Expand Down
14 changes: 6 additions & 8 deletions cssutils/css/cssimportrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def __init__(
:param name:
Additional name of imported style sheet
"""
super(CSSImportRule, self).__init__(
parentRule=parentRule, parentStyleSheet=parentStyleSheet
)
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
self._atkeyword = '@import'
self._styleSheet = None

Expand Down Expand Up @@ -76,7 +74,7 @@ def __repr__(self):
mediaText = self.media.mediaText
else:
mediaText = None
return "cssutils.css.%s(href=%r, mediaText=%r, name=%r)" % (
return "cssutils.css.{}(href={!r}, mediaText={!r}, name={!r})".format(
self.__class__.__name__,
self.href,
mediaText,
Expand All @@ -88,7 +86,7 @@ def __str__(self):
mediaText = self.media.mediaText
else:
mediaText = None
return "<cssutils.css.%s object href=%r mediaText=%r name=%r at 0x%x>" % (
return "<cssutils.css.{} object href={!r} mediaText={!r} name={!r} at 0x{:x}>".format(
self.__class__.__name__,
self.href,
mediaText,
Expand Down Expand Up @@ -120,7 +118,7 @@ def _setCssText(self, cssText): # noqa: C901
Raised if the specified CSS string value has a syntax error and
is unparsable.
"""
super(CSSImportRule, self)._setCssText(cssText)
super()._setCssText(cssText)
tokenizer = self._tokenize2(cssText)
attoken = self._nexttoken(tokenizer, None)
if self._type(attoken) != self._prods.IMPORT_SYM:
Expand Down Expand Up @@ -314,7 +312,7 @@ def _setHref(self, href):

if cssText is None:
# catched in next except below!
raise IOError('Cannot read Stylesheet.')
raise OSError('Cannot read Stylesheet.')

# contentEncoding with parentStyleSheet.overrideEncoding,
# HTTP or parent
Expand All @@ -332,7 +330,7 @@ def _setHref(self, href):
cssText, encodingOverride=encodingOverride, encoding=encoding
)

except (OSError, IOError, ValueError) as e:
except (OSError, ValueError) as e:
self._log.warn(
'CSSImportRule: While processing imported '
'style sheet href=%s: %r' % (self.href, e),
Expand Down
10 changes: 4 additions & 6 deletions cssutils/css/cssmediarule.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def __init__(
readonly=False,
):
"""constructor"""
super(CSSMediaRule, self).__init__(
parentRule=parentRule, parentStyleSheet=parentStyleSheet
)
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
self._atkeyword = '@media'

# 1. media
Expand All @@ -48,13 +46,13 @@ def __init__(
self._readonly = readonly

def __repr__(self):
return "cssutils.css.%s(mediaText=%r)" % (
return "cssutils.css.{}(mediaText={!r})".format(
self.__class__.__name__,
self.media.mediaText,
)

def __str__(self):
return "<cssutils.css.%s object mediaText=%r at 0x%x>" % (
return "<cssutils.css.{} object mediaText={!r} at 0x{:x}>".format(
self.__class__.__name__,
self.media.mediaText,
id(self),
Expand Down Expand Up @@ -85,7 +83,7 @@ def _setCssText(self, cssText): # noqa: C901
Raised if the rule is readonly.
"""
# media "name"? { cssRules }
super(CSSMediaRule, self)._setCssText(cssText)
super()._setCssText(cssText)

# might be (cssText, namespaces)
cssText, namespaces = self._splitNamespacesOff(cssText)
Expand Down
20 changes: 10 additions & 10 deletions cssutils/css/cssnamespacerule.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def __init__(
: IDENT
;
"""
super(CSSNamespaceRule, self).__init__(
parentRule=parentRule, parentStyleSheet=parentStyleSheet
)
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
self._atkeyword = '@namespace'
self._prefix = ''
self._namespaceURI = None
Expand All @@ -91,18 +89,20 @@ def __init__(
self._readonly = readonly

def __repr__(self):
return "cssutils.css.%s(namespaceURI=%r, prefix=%r)" % (
return "cssutils.css.{}(namespaceURI={!r}, prefix={!r})".format(
self.__class__.__name__,
self.namespaceURI,
self.prefix,
)

def __str__(self):
return "<cssutils.css.%s object namespaceURI=%r prefix=%r at 0x%x>" % (
self.__class__.__name__,
self.namespaceURI,
self.prefix,
id(self),
return (
"<cssutils.css.{} object namespaceURI={!r} prefix={!r} at 0x{:x}>".format(
self.__class__.__name__,
self.namespaceURI,
self.prefix,
id(self),
)
)

def _getCssText(self):
Expand All @@ -125,7 +125,7 @@ def _setCssText(self, cssText): # noqa: C901
Raised if the specified CSS string value has a syntax error and
is unparsable.
"""
super(CSSNamespaceRule, self)._setCssText(cssText)
super()._setCssText(cssText)
tokenizer = self._tokenize2(cssText)
attoken = self._nexttoken(tokenizer, None)
if self._type(attoken) != self._prods.NAMESPACE_SYM:
Expand Down
8 changes: 3 additions & 5 deletions cssutils/css/csspagerule.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ def __init__(
:param style:
CSSStyleDeclaration for this CSSStyleRule
"""
super(CSSPageRule, self).__init__(
parentRule=parentRule, parentStyleSheet=parentStyleSheet
)
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)
self._atkeyword = '@page'
self._specificity = (0, 0, 0)

Expand All @@ -94,7 +92,7 @@ def __init__(
self._readonly = readonly

def __repr__(self):
return "cssutils.css.%s(selectorText=%r, style=%r)" % (
return "cssutils.css.{}(selectorText={!r}, style={!r})".format(
self.__class__.__name__,
self.selectorText,
self.style.cssText,
Expand Down Expand Up @@ -299,7 +297,7 @@ def _setCssText(self, cssText):
- :exc:`~xml.dom.NoModificationAllowedErr`:
Raised if the rule is readonly.
"""
super(CSSPageRule, self)._setCssText(cssText)
super()._setCssText(cssText)

tokenizer = self._tokenize2(cssText)
if self._type(self._nexttoken(tokenizer)) != self._prods.PAGE_SYM:
Expand Down
19 changes: 10 additions & 9 deletions cssutils/css/cssrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CSSRule(cssutils.util.Base2):

def __init__(self, parentRule=None, parentStyleSheet=None, readonly=False):
"""Set common attributes for all rules."""
super(CSSRule, self).__init__()
super().__init__()
self._parent = parentRule
self._parentRule = parentRule
self._parentStyleSheet = parentStyleSheet
Expand All @@ -78,7 +78,9 @@ def _setAtkeyword(self, keyword):
self._keyword = keyword
else:
self._log.error(
'%s: Invalid atkeyword for this rule: %r' % (self.atkeyword, keyword),
'{}: Invalid atkeyword for this rule: {!r}'.format(
self.atkeyword, keyword
),
error=xml.dom.InvalidModificationErr,
)

Expand Down Expand Up @@ -160,16 +162,13 @@ class CSSRuleRules(CSSRule):

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

super(CSSRuleRules, self).__init__(
parentRule=parentRule, parentStyleSheet=parentStyleSheet
)
super().__init__(parentRule=parentRule, parentStyleSheet=parentStyleSheet)

self.cssRules = cssutils.css.CSSRuleList()

def __iter__(self):
"""Generator iterating over these rule's cssRules."""
for rule in self._cssRules:
yield rule
yield from self._cssRules

def _setCssRules(self, cssRules):
"Set new cssRules and update contained rules refs."
Expand Down Expand Up @@ -257,7 +256,7 @@ def _prepareInsertRule(self, rule, index=None):
and not isinstance(tempsheet.cssRules[0], cssutils.css.CSSRule)
):
self._log.error(
'%s: Invalid Rule: %s' % (self.__class__.__name__, rule)
'{}: Invalid Rule: {}'.format(self.__class__.__name__, rule)
)
return False, False
rule = tempsheet.cssRules[0]
Expand All @@ -269,7 +268,9 @@ def _prepareInsertRule(self, rule, index=None):
return True, True

elif not isinstance(rule, cssutils.css.CSSRule):
self._log.error('%s: Not a CSSRule: %s' % (rule, self.__class__.__name__))
self._log.error(
'{}: Not a CSSRule: {}'.format(rule, self.__class__.__name__)
)
return False, False

return rule, index
Expand Down
Loading

0 comments on commit 57179fe

Please sign in to comment.