Skip to content

Commit

Permalink
chore: pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Apr 15, 2023
1 parent 217771a commit 3260c06
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 75 deletions.
1 change: 0 additions & 1 deletion src/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 src/plone/folder/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
9 changes: 4 additions & 5 deletions src/plone/folder/default.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from BTrees.OIBTree import OIBTree
from persistent.list import PersistentList
from plone.folder.interfaces import IExplicitOrdering
Expand All @@ -13,7 +12,7 @@

@implementer(IExplicitOrdering)
@adapter(IOrderableFolder)
class DefaultOrdering(object):
class DefaultOrdering:
""" This implementation uses annotations to store the order on the
object, and supports explicit ordering. """

Expand Down Expand Up @@ -55,7 +54,7 @@ def moveObjectsByDelta(
order = self._order()
pos = self._pos()
min_position = 0
if isinstance(ids, six.string_types):
if isinstance(ids, str):
ids = [ids]
if subset_ids is None:
subset_ids = self.idsInOrder()
Expand Down Expand Up @@ -95,7 +94,7 @@ def moveObjectsByDelta(
idx += 1
except KeyError:
raise ValueError(
'No object with id "{0:s}" exists.'.format(obj_id)
f'No object with id "{obj_id:s}" exists.'
)
if not suppress_events:
notifyContainerModified(self.context)
Expand Down Expand Up @@ -155,7 +154,7 @@ def getObjectPosition(self, obj_id):
pos = self._pos()
if obj_id in pos:
return pos[obj_id]
raise ValueError('No object with id "{0:s}" exists in "{1:s}".'.format(
raise ValueError('No object with id "{:s}" exists in "{:s}".'.format(
obj_id, '/'.join(self.context.getPhysicalPath())))

def idsInOrder(self):
Expand Down
3 changes: 1 addition & 2 deletions src/plone/folder/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 All @@ -16,7 +15,7 @@ class IOrderableFolder(IFolder):
def getOrdering():
""" return the currently active ordering adapter for this folder """

def setOrdering(ordering=u''):
def setOrdering(ordering=''):
""" (re)set ordering adapter to be used for this folder """


Expand Down
3 changes: 1 addition & 2 deletions src/plone/folder/nogopip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_base
from App.special_dtml import DTMLFile
from inspect import currentframe
Expand Down Expand Up @@ -72,7 +71,7 @@ class GopipIndex(StubIndex):
keyForDocument = 42

def __init__(self, id, extra=None, caller=None):
super(GopipIndex, self).__init__(id)
super().__init__(id)
self.catalog = aq_base(caller._catalog)

def __len__(self):
Expand Down
17 changes: 8 additions & 9 deletions src/plone/folder/ordered.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from AccessControl import ClassSecurityInfo
from AccessControl.Permissions import access_contents_information
from AccessControl.Permissions import manage_properties
Expand Down Expand Up @@ -33,7 +32,7 @@ class OrderedBTreeFolderBase(BTreeFolder2Base):
is done by a named adapter (to IOrdering), which makes the policy
changeable. """

_ordering = u'' # name of adapter defining ordering policy
_ordering = '' # name of adapter defining ordering policy

security = ClassSecurityInfo()

Expand All @@ -50,7 +49,7 @@ def getOrdering(self):
return adapter

@security.protected(manage_properties)
def setOrdering(self, ordering=u''):
def setOrdering(self, ordering=''):
""" (re)set ordering adapter to be used for this folder """
if ordering:
# make sure the adapter exists...
Expand All @@ -62,28 +61,28 @@ def setOrdering(self, ordering=u''):
def _getOb(self, id, default=_marker):
""" Return the named object from the folder. """
try:
return super(OrderedBTreeFolderBase, self)._getOb(id, default)
return super()._getOb(id, default)
except KeyError as e:
raise AttributeError(e)

def _setOb(self, id, object):
""" Store the named object in the folder. """
super(OrderedBTreeFolderBase, self)._setOb(id, object)
super()._setOb(id, object)
self.getOrdering().notifyAdded(id) # notify the ordering adapter

def _delOb(self, id):
""" Remove the named object from the folder. """
super(OrderedBTreeFolderBase, self)._delOb(id)
super()._delOb(id)
self.getOrdering().notifyRemoved(id) # notify the ordering adapter

def objectIds(self, spec=None, ordered=True):
if not ordered:
return super(OrderedBTreeFolderBase, self).objectIds(spec)
return super().objectIds(spec)
ordering = self.getOrdering()
if spec is None:
return ordering.idsInOrder()
else:
ids = super(OrderedBTreeFolderBase, self).objectIds(spec)
ids = super().objectIds(spec)
idxs = []
for id in ids:
idxs.append((ordering.getObjectPosition(id), id))
Expand Down Expand Up @@ -196,7 +195,7 @@ def iterkeys(self):
def manage_renameObject(self, id, new_id, REQUEST=None):
""" Rename a particular sub-object without changing its position. """
old_position = self.getObjectPosition(id)
result = super(OrderedBTreeFolderBase, self).manage_renameObject(
result = super().manage_renameObject(
id,
new_id,
REQUEST
Expand Down
4 changes: 2 additions & 2 deletions src/plone/folder/partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


@implementer(IExplicitOrdering)
class PartialOrdering(object):
class PartialOrdering:
""" this implementation uses a list to store order information on a
regular attribute of the folderish object; explicit ordering
is supported """
Expand Down Expand Up @@ -70,7 +70,7 @@ def moveObjectsByDelta(self, ids, delta, subset_ids=None,
suppress_events=False):
""" see interfaces.py """
min_position = 0
if isinstance(ids, six.string_types):
if isinstance(ids, str):
ids = [ids]
if subset_ids is None:
subset_ids = self.idsInOrder(onlyOrderables=True)
Expand Down
1 change: 0 additions & 1 deletion src/plone/folder/testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
from plone.app.testing import PLONE_FIXTURE
Expand Down
2 changes: 0 additions & 2 deletions src/plone/folder/tests/benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# simple benchmarking tests related to plip191
# to run individual tests using:
# $ bin/instance test -s plone.folder --tests-pattern=benchmarks -t <testName>
Expand All @@ -8,7 +7,6 @@
from plone.folder.tests.layer import PloneFolderLayer
from plone.folder.tests.utils import DummyObject
from profilehooks import timecall
from six.moves import range
from unittest import defaultTestLoader
from unittest import TestCase

Expand Down
23 changes: 11 additions & 12 deletions src/plone/folder/tests/test_dict_interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_base
from plone.folder.ordered import OrderedBTreeFolderBase
from plone.folder.testing import PLONEFOLDER_INTEGRATION_TESTING
Expand Down Expand Up @@ -37,19 +36,19 @@ def test_delitem(self):
folder = OrderedBTreeFolderBase("f1")
folder._setOb('foo', DummyObject('foo'))
folder._setOb('bar', DummyObject('bar'))
self.assertEquals(len(folder.objectIds()), 2)
self.assertEqual(len(folder.objectIds()), 2)
del folder['foo']
del folder['bar']
self.assertEquals(len(folder.objectIds()), 0)
self.assertEqual(len(folder.objectIds()), 0)

def test_len_empty_folder(self):
folder = OrderedBTreeFolderBase("f1")
self.assertEquals(len(folder), 0)
self.assertEqual(len(folder), 0)

def test_len_one_child(self):
folder = OrderedBTreeFolderBase("f1")
folder['child'] = DummyObject('child')
self.assertEquals(len(folder), 1)
self.assertEqual(len(folder), 1)

def test_to_verify_ticket_9120(self):
folder = OrderedBTreeFolderBase("f1")
Expand All @@ -59,9 +58,9 @@ def test_to_verify_ticket_9120(self):
folder['ob4'] = ob4 = DummyObject('ob4')
del folder['ob2']
del folder['ob3']
self.assertEquals(folder.keys(), ['ob1', 'ob4'])
self.assertEquals(list(map(aq_base, folder.values())), [ob1, ob4])
self.assertEquals([key in folder for key in folder], [True, True])
self.assertEqual(folder.keys(), ['ob1', 'ob4'])
self.assertEqual(list(map(aq_base, folder.values())), [ob1, ob4])
self.assertEqual([key in folder for key in folder], [True, True])


class RelatedToDictInterfaceTests(unittest.TestCase):
Expand All @@ -79,9 +78,9 @@ def create(self):

def testObjectIdsWithSpec(self):
folder = self.create()
self.assertEquals(['o1', 'o3'], folder.objectIds(spec='mt1'))
self.assertEquals(['o2', 'o4'], folder.objectIds(spec='mt2'))
self.assertEqual(['o1', 'o3'], folder.objectIds(spec='mt1'))
self.assertEqual(['o2', 'o4'], folder.objectIds(spec='mt2'))
folder.moveObjectsToTop(['o3'])
folder.moveObjectsDown(['o2'])
self.assertEquals(['o3', 'o1'], folder.objectIds(spec='mt1'))
self.assertEquals(['o4', 'o2'], folder.objectIds(spec='mt2'))
self.assertEqual(['o3', 'o1'], folder.objectIds(spec='mt1'))
self.assertEqual(['o4', 'o2'], folder.objectIds(spec='mt2'))
3 changes: 1 addition & 2 deletions src/plone/folder/tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
from Acquisition import Implicit
from plone.folder.interfaces import IOrderable
from plone.folder.ordered import OrderedBTreeFolderBase
from plone.folder.testing import PLONEFOLDER_FUNCTIONAL_TESTING
from six import BytesIO
from io import BytesIO
from transaction import savepoint
from zope.interface import implementer

Expand Down
1 change: 0 additions & 1 deletion src/plone/folder/tests/test_ordering_adapters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.folder.default import DefaultOrdering
from plone.folder.ordered import OrderedBTreeFolderBase
from plone.folder.testing import PLONEFOLDER_INTEGRATION_TESTING
Expand Down
35 changes: 17 additions & 18 deletions src/plone/folder/tests/test_ordersupport.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from OFS.Traversable import Traversable
from plone.folder.interfaces import IOrdering
from plone.folder.ordered import OrderedBTreeFolderBase
Expand Down Expand Up @@ -33,59 +32,59 @@ def create(self):

def test_objectIdsOrdered(self):
folder = self.create()
self.assertEquals(["o1", "o2", "o3", "o4"], folder.objectIds())
self.assertEqual(["o1", "o2", "o3", "o4"], folder.objectIds())
folder.moveObjectsUp(("o2",), 1)
self.assertEquals(["o2", "o1", "o3", "o4"], folder.objectIds())
self.assertEqual(["o2", "o1", "o3", "o4"], folder.objectIds())

def test_objectValuesOrdered(self):
folder = self.create()
self.assertEquals(
self.assertEqual(
["o1", "o2", "o3", "o4"],
[x.id for x in folder.objectValues()]
)
folder.moveObjectsUp(("o2",), 1)
self.assertEquals(
self.assertEqual(
["o2", "o1", "o3", "o4"],
[x.id for x in folder.objectValues()]
)

def test_objectItemsOrdered(self):
folder = self.create()
self.assertEquals(
self.assertEqual(
["o1", "o2", "o3", "o4"],
[x for x, y in folder.objectItems()]
)
folder.moveObjectsUp(("o2",), 1)
self.assertEquals(
self.assertEqual(
["o2", "o1", "o3", "o4"],
[x for x, y in folder.objectItems()]
)

def test_iterkeys(self):
folder = self.create()
self.assertEquals(
self.assertEqual(
["o1", "o2", "o3", "o4"],
[x for x in six.iterkeys(folder)]
[x for x in folder.keys()]
)
folder.moveObjectsUp(("o2",), 1)
self.assertEquals(
self.assertEqual(
["o2", "o1", "o3", "o4"],
[x for x in six.iterkeys(folder)]
[x for x in folder.keys()]
)

def test_iter(self):
folder = self.create()
self.assertEquals(["o1", "o2", "o3", "o4"], [x for x in folder])
self.assertEqual(["o1", "o2", "o3", "o4"], [x for x in folder])
folder.moveObjectsUp(("o2",), 1)
self.assertEquals(["o2", "o1", "o3", "o4"], [x for x in folder])
self.assertEqual(["o2", "o1", "o3", "o4"], [x for x in folder])

def test_getitem(self):
ordering = IOrdering(self.create())
self.assertEquals(ordering[1], 'o2')
self.assertEquals(ordering[-1], 'o4')
self.assertEquals(ordering[1:2], ['o2'])
self.assertEquals(ordering[1:-1], ['o2', 'o3'])
self.assertEquals(ordering[1:], ['o2', 'o3', 'o4'])
self.assertEqual(ordering[1], 'o2')
self.assertEqual(ordering[-1], 'o4')
self.assertEqual(ordering[1:2], ['o2'])
self.assertEqual(ordering[1:-1], ['o2', 'o3'])
self.assertEqual(ordering[1:], ['o2', 'o3', 'o4'])

# Tests borrowed from OFS.tests.testsOrderSupport

Expand Down
10 changes: 5 additions & 5 deletions src/plone/folder/tests/test_partialordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PartialOrderingTests(unittest.TestCase):

def create(self):
container = OrderedBTreeFolderBase()
container.setOrdering(u'partial')
container.setOrdering('partial')
container['o1'] = Orderable('o1', 'mt1')
container['o2'] = Orderable('o2', 'mt2')
container['c1'] = Chaoticle('c1', 'mt3')
Expand Down Expand Up @@ -47,7 +47,7 @@ def testNotifyAdded(self):
)
self.assertEqual(
set(container.objectIds()),
set(['o1', 'o2', 'o3', 'o4', 'o5', 'c1', 'c2', 'c3'])
{'o1', 'o2', 'o3', 'o4', 'o5', 'c1', 'c2', 'c3'}
)

def testNotifyRemoved(self):
Expand All @@ -63,7 +63,7 @@ def testNotifyRemoved(self):
)
self.assertEqual(
set(container.objectIds()),
set(['o1', 'o2', 'o4', 'c1', 'c2', 'c3'])
{'o1', 'o2', 'o4', 'c1', 'c2', 'c3'}
)
container._delOb('o1')
self.assertEqual(
Expand All @@ -72,7 +72,7 @@ def testNotifyRemoved(self):
)
self.assertEqual(
set(container.objectIds()),
set(['o2', 'o4', 'c1', 'c2', 'c3'])
{'o2', 'o4', 'c1', 'c2', 'c3'}
)

def runTableTests(self, action, tests):
Expand Down Expand Up @@ -194,7 +194,7 @@ class DummyFolder(OrderedBTreeFolderBase, Implicit):
""" we need to mix in acquisition """

meta_type = 'DummyFolder'
_ordering = u'partial'
_ordering = 'partial'

def dummy_method(self):
return self.id
Expand Down
Loading

0 comments on commit 3260c06

Please sign in to comment.