Skip to content

Commit

Permalink
Fix up zope.app after moving zope.app.filerepresentation to zope.file…
Browse files Browse the repository at this point in the history
…representation
  • Loading branch information
philikon committed Apr 12, 2006
1 parent 2aed6d0 commit 20a2d4f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

<adapter
for=".interfaces.IReadContainer"
provides="zope.app.filerepresentation.interfaces.IReadDirectory"
provides="zope.filerepresentation.interfaces.IReadDirectory"
factory=".directory.noop"
/>

<adapter
for=".interfaces.IWriteContainer"
provides="zope.app.filerepresentation.interfaces.IWriteDirectory"
provides="zope.filerepresentation.interfaces.IWriteDirectory"
factory=".directory.noop"
/>

Expand Down
62 changes: 62 additions & 0 deletions directory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
##############################################################################
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
##############################################################################
"""File-system representation adapters for containers
This module includes two adapters (adapter factories, really) for
providing a file-system representation for containers:
`noop`
Factory that "adapts" `IContainer` to `IWriteDirectory`.
This is a lie, since it just returns the original object.
`Cloner`
An `IDirectoryFactory` adapter that just clones the original object.
$Id$
"""
__docformat__ = 'restructuredtext'

import zope.filerepresentation.interfaces
from zope.security.proxy import removeSecurityProxy
from zope.interface import implements

def noop(container):
"""Adapt an `IContainer` to an `IWriteDirectory` by just returning it
This "works" because `IContainer` and `IWriteDirectory` have the same
methods, however, the output doesn't actually implement `IWriteDirectory`.
"""
return container


class Cloner(object):
"""`IContainer` to `IDirectoryFactory` adapter that clones
This adapter provides a factory that creates a new empty container
of the same class as it's context.
"""

implements(zope.filerepresentation.interfaces.IDirectoryFactory)

def __init__(self, context):
self.context = context

def __call__(self, name):

# We remove the security proxy so we can actually call the
# class and return an unproxied new object. (We can't use a
# trusted adapter, because the result must be unproxied.) By
# registering this adapter, one effectively gives permission
# to clone the class. Don't use this for classes that have
# exciting side effects as a result of instantiation. :)

return removeSecurityProxy(self.context).__class__()

0 comments on commit 20a2d4f

Please sign in to comment.