Ejemplo n.º 1
0
    def test_timeout(self):
        # fake time function to avoid a time.sleep in tests
        def faketime(t):
            zope.app.locking.storage.timefunc = lambda: t

        # test the cleanup of timedout locks.
        content = File('some content', 'text/plain')
        lockable = ILockable(content)
        participation = Participation(Principal('michael'))
        zope.security.management.newInteraction(participation)
        now = time.time()
        faketime(now)
        lockinfo = lockable.lock(timeout=1)
        lockinfo.created = now
        # two seconds pass
        faketime(now + 2.0)
        # now lockable.locked is False since the lock has timed out
        self.assertEqual(lockable.locked(), False)
        # since lockable.locked is False lockable.lock should succeed
        # assume this is done 3 seconds after the first lock
        lockinfo = lockable.lock(timeout=20)
        lockinfo.created = now + 3.0
        faketime(now + 4.0)  # let time pass
        self.assertEqual(lockable.locked(), True)
        zope.security.management.endInteraction()
        # reset the time function
        zope.app.locking.storage.timefunc = time.time
Ejemplo n.º 2
0
    def __call__(self, name, content_type, data):
        if not content_type and data:
            content_type, _width, _height = getImageInfo(data)
        if not content_type:
            content_type, _encoding = guess_content_type(name, data, '')

        if content_type.startswith('image/'):
            return Image(data)

        return File(data, content_type)
Ejemplo n.º 3
0
    def test_folder_lock(self):
        folder = Folder()
        file = File('some content', 'text/plain')
        folder['file'] = file

        participation = Participation(Principal('michael'))
        zope.security.management.newInteraction(participation)

        lockablefolder = ILockable(folder)
        lockablefolder.lock()
        self.assertEqual(lockablefolder.locked(), True)
        lockablefile = ILockable(folder['file'])
        self.assertEqual(lockablefile.locked(), False)

        zope.security.management.endInteraction()
Ejemplo n.º 4
0
 def __init__(self, data='', contentType='', filename=None):
     File.__init__(self, data, contentType)
     self.filename = filename
Ejemplo n.º 5
0
 def update_object(self, data, contenttype):
     f = File(data, contenttype)
     zope.event.notify(lifecycleevent.ObjectCreatedEvent(f))
     self.context.add(f)
     self.request.response.redirect(self.context.nextURL())
     return ''
Ejemplo n.º 6
0
 def addFile(self):
     file = File(self.content)
     root = self.getRootFolder()
     root['file'] = file
     self.commit()
Ejemplo n.º 7
0
 def __init__(self, data='', contentType='', filename=None):
     File.__init__(self, data, contentType)
     self.filename=filename