Skip to content

Commit

Permalink
find -name "*.py" -exec pyupgrade --py3-only --py37-plus {} +
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed May 5, 2022
1 parent 0be1c60 commit e025513
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 118 deletions.
1 change: 0 additions & 1 deletion plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
__import__("pkg_resources").declare_namespace(__name__)
13 changes: 6 additions & 7 deletions plone/cachepurging/browser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.cachepurging.interfaces import ICachePurgingSettings
from plone.cachepurging.interfaces import IPurger
from plone.cachepurging.utils import getPathsToPurge
Expand All @@ -10,7 +9,7 @@
from zope.event import notify


class QueuePurge(object):
class QueuePurge:
"""Manually initiate a purge"""

def __init__(self, context, request):
Expand All @@ -25,10 +24,10 @@ def __call__(self):
paths = getPathsToPurge(self.context, self.request)

notify(Purge(self.context))
return "Queued:\n\n{0}".format("\n".join(paths))
return "Queued:\n\n{}".format("\n".join(paths))


class PurgeImmediately(object):
class PurgeImmediately:
"""Purge immediately"""

def __init__(self, context, request):
Expand All @@ -55,11 +54,11 @@ def __call__(self):
self.write(
"(hint: add '?traceback' to url to show full traceback in case of errors)\n\n"
)
self.write("Proxies to purge: {0}\n".format(", ".join(caching_proxies)))
self.write("Proxies to purge: {}\n".format(", ".join(caching_proxies)))
for path in getPathsToPurge(self.context, self.request):
self.write("- process path: {0}\n".format(path))
self.write(f"- process path: {path}\n")
for url in getURLsToPurge(path, caching_proxies):
self.write(" - send to purge {0}\n".format(url).encode("utf-8"))
self.write(f" - send to purge {url}\n".encode("utf-8"))
status, xcache, xerror = purger.purgeSync(url)
self.write(
" response with status: {status}, X-Cache: {xcache}\n".format(
Expand Down
1 change: 0 additions & 1 deletion plone/cachepurging/hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.cachepurging.interfaces import ICachePurgingSettings
from plone.cachepurging.interfaces import IPurger
from plone.cachepurging.utils import getPathsToPurge
Expand Down
71 changes: 35 additions & 36 deletions plone/cachepurging/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from zope import schema
from zope.i18nmessageid import MessageFactory
from zope.interface import Interface
Expand All @@ -14,57 +13,57 @@ class ICachePurgingSettings(Interface):
"""

enabled = schema.Bool(
title=_(u"Enable purging"),
description=_(u"If disabled, no purging will take place"),
title=_("Enable purging"),
description=_("If disabled, no purging will take place"),
default=True,
)

cachingProxies = schema.Tuple(
title=_(u"Caching proxies"),
title=_("Caching proxies"),
description=_(
u"Provide the URLs of each proxy to which PURGE "
u"requests should be sent."
"Provide the URLs of each proxy to which PURGE "
"requests should be sent."
),
value_type=schema.URI(),
)

virtualHosting = schema.Bool(
title=_(u"Send PURGE requests with virtual hosting paths"),
title=_("Send PURGE requests with virtual hosting paths"),
description=_(
u"This option is only relevant if you are using "
u"virtual hosting with Zope's VirtualHostMonster. "
u"This relies on special tokens (VirtualHostBase "
u"and VirtualHostRoot) in the URL to instruct "
u"Zope about the types of URLs that the user sees. "
u"If virtual host URLs are in use and this option "
u"is set, PURGE requests will be sent to the "
u"caching proxy with the virtual hosting tokens "
u"in place. This makes sense if there is a web "
u"server in front of your caching proxy performing "
u"the rewrites necessary to translate a user-"
u"facing URL into a virtual hosting URL, so that "
u"the requests the caching proxy sees have the "
u"rewrite information in them. Conversely, if the "
u"rewrite is done in or behind the caching proxy, "
u"you want to disable this option, so that the "
u"PURGE requests use URLs that match those seen "
u"by the caching proxy as they come from the "
u"client."
"This option is only relevant if you are using "
"virtual hosting with Zope's VirtualHostMonster. "
"This relies on special tokens (VirtualHostBase "
"and VirtualHostRoot) in the URL to instruct "
"Zope about the types of URLs that the user sees. "
"If virtual host URLs are in use and this option "
"is set, PURGE requests will be sent to the "
"caching proxy with the virtual hosting tokens "
"in place. This makes sense if there is a web "
"server in front of your caching proxy performing "
"the rewrites necessary to translate a user-"
"facing URL into a virtual hosting URL, so that "
"the requests the caching proxy sees have the "
"rewrite information in them. Conversely, if the "
"rewrite is done in or behind the caching proxy, "
"you want to disable this option, so that the "
"PURGE requests use URLs that match those seen "
"by the caching proxy as they come from the "
"client."
),
required=True,
default=False,
)

domains = schema.Tuple(
title=_(u"Domains"),
title=_("Domains"),
description=_(
u"This option is only relevant if you are using "
u"virtual hosting and you have enabled the option "
u"to send PURGE requests with virtual hosting URLs "
u"above. If you your site is served on multiple "
u"domains e.g. http://example.org and "
u"http://www.example.org you may wish to purge "
u"both. If so, list all your domains here"
"This option is only relevant if you are using "
"virtual hosting and you have enabled the option "
"to send PURGE requests with virtual hosting URLs "
"above. If you your site is served on multiple "
"domains e.g. http://example.org and "
"http://www.example.org you may wish to purge "
"both. If so, list all your domains here"
),
required=False,
default=(),
Expand Down Expand Up @@ -115,9 +114,9 @@ def stopThreads(wait=False):
"""

errorHeaders = schema.Tuple(
title=u"Error header names",
title="Error header names",
value_type=schema.ASCIILine(),
default=("x-squid-error",),
)

http_1_1 = schema.Bool(title=u"Use HTTP 1.1 for PURGE request", default=True)
http_1_1 = schema.Bool(title="Use HTTP 1.1 for PURGE request", default=True)
3 changes: 1 addition & 2 deletions plone/cachepurging/paths.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from OFS.interfaces import ITraversable
from z3c.caching.interfaces import IPurgePaths
from zope.component import adapter
Expand All @@ -7,7 +6,7 @@

@implementer(IPurgePaths)
@adapter(ITraversable)
class TraversablePurgePaths(object):
class TraversablePurgePaths:
"""Default purge for OFS.Traversable-style objects"""

def __init__(self, context):
Expand Down
22 changes: 10 additions & 12 deletions plone/cachepurging/purger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""The following is borrowed heavily from Products.CMFSquidTool. That code
is ZPL licensed.
Expand All @@ -15,7 +14,6 @@
from App.config import getConfiguration
from plone.cachepurging.interfaces import IPurger
from six.moves import queue
from six.moves import range
from six.moves.urllib.parse import urlparse
from traceback import format_exception
from zope.interface import implementer
Expand All @@ -33,7 +31,7 @@


@implementer(IPurger)
class DefaultPurger(object):
class DefaultPurger:
def __init__(self, timeout=(3, 27), backlog=0, errorHeaders=("x-squid-error",)):
self.timeout = timeout
self.queues = {}
Expand Down Expand Up @@ -79,9 +77,9 @@ def purgeSync(self, url, httpVerb="PURGE"):
# Avoid leaking a ref to traceback.
del err, msg, tb
xcache = ""
logger.debug("Finished %s for %s: %s %s" % (httpVerb, url, status, xcache))
logger.debug(f"Finished {httpVerb} for {url}: {status} {xcache}")
if xerror:
logger.debug("Error while purging %s:\n%s" % (url, xerror))
logger.debug(f"Error while purging {url}:\n{xerror}")
logger.debug("Completed synchronous purge of %s", url)
return status, xcache, xerror

Expand All @@ -104,7 +102,7 @@ def purgeAsync(self, url, httpVerb="PURGE"):
)

def stopThreads(self, wait=False):
for worker in six.itervalues(self.workers):
for worker in self.workers.values():
worker.stop()
# in case the queue is empty, wake it up so the .stopping flag is seen
for q in self.queues.values():
Expand All @@ -114,7 +112,7 @@ def stopThreads(self, wait=False):
# no problem - self.stopping should be seen.
pass
if wait:
for worker in six.itervalues(self.workers):
for worker in self.workers.values():
worker.join(5)
if worker.is_alive():
logger.warning("Worker thread %s failed to terminate", worker)
Expand Down Expand Up @@ -156,7 +154,7 @@ def __init__(self, queue, host, scheme, producer):
self.producer = producer
self.queue = queue
self.stopping = False
super(Worker, self).__init__(name="PurgeThread for %s://%s" % (scheme, host))
super().__init__(name=f"PurgeThread for {scheme}://{host}")

def stop(self):
self.stopping = True
Expand Down Expand Up @@ -191,17 +189,17 @@ def run(self):
break # all done with this item!
if resp.status_code == requests.codes.not_found:
# not found is valid
logger.debug("Purge URL not found: {0}".format(url))
logger.debug(f"Purge URL not found: {url}")
break # all done with this item!
except Exception:
# All other exceptions are evil - we just disard
# the item. This prevents other logic failures etc
# being retried.
logger.exception("Failed to purge {0}".format(url))
logger.exception(f"Failed to purge {url}")
break
logger.debug(
"Transient failure on {0} for {1}, "
"retrying: {2}".format(httpVerb, url, i)
"Transient failure on {} for {}, "
"retrying: {}".format(httpVerb, url, i)
)

except Exception:
Expand Down
3 changes: 1 addition & 2 deletions plone/cachepurging/rewrite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.cachepurging.interfaces import ICachePurgingSettings
from plone.cachepurging.interfaces import IPurgePathRewriter
from plone.registry.interfaces import IRegistry
Expand All @@ -11,7 +10,7 @@

@implementer(IPurgePathRewriter)
@adapter(Interface)
class DefaultRewriter(object):
class DefaultRewriter:
"""Default rewriter, which is aware of virtual hosting"""

def __init__(self, request):
Expand Down
Loading

0 comments on commit e025513

Please sign in to comment.