-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix up zope.app after moving zope.app.filerepresentation to zope.file…
…representation
- Loading branch information
Showing
2 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__() |