Skip to content

Commit

Permalink
Merge pull request #3701 from Pylons/pyupgrade-3.7
Browse files Browse the repository at this point in the history
pyupgrade --py37-plus
  • Loading branch information
mmerickel committed Sep 29, 2022
2 parents 97481ac + d9a49e0 commit 51a731c
Show file tree
Hide file tree
Showing 44 changed files with 110 additions and 110 deletions.
2 changes: 0 additions & 2 deletions docs/conf.py
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# pyramid documentation build configuration file, created by
# sphinx-quickstart on Wed Jul 16 13:18:14 2008.
#
Expand Down
2 changes: 1 addition & 1 deletion src/pyramid/asset.py
Expand Up @@ -26,7 +26,7 @@ def asset_spec_from_abspath(abspath, package):
pp = package_path(package) + os.path.sep
if abspath.startswith(pp):
relpath = abspath[len(pp) :]
return '%s:%s' % (
return '{}:{}'.format(
package_name(package),
relpath.replace(os.path.sep, '/'),
)
Expand Down
14 changes: 7 additions & 7 deletions src/pyramid/authentication.py
Expand Up @@ -74,7 +74,7 @@ def authenticated_userid(self, request):

if self.callback is None:
debug and self._log(
'there was no groupfinder callback; returning %r' % (userid,),
f'there was no groupfinder callback; returning {userid!r}',
'authenticated_userid',
request,
)
Expand Down Expand Up @@ -152,14 +152,14 @@ def effective_principals(self, request):
else:
groups = self.callback(userid, request)
debug and self._log(
'groupfinder callback returned %r as groups' % (groups,),
f'groupfinder callback returned {groups!r} as groups',
'effective_principals',
request,
)

if groups is None: # is None!
debug and self._log(
'returning effective principals: %r' % (effective_principals,),
f'returning effective principals: {effective_principals!r}',
'effective_principals',
request,
)
Expand All @@ -170,7 +170,7 @@ def effective_principals(self, request):
effective_principals.extend(groups)

debug and self._log(
'returning effective principals: %r' % (effective_principals,),
f'returning effective principals: {effective_principals!r}',
'effective_principals',
request,
)
Expand Down Expand Up @@ -717,7 +717,7 @@ def digest(self):
)

def cookie_value(self):
v = '%s%08x%s!' % (self.digest(), int(self.time), quote(self.userid))
v = f'{self.digest()}{int(self.time):08x}{quote(self.userid)}!'
if self.tokens:
v += self.tokens + '!'
v += self.user_data
Expand Down Expand Up @@ -1174,9 +1174,9 @@ def remember(self, request, userid, max_age=None, tokens=()):
try:
token = ascii_(token)
except UnicodeEncodeError:
raise ValueError("Invalid token %r" % (token,))
raise ValueError(f"Invalid token {token!r}")
if not (isinstance(token, str) and VALID_TOKEN.match(token)):
raise ValueError("Invalid token %r" % (token,))
raise ValueError(f"Invalid token {token!r}")
new_tokens.append(token)
tokens = tuple(new_tokens)

Expand Down
2 changes: 1 addition & 1 deletion src/pyramid/config/__init__.py
Expand Up @@ -447,7 +447,7 @@ def _make_spec(self, path_or_spec):
package, filename = resolve_asset_spec(path_or_spec, self.package_name)
if package is None:
return filename # absolute filename
return '%s:%s' % (package, filename)
return f'{package}:{filename}'

