Skip to content

Commit

Permalink
Merge pull request #17 from plone/python3
Browse files Browse the repository at this point in the history
Python3
  • Loading branch information
jensens authored Aug 17, 2018
2 parents 839205b + 3ab128e commit 6496390
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 29 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ New features:

Bug fixes:

- *add item here*
- More Python 2 / 3 compatibility fixes.
[thet]


2.2.2 (2018-02-05)
Expand Down
4 changes: 2 additions & 2 deletions plone/locking/browser/locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def _getNiceTimeDifference(self, baseTime):
days = int(round(now - DateTime(baseTime)))
delta = timedelta(now - DateTime(baseTime))
days = delta.days
hours = int(delta.seconds / 3600)
minutes = (delta.seconds - (hours * 3600)) / 60
hours = delta.seconds // 3600
minutes = (delta.seconds - (hours * 3600)) // 60

dateString = u""
if days == 0:
Expand Down
2 changes: 1 addition & 1 deletion plone/locking/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Timeouts are expressed in minutes
DEFAULT_TIMEOUT = 10
MAX_TIMEOUT = ((2 ** 32) - 1) / 60
MAX_TIMEOUT = ((2 ** 32) - 1) // 60


class ILockType(Interface):
Expand Down
13 changes: 9 additions & 4 deletions plone/locking/lockable.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from zope.interface import implementer
from zope.component import adapts, queryAdapter
from zope.component import adapter, queryAdapter

from persistent.dict import PersistentDict

from zope.annotation.interfaces import IAnnotations
from zope.component import getUtility

from AccessControl import getSecurityManager
from webdav.LockItem import LockItem
try:
from OFS.LockItem import LockItem
except ImportError:
# Zope2
from webdav.LockItem import LockItem

from plone.registry.interfaces import IRegistry
from Products.CMFPlone.interfaces import IEditingSchema
Expand All @@ -28,11 +32,11 @@ def safeWrite(*args):
ANNOTATION_KEY = 'plone.locking'


@adapter(ITTWLockable)
@implementer(IRefreshableLockable)
class TTWLockable(object):
"""An object that is being locked through-the-web
"""
adapts(ITTWLockable)

def __init__(self, context):
self.context = context
Expand All @@ -50,7 +54,8 @@ def lock(self, lock_type=STEALABLE_LOCK, children=False):
if not self.locked():
user = getSecurityManager().getUser()
depth = children and 'infinity' or 0
lock = LockItem(user, depth=depth, timeout=lock_type.timeout * 60)
timeout = int(lock_type.timeout * 60)
lock = LockItem(user, depth=depth, timeout=timeout)
token = lock.getLockToken()
self.context._v_safe_write = True
self.context.wl_setLock(token, lock)
Expand Down
5 changes: 2 additions & 3 deletions plone/locking/testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
from plone.app.testing import applyProfile
from plone.app.testing import PloneSandboxLayer
from plone.app.testing.layers import FunctionalTesting
Expand All @@ -8,14 +9,12 @@


class PloneLockingLayer(PloneSandboxLayer):
defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)

def setUpZope(self, app, configurationContext):
import plone.locking
self.loadZCML(package=plone.locking)

def setUpPloneSite(self, portal):
applyProfile(portal, 'plone.app.contenttypes:default')


PLONE_LOCKING_FIXTURE = PloneLockingLayer()

Expand Down
24 changes: 6 additions & 18 deletions plone/locking/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,11 @@
import unittest


doctests = (
'locking.rst',
)


def add_member(portal, username):
portal_membership = getToolByName(portal, 'portal_membership')
portal_membership.addMember(username, 'secret', ('Member', ), [])


def setup(doctest):
portal = doctest.globs['layer']['portal']
add_member(portal, 'member1', )
add_member(portal, 'member2', )
portal_membership = getToolByName(portal, 'portal_membership')
portal_membership.addMember('member1', 'secret', ('Member', ), [])
portal_membership.addMember('member2', 'secret', ('Member', ), [])

logout()
login(portal, 'member1')
Expand All @@ -35,18 +26,15 @@ def setup(doctest):

def test_suite():
suite = unittest.TestSuite()
tests = [
suite.addTest(
layered(
doctest.DocFileSuite(
'tests/{0}'.format(test_file),
'tests/locking.rst',
package='plone.locking',
optionflags=optionflags,
setUp=setup,
),
layer=PLONE_LOCKING_FUNCTIONAL_TESTING,
)
for test_file in doctests
]
suite.addTests(tests)
)
return suite

0 comments on commit 6496390

Please sign in to comment.