Skip to content

Commit

Permalink
pyupgrade --py37-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritsvanrees committed Dec 16, 2021
1 parent b7056ff commit 57bc28f
Show file tree
Hide file tree
Showing 45 changed files with 159 additions and 208 deletions.
1 change: 0 additions & 1 deletion Products/CMFEditions/ArchivistTool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down
9 changes: 4 additions & 5 deletions Products/CMFEditions/CopyModifyMergeRepositoryTool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber,
# Reflab (Vincenzo Di Somma, Francesco Ciriaci, Riccardo Lemmi)
Expand Down Expand Up @@ -231,9 +230,9 @@ def manage_changePolicyDefs(self, policy_list, **kwargs):
raise AssertionError(
"Each policy definition must contain a title and id: %s" % str(item)
)
if not isinstance(item[0], six.string_types):
if not isinstance(item[0], str):
raise AssertionError("Policy id must be a string: %s" % str(item[0]))
if not isinstance(item[1], six.string_types):
if not isinstance(item[1], str):
raise AssertionError("Policy title must be a string: %s" % str(item[1]))
# Get optional Policy class and kwargs.
if len(item) >= 3:
Expand Down Expand Up @@ -462,7 +461,7 @@ def _recursiveSave(self, obj, app_metadata, sys_metadata, autoapply):
# objects
if sys_metadata["originator"] is None:
clone = prep.clone.object
sys_metadata["originator"] = "%s.%s.%s" % (
sys_metadata["originator"] = "{}.{}.{}".format(
prep.history_id,
clone.version_id,
clone.location_id,
Expand Down Expand Up @@ -698,7 +697,7 @@ def _fixIds(self, obj):
object_list = getattr(obj, "_objects", None)
if object_list is not None:
obj._objects = tuple(
[o for o in object_list if o["id"] != orig_id]
o for o in object_list if o["id"] != orig_id
) # noqa
temp_ids.append((real_id, child))
# Make a second pass to move the objects into place if possible
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/KeepLastNVersionsTool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down
3 changes: 1 addition & 2 deletions Products/CMFEditions/ModifierRegistryTool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down Expand Up @@ -196,7 +195,7 @@ def persistent_id(obj):
pid = pers_id(obj)
if pid is not None:
# found a modifier, add the modifiers name to its pid
return "%s/%s" % (pers_id_nameByMeth[pers_id], pid)
return f"{pers_id_nameByMeth[pers_id]}/{pid}"

def persistent_load(named_pid):
# call the right modifiers persistent_load callback
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/Modifiers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2005 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/Permissions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/ReferenceFactoriesTool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2005 Gregoire Weber.
# All Rights Reserved.
Expand Down
35 changes: 17 additions & 18 deletions Products/CMFEditions/StandardModifiers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2005 Alberto Berti, Gregoire Weber,
# Reflab(Vincenzo Di Somma, Francesco Ciriaci, Riccardo Lemmi),
Expand Down Expand Up @@ -725,24 +724,24 @@ def getOnCloneModifiers(self, obj):
return

component_bases = dict(
registry=dict(
(id(aq_base(base)), aq_base(base)) for base in registry.__bases__
),
utilities=dict(
(id(aq_base(base)), aq_base(base))
registry={
id(aq_base(base)): aq_base(base) for base in registry.__bases__
},
utilities={
id(aq_base(base)): aq_base(base)
for base in registry.utilities.__bases__
),
adapters=dict(
(id(aq_base(base)), aq_base(base))
},
adapters={
id(aq_base(base)): aq_base(base)
for base in registry.adapters.__bases__
),
},
)

def persistent_id(obj):
obj_id = id(aq_base(obj))
for key, bases in six.iteritems(component_bases):
for key, bases in component_bases.items():
if obj_id in bases:
return "%s:%s" % (key, obj_id)
return f"{key}:{obj_id}"
return None

def persistent_load(obj):
Expand Down Expand Up @@ -872,7 +871,7 @@ def _getFieldValues(self, obj):
# Skip linked Pdata chains too long for the pickler
if hasattr(aq_base(val), "getSize") and callable(val.getSize):
size = val.getSize()
if isinstance(size, six.integer_types) and size >= max_size:
if isinstance(size, int) and size >= max_size:
yield "attribute", name, val

def getOnCloneModifiers(self, obj):
Expand All @@ -888,7 +887,7 @@ def getOnCloneModifiers(self, obj):
_empty_marker = []


class LargeFilePlaceHolder(object):
class LargeFilePlaceHolder:
"""PlaceHolder for a large object"""

@staticmethod
Expand Down Expand Up @@ -972,11 +971,11 @@ def getOnCloneModifiers(self, obj):
if not blob_file_classes:
return

blob_refs = set(
blob_refs = {
id(v)
for v in six.itervalues(obj.__dict__)
for v in obj.__dict__.values()
if isinstance(v, blob_file_classes)
)
}

def persistent_id(obj):
if id(aq_base(obj)) in blob_refs:
Expand All @@ -1001,7 +1000,7 @@ def afterRetrieveModifier(self, obj, repo_clone, preserve=()):

blob_fields = (
(k, v)
for k, v in six.iteritems(obj.__dict__)
for k, v in obj.__dict__.items()
if isinstance(v, blob_file_classes)
)

Expand Down
47 changes: 23 additions & 24 deletions Products/CMFEditions/StorageMigrationSupport.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2006 Gregoire Weber
# All Rights Reserved.
Expand Down Expand Up @@ -61,10 +60,10 @@ def editEvent(context, version=0):
location = "0: %s event location" % name
contact = "0: %s event contact" % name
else:
title = "%s%s" % (version, title[1:])
desc = "%s%s" % (version, desc[1:])
location = "%s%s" % (version, location[1:])
contact = "%s%s" % (version, contact[1:])
title = f"{version}{title[1:]}"
desc = f"{version}{desc[1:]}"
location = f"{version}{location[1:]}"
contact = f"{version}{contact[1:]}"

context.update(
title=title,
Expand All @@ -85,9 +84,9 @@ def editFile(context, version=0):
desc = "0: %s file description" % name
file = 100 * ("0: %s file body\n" % name)
else:
title = "%s%s" % (version, title[1:])
desc = "%s%s" % (version, desc[1:])
file = 100 * ("%s%s" % (version, ": %s file body\n" % name))
title = f"{version}{title[1:]}"
desc = f"{version}{desc[1:]}"
file = 100 * ("{}{}".format(version, ": %s file body\n" % name))
context.update(title=title, description=desc, file=file)


Expand All @@ -98,8 +97,8 @@ def editFolder(context, version=0):
if not title:
title = "0: %s folder title" % name
desc = "0: %s folder description" % name
title = "%s%s" % (version, title[1:])
desc = "%s%s" % (version, desc[1:])
title = f"{version}{title[1:]}"
desc = f"{version}{desc[1:]}"
context.folder_edit(title=title, description=desc)


Expand All @@ -110,16 +109,16 @@ def editImage(context, version=0):
name = context.getId()
if name.endswith(".gif"):
name = name[:-4]
filename = "%s_v%s.gif" % (name, version)
filename = f"{name}_v{version}.gif"
path = os.path.join(PACKAGE_HOME, "tests", "images", filename)
with open(path) as image_handle:
image = image_handle.read()
if not title:
title = "0: %s image title" % name
desc = "0: %s image description" % name
else:
title = "%s%s" % (version, title[1:])
desc = "%s%s" % (version, desc[1:])
title = f"{version}{title[1:]}"
desc = f"{version}{desc[1:]}"
context.update(title=title, description=desc, image=image)


Expand All @@ -133,9 +132,9 @@ def editLink(context, version=0):
desc = "0: %s link description" % name
remoteUrl = "http://www.plone.org/#%s_v0" % name
else:
title = "%s%s" % (version, title[1:])
desc = "%s%s" % (version, desc[1:])
remoteUrl = "%s%s" % (remoteUrl[:-1], version)
title = f"{version}{title[1:]}"
desc = f"{version}{desc[1:]}"
remoteUrl = f"{remoteUrl[:-1]}{version}"
context.update(title=title, description=desc, remoteUrl=remoteUrl)


Expand All @@ -149,9 +148,9 @@ def editNewsItem(context, version=0):
desc = "0: %s news item description" % name
text = "0: %s news item body" % name
else:
title = "%s%s" % (version, title[1:])
desc = "%s%s" % (version, desc[1:])
text = "%s%s" % (version, text[1:])
title = f"{version}{title[1:]}"
desc = f"{version}{desc[1:]}"
text = f"{version}{text[1:]}"
context.update(title=title, description=desc, text=text)


Expand All @@ -165,9 +164,9 @@ def editDocument(context, version=0):
desc = "0: %s document description" % name
text = "0: %s document body" % name
else:
title = "%s%s" % (version, title[1:])
desc = "%s%s" % (version, desc[1:])
text = "%s%s" % (version, text[1:])
title = f"{version}{title[1:]}"
desc = f"{version}{desc[1:]}"
text = f"{version}{text[1:]}"
context.update(title=title, description=desc, text=text)


Expand Down Expand Up @@ -208,7 +207,7 @@ def createTestHierarchy(context):
for name, type in hierarchy.items():
logger.log(
logging.INFO,
"createTestHierarchy: creating container %s(%s)" % (name, type[0]),
f"createTestHierarchy: creating container {name}({type[0]})",
)
folder = create(testRoot, type[0], name)
nbrOfObjects += 1
Expand All @@ -225,7 +224,7 @@ def createTestHierarchy(context):
objName = name[:-1] + str(i + 1) + ext
logger.log(
logging.INFO,
"createTestHierarchy: creating %s(%s)" % (objName, type[1]),
f"createTestHierarchy: creating {objName}({type[1]})",
)
obj = create(folder, type[1], objName)
nbrOfObjects += 1
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/VersionPolicies.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alec Mitchell
# All Rights Reserved.
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/ZVCStorageTool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005, 2006 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2003, 2004, 2005 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/browser/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
7 changes: 2 additions & 5 deletions Products/CMFEditions/browser/diff.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# -*- coding: utf-8 -*-

from Acquisition import aq_inner
from Products.CMFCore.utils import getToolByName
from Products.CMFEditions import CMFEditionsMessageFactory as _
from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from six.moves import range
from zope.i18n import translate


class DiffView(BrowserView):
template = ViewPageTemplateFile("diff.pt")

def __init__(self, *args):
super(DiffView, self).__init__(*args)
super().__init__(*args)
self.repo_tool = getToolByName(self.context, "portal_repository")

def getVersion(self, version):
Expand All @@ -34,7 +31,7 @@ def versionTitle(self, version):
version_name = self.versionName(version)

return translate(
_(u"version ${version}", mapping=dict(version=version_name)),
_("version ${version}", mapping=dict(version=version_name)),
context=self.request,
)

Expand Down
2 changes: 1 addition & 1 deletion Products/CMFEditions/browser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_macros(self, vdata):
return versionPreviewTemplate.macros["main"]
except KeyError:
logger.warn(
'Missing TAL macros {0} in template "{1}".'.format(
'Missing TAL macros {} in template "{}".'.format(
", ".join(macro_names), versionPreviewMethodName
)
)
2 changes: 1 addition & 1 deletion Products/CMFEditions/browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __call__(self):
obj = portal_repository.retrieve(context, version_id).object
working_copy_tag = obj.tag()
altPos = working_copy_tag.find("alt=")
tag = '<img src="%s/file_download_version?version_id=%s" %s' % (
tag = '<img src="{}/file_download_version?version_id={}" {}'.format(
here_url,
version_id,
working_copy_tag[altPos:],
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/exportimport/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
#
3 changes: 1 addition & 2 deletions Products/CMFEditions/exportimport/repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from Products.CMFCore.utils import getToolByName
from Products.CMFEditions.VersionPolicies import VersionPolicy
from Products.GenericSetup.utils import exportObjects
Expand Down Expand Up @@ -74,7 +73,7 @@ def _extractPolicies(self):
p.setAttribute("title", policy.Title())
klass = type(policy)
if klass is not VersionPolicy:
p.setAttribute("class", "%s.%s" % (klass.__module__, klass.__name__))
p.setAttribute("class", f"{klass.__module__}.{klass.__name__}")
node.appendChild(p)
return node

Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/historyidhandlertool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/interfaces/IArchivist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/interfaces/IModifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber,
# Reflab(Vincenzo Di Somma, Francesco Ciriaci, Riccardo Lemmi),
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/interfaces/IPurgePolicy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2006 Gregoire Weber.
# All Rights Reserved.
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/interfaces/IReferenceFactories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2005 Gregoire Weber.
# All Rights Reserved.
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/interfaces/IRepository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/interfaces/IStorage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down
1 change: 0 additions & 1 deletion Products/CMFEditions/interfaces/IVersionPolicy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#########################################################################
# Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber.
# All Rights Reserved.
Expand Down
Loading

0 comments on commit 57bc28f

Please sign in to comment.