def _fix_registry(self):
"""Fix up a ZCA component registry that is not a
Expand Down
2 changes: 1 addition & 1 deletion src/pyramid/config/actions.py
Expand Up @@ -537,7 +537,7 @@ def __init__(self, file, line, function, src):
def __str__(self):
srclines = self.src.split('\n')
src = '\n'.join(' %s' % x for x in srclines)
return 'Line %s of file %s:\n%s' % (self.line, self.file, src)
return f'Line {self.line} of file {self.file}:\n{src}'


def action_method(wrapped):
Expand Down
4 changes: 2 additions & 2 deletions src/pyramid/config/assets.py
Expand Up @@ -221,7 +221,7 @@ def __init__(self, package, prefix):
self.prefix = prefix

def get_path(self, resource_name):
return '%s%s' % (self.prefix, resource_name)
return f'{self.prefix}{resource_name}'

def get_filename(self, resource_name):
path = self.get_path(resource_name)
Expand Down Expand Up @@ -388,7 +388,7 @@ def register():
intr = self.introspectable(
'asset overrides',
(package, override_package, path, override_prefix),
'%s -> %s' % (to_override, override_with),
f'{to_override} -> {override_with}',
'asset override',
)
intr['to_override'] = to_override
Expand Down
2 changes: 1 addition & 1 deletion src/pyramid/config/predicates.py
Expand Up @@ -27,7 +27,7 @@ def _add_predicate(
intr = self.introspectable(
'%s predicates' % type,
discriminator,
'%s predicate named %s' % (type, name),
f'{type} predicate named {name}',
'%s predicate' % type,
)
intr['name'] = name
Expand Down
4 changes: 2 additions & 2 deletions src/pyramid/config/routes.py
Expand Up @@ -401,7 +401,7 @@ def external_url_pregenerator(request, elements, kw):
scheme = parsed.scheme
else:
scheme = request.scheme
kw['_app_url'] = '{}://{}'.format(scheme, parsed.netloc)
kw['_app_url'] = f'{scheme}://{parsed.netloc}'

if original_pregenerator:
elements, kw = original_pregenerator(request, elements, kw)
Expand All @@ -423,7 +423,7 @@ def external_url_pregenerator(request, elements, kw):
introspectables = []

intr = self.introspectable(
'routes', name, '%s (pattern: %r)' % (name, pattern), 'route'
'routes', name, f'{name} (pattern: {pattern!r})', 'route'
)
intr['name'] = name
intr['pattern'] = pattern
Expand Down
2 changes: 1 addition & 1 deletion src/pyramid/config/tweens.py
Expand Up @@ -121,7 +121,7 @@ def _add_tween(self, tween_factory, under=None, over=None, explicit=False):
if p is not None:
if not is_string_or_iterable(p):
raise ConfigurationError(
'"%s" must be a string or iterable, not %s' % (t, p)
f'"{t}" must be a string or iterable, not {p}'
)

if over is INGRESS or is_nonstr_iter(over) and INGRESS in over:
Expand Down
10 changes: 5 additions & 5 deletions src/pyramid/config/views.py
Expand Up @@ -904,7 +904,7 @@ def discrim_func():
discriminator = Deferred(discrim_func)

if inspect.isclass(view) and attr:
view_desc = 'method %r of %s' % (
view_desc = 'method {!r} of {}'.format(
attr,
self.object_description(view),
)
Expand Down Expand Up @@ -1160,7 +1160,7 @@ def _check_view_options(self, **kw):
for opt in getattr(deriver, 'options', []):
kw.pop(opt, None)
if kw:
raise ConfigurationError('Unknown view options: %s' % (kw,))
raise ConfigurationError(f'Unknown view options: {kw}')

def _apply_view_derivers(self, info):
# These derivers are not really derivers and so have fixed order
Expand Down Expand Up @@ -2248,7 +2248,7 @@ def add(self, config, name, spec, **extra):
# pattern, plus any extras passed to us via add_static_view
pattern = "%s*subpath" % name # name already ends with slash
if config.route_prefix:
route_name = '__%s/%s' % (config.route_prefix, name)
route_name = f'__{config.route_prefix}/{name}'
else:
route_name = '__%s' % name
config.add_route(route_name, pattern, **extra)
Expand Down Expand Up @@ -2335,15 +2335,15 @@ def _bust_asset_path(self, request, spec, subpath, kw):
rawspec = None

if pkg_name is not None:
pathspec = '{}:{}{}'.format(pkg_name, pkg_subpath, subpath)
pathspec = f'{pkg_name}:{pkg_subpath}{subpath}'
overrides = registry.queryUtility(IPackageOverrides, name=pkg_name)
if overrides is not None:
resource_name = posixpath.join(pkg_subpath, subpath)
sources = overrides.filtered_sources(resource_name)
for source, filtered_path in sources:
rawspec = source.get_path(filtered_path)
if hasattr(source, 'pkg_name'):
rawspec = '{}:{}'.format(source.pkg_name, rawspec)
rawspec = f'{source.pkg_name}:{rawspec}'
break

else:
Expand Down
2 changes: 1 addition & 1 deletion src/pyramid/csrf.py
Expand Up @@ -360,6 +360,6 @@ def _fail(reason):
if not any(
is_same_domain(originp.netloc, host) for host in trusted_origins
):
return _fail("{} does not match any trusted origins.".format(origin))
return _fail(f"{origin} does not match any trusted origins.")

return True
6 changes: 3 additions & 3 deletions src/pyramid/encode.py
Expand Up @@ -70,13 +70,13 @@ def urlencode(query, doseq=True, quote_via=quote_plus):
if is_nonstr_iter(v):
for x in v:
x = quote_via(x)
result += '%s%s=%s' % (prefix, k, x)
result += f'{prefix}{k}={x}'
prefix = '&'
elif v is None:
result += '%s%s=' % (prefix, k)
result += f'{prefix}{k}='
else:
v = quote_via(v)
result += '%s%s=%s' % (prefix, k, v)
result += f'{prefix}{k}={v}'

prefix = '&'

Expand Down
6 changes: 3 additions & 3 deletions src/pyramid/exceptions.py
Expand Up @@ -91,7 +91,7 @@ def __init__(self, conflicts):
def __str__(self):
r = ["Conflicting configuration actions"]
for discriminator, infos in self._conflicts.items():
r.append(" For: %s" % (discriminator,))
r.append(f" For: {discriminator}")
for info in infos:
for line in str(info).rstrip().split('\n'):
r.append(" " + line)
Expand All @@ -106,7 +106,7 @@ def __init__(self, etype, evalue, info):
self.etype, self.evalue, self.info = etype, evalue, info

def __str__(self):
return "%s: %s\n in:\n %s" % (self.etype, self.evalue, self.info)
return f"{self.etype}: {self.evalue}\n in:\n {self.info}"


class CyclicDependencyError(Exception):
Expand All @@ -122,6 +122,6 @@ def __str__(self):
for cycle in cycles:
dependent = cycle
dependees = cycles[cycle]
L.append('%r sorts before %r' % (dependent, dependees))
L.append(f'{dependent!r} sorts before {dependees!r}')
msg = 'Implicit ordering cycle:' + '; '.join(L)
return msg
2 changes: 1 addition & 1 deletion src/pyramid/httpexceptions.py
Expand Up @@ -227,7 +227,7 @@ def __init__(
json_formatter=None,
**kw,
):
status = '%s %s' % (self.code, self.title)
status = f'{self.code} {self.title}'
Response.__init__(self, status=status, **kw)
Exception.__init__(self, detail)
self.detail = self.message = detail
Expand Down
2 changes: 1 addition & 1 deletion src/pyramid/i18n.py
Expand Up @@ -273,7 +273,7 @@ def load(cls, dirname=None, locales=None, domain=DEFAULT_DOMAIN):
return cls(fileobj=fp, domain=domain)

def __repr__(self):
return '<%s: "%s">' % (
return '<{}: "{}">'.format(
type(self).__name__,
self._info.get('project-id-version'),
)
Expand Down
12 changes: 6 additions & 6 deletions src/pyramid/path.py
Expand Up @@ -98,7 +98,7 @@ def __init__(self, package=CALLER_PACKAGE):
__import__(package)
except ImportError:
raise ValueError(
'The dotted name %r cannot be imported' % (package,)
f'The dotted name {package!r} cannot be imported'
)
package = sys.modules[package]
self.package = package_of(package)
Expand Down Expand Up @@ -209,7 +209,7 @@ def resolve(self, spec):
package_name = getattr(self.package, '__name__', None)
if package_name is None:
raise ValueError(
'relative spec %r irresolveable without package' % (spec,)
f'relative spec {spec!r} irresolveable without package'
)
return PkgResourcesAssetDescriptor(package_name, path)

Expand Down Expand Up @@ -300,7 +300,7 @@ def resolve(self, dotted):
"""
if not isinstance(dotted, str):
raise ValueError('%r is not a string' % (dotted,))
raise ValueError(f'{dotted!r} is not a string')
package = self.package
if package is CALLER_PACKAGE:
package = caller_package()
Expand Down Expand Up @@ -338,7 +338,7 @@ def _pkg_resources_style(self, value, package):
if value.startswith(('.', ':')):
if not package:
raise ValueError(
'relative name %r irresolveable without package' % (value,)
f'relative name {value!r} irresolveable without package'
)
if value in ['.', ':']:
value = package.__name__
Expand All @@ -361,7 +361,7 @@ def _zope_dottedname_style(self, value, package):
if value == '.':
if module is None:
raise ValueError(
'relative name %r irresolveable without package' % (value,)
f'relative name {value!r} irresolveable without package'
)
name = module.split('.')
else:
Expand Down Expand Up @@ -401,7 +401,7 @@ def __init__(self, pkg_name, path):
self.path = path

