Skip to content

Commit

Permalink
chore: pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Apr 1, 2023
1 parent 40e02f3 commit 1f1670d
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 25 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__)
1 change: 0 additions & 1 deletion plone/memoize/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
3 changes: 1 addition & 2 deletions plone/memoize/compress.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""XHTML Compressor
"""

Expand All @@ -22,7 +21,7 @@ def xhtml_compress(string):


@implementer(IXHTMLCompressor)
class XHTMLSlimmer(object):
class XHTMLSlimmer:
def compress(self, string):
if SLIMMER:
return xhtml_slimmer(string)
Expand Down
1 change: 0 additions & 1 deletion plone/memoize/forever.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Memo decorators for globals - memoized values survive for as long as the
process lives.
Expand Down
3 changes: 1 addition & 2 deletions plone/memoize/instance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Memo decorators for instances.
Stores values in an attribute on the instance. See instance.rst.
Expand All @@ -11,7 +10,7 @@
_marker = object()


class Memojito(object):
class Memojito:
propname = "_memojito_"

def clear(self, inst):
Expand Down
1 change: 0 additions & 1 deletion plone/memoize/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from zope.interface import Interface


Expand Down
7 changes: 3 additions & 4 deletions plone/memoize/ram.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""A cache decorator that uses RAMCache by default.
"""

Expand Down Expand Up @@ -40,7 +39,7 @@ def __init__(self, client, globalkey=""):
self.globalkey = globalkey and "%s:" % globalkey

def _make_key(self, source):
if issubclass(type(source), six.text_type):
if issubclass(type(source), str):
source = source.encode("utf-8")
return sha1(source).hexdigest()

Expand All @@ -62,7 +61,7 @@ def __init__(self, ramcache, globalkey=""):
self.globalkey = globalkey

def _make_key(self, source):
if issubclass(type(source), six.text_type):
if issubclass(type(source), str):
source = source.encode("utf-8")
return sha1(source).digest()

Expand All @@ -87,7 +86,7 @@ def choose_cache(fun_name):


def store_in_cache(fun, *args, **kwargs):
key = "%s.%s" % (fun.__module__, fun.__name__)
key = f"{fun.__module__}.{fun.__name__}"
cache_chooser = component.queryUtility(ICacheChooser)
if cache_chooser is not None:
return cache_chooser(key)
Expand Down
3 changes: 1 addition & 2 deletions plone/memoize/request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Memoize decorator for methods.
Stores values in an annotation of the request.
Expand All @@ -19,7 +18,7 @@
_marker = object()


class RequestMemo(object):
class RequestMemo:

key = "plone.memoize_request"

Expand Down
1 change: 0 additions & 1 deletion plone/memoize/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from zope.component.testing import setUp
from zope.component.testing import tearDown
from zope.configuration.xmlconfig import XMLConfig
Expand Down
3 changes: 1 addition & 2 deletions plone/memoize/view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Memoize decorator for views.
Stores values in an annotation of the request. See view.rst.
Expand All @@ -15,7 +14,7 @@ def getRequest():
return None


class ViewMemo(object):
class ViewMemo:

key = "plone.memoize"

Expand Down
11 changes: 5 additions & 6 deletions plone/memoize/volatile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""A flexible caching decorator.
This module provides a cache decorator `cache` that you can use to
Expand All @@ -18,18 +17,18 @@ class CleanupDict(dict):
cleanup_period = 60 * 60 * 24 * 3 # 3 days

def __init__(self, cleanup_period=None):
super(CleanupDict, self).__init__()
super().__init__()
self._last_access = {}
if cleanup_period is not None:
self.cleanup_period = cleanup_period

def __getitem__(self, key):
value = super(CleanupDict, self).__getitem__(key)
value = super().__getitem__(key)
self._last_access[key] = time.time()
return value

def __setitem__(self, key, value):
super(CleanupDict, self).__setitem__(key, value)
super().__setitem__(key, value)
self._last_access[key] = time.time()
self._cleanup()

Expand All @@ -39,7 +38,7 @@ def _cleanup(self):
for key, timestamp in list(self._last_access.items()):
if timestamp < okay:
del self._last_access[key]
super(CleanupDict, self).__delitem__(key)
super().__delitem__(key)


ATTR = "_v_memoize_cache"
Expand Down Expand Up @@ -67,7 +66,7 @@ def replacement(*args, **kwargs):
key = get_key(fun, *args, **kwargs)
except DontCache:
return fun(*args, **kwargs)
key = "%s.%s:%s" % (fun.__module__, fun.__name__, key)
key = f"{fun.__module__}.{fun.__name__}:{key}"
cache = get_cache(fun, *args, **kwargs)
cached_value = cache.get(key, _marker)
if cached_value is _marker:
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from setuptools import find_packages
from setuptools import setup

Expand All @@ -11,7 +10,7 @@ def read(*rnames):

version = "3.0.1.dev0"

long_description = u"\n".join(
long_description = "\n".join(
[read("README.rst"), read("plone", "memoize", "README.rst"), read("CHANGES.rst"),]
)

Expand Down

0 comments on commit 1f1670d

Please sign in to comment.