def absspec(self):
return '%s:%s' % (self.pkg_name, self.path)
return f'{self.pkg_name}:{self.path}'

def abspath(self):
return os.path.abspath(
Expand Down
20 changes: 9 additions & 11 deletions src/pyramid/predicates.py
Expand Up @@ -52,7 +52,7 @@ def __init__(self, val, config):
self.val = val

def text(self):
return 'path_info = %s' % (self.orig,)
return f'path_info = {self.orig}'

phash = text

Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(self, val, config):

def text(self):
return 'request_param %s' % ','.join(
['%s=%s' % (x, y) if y else x for x, y in self.reqs]
[f'{x}={y}' if y else x for x, y in self.reqs]
)

phash = text
Expand Down Expand Up @@ -116,7 +116,7 @@ def __init__(self, val, config):

def text(self):
return 'header %s' % ', '.join(
'%s=%s' % (name, val_str) if val_str else name
f'{name}={val_str}' if val_str else name
for name, _, val_str in self.val
)

Expand Down Expand Up @@ -144,7 +144,7 @@ def __init__(self, values, config):
self.values = values

def text(self):
return 'accept = %s' % (', '.join(self.values),)
return 'accept = {}'.format(', '.join(self.values))

phash = text

Expand All @@ -157,7 +157,7 @@ def __init__(self, val, config):
self.val = config.maybe_dotted(val)

def text(self):
return 'containment = %s' % (self.val,)
return f'containment = {self.val}'

phash = text

Expand All @@ -171,7 +171,7 @@ def __init__(self, val, config):
self.val = val

def text(self):
return 'request_type = %s' % (self.val,)
return f'request_type = {self.val}'

phash = text

Expand All @@ -187,9 +187,7 @@ def __init__(self, val, config):
self.reqs = [(x.strip(), y.strip()) for x, y in reqs]

def text(self):
return 'match_param %s' % ','.join(
['%s=%s' % (x, y) for x, y in self.reqs]
)
return 'match_param %s' % ','.join([f'{x}={y}' for x, y in self.reqs])

phash = text

Expand Down Expand Up @@ -266,7 +264,7 @@ def __init__(self, val, config):
self.val = ('',) + val

def text(self):
return 'physical_path = %s' % (self.val,)
return f'physical_path = {self.val}'

phash = text

Expand All @@ -281,7 +279,7 @@ def __init__(self, val, config):
self.val = val

def text(self):
return "is_authenticated = %r" % (self.val,)
return f"is_authenticated = {self.val!r}"

phash = text

Expand Down

0 comments on commit 51a731c

Please sign in to comment.