Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zope-container
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
zope-container
Commits
71bc46f4
Commit
71bc46f4
authored
Jan 30, 2009
by
Jan-Wijbrand Kolman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make filepresentation work for zope.container.folder.Folder
parent
4c64fee3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
139 additions
and
4 deletions
+139
-4
src/zope/container/configure.zcml
src/zope/container/configure.zcml
+19
-0
src/zope/container/directory.py
src/zope/container/directory.py
+58
-2
src/zope/container/folder.py
src/zope/container/folder.py
+8
-2
src/zope/container/interfaces.py
src/zope/container/interfaces.py
+4
-0
src/zope/container/tests/directory.txt
src/zope/container/tests/directory.txt
+43
-0
src/zope/container/tests/test_directory.py
src/zope/container/tests/test_directory.py
+7
-0
No files found.
src/zope/container/configure.zcml
View file @
71bc46f4
...
@@ -5,6 +5,11 @@
...
@@ -5,6 +5,11 @@
i18n_domain="zope"
i18n_domain="zope"
>
>
<interface
interface=".interfaces.IContentContainer"
type="zope.app.content.interfaces.IContentType"
/>
<adapter
<adapter
provides=".interfaces.IFind"
provides=".interfaces.IFind"
for=".interfaces.IReadContainer"
for=".interfaces.IReadContainer"
...
@@ -24,6 +29,20 @@
...
@@ -24,6 +29,20 @@
factory=".directory.noop"
factory=".directory.noop"
/>
/>
<adapter
for=".interfaces.IContentContainer"
provides="zope.filerepresentation.interfaces.IDirectoryFactory"
factory="zope.container.directory.Cloner"
permission="zope.ManageContent"
/>
<adapter
for=".interfaces.IContentContainer"
provides="zope.filerepresentation.interfaces.IReadDirectory"
factory=".filerepresentation.ReadDirectory"
permission="zope.View"
/>
<adapter
<adapter
factory="zope.container.traversal.ContainerTraversable"
factory="zope.container.traversal.ContainerTraversable"
provides="zope.traversing.interfaces.ITraversable"
provides="zope.traversing.interfaces.ITraversable"
...
...
src/zope/container/directory.py
View file @
71bc46f4
...
@@ -25,10 +25,14 @@ $Id$
...
@@ -25,10 +25,14 @@ $Id$
"""
"""
__docformat__
=
'restructuredtext'
__docformat__
=
'restructuredtext'
import
zope.filerepresentation.interfaces
from
zope.security.proxy
import
removeSecurityProxy
from
zope.interface
import
implements
from
zope.interface
import
implements
from
zope.location.interfaces
import
ISite
from
zope.security.proxy
import
removeSecurityProxy
import
zope.filerepresentation.interfaces
MARKER
=
object
()
def
noop
(
container
):
def
noop
(
container
):
"""Adapt an `IContainer` to an `IWriteDirectory` by just returning it
"""Adapt an `IContainer` to an `IWriteDirectory` by just returning it
...
@@ -60,3 +64,55 @@ class Cloner(object):
...
@@ -60,3 +64,55 @@ class Cloner(object):
# exciting side effects as a result of instantiation. :)
# exciting side effects as a result of instantiation. :)
return
removeSecurityProxy
(
self
.
context
).
__class__
()
return
removeSecurityProxy
(
self
.
context
).
__class__
()
class
RootDirectoryFactory
(
object
):
def
__init__
(
self
,
context
):
pass
def
__call__
(
self
,
name
):
return
Folder
()
class
ReadDirectory
(
object
):
"""Adapter to provide a file-system rendition of folders."""
def
__init__
(
self
,
context
):
self
.
context
=
context
def
keys
(
self
):
keys
=
self
.
context
.
keys
()
if
ISite
.
providedBy
(
self
.
context
):
return
list
(
keys
)
+
[
'++etc++site'
]
return
keys
def
get
(
self
,
key
,
default
=
None
):
if
key
==
'++etc++site'
and
ISite
.
providedBy
(
self
.
context
):
return
self
.
context
.
getSiteManager
()
return
self
.
context
.
get
(
key
,
default
)
def
__iter__
(
self
):
return
iter
(
self
.
keys
())
def
__getitem__
(
self
,
key
):
v
=
self
.
get
(
key
,
MARKER
)
if
v
is
MARKER
:
raise
KeyError
(
key
)
return
v
def
values
(
self
):
return
map
(
self
.
get
,
self
.
keys
())
def
__len__
(
self
):
l
=
len
(
self
.
context
)
if
ISite
.
providedBy
(
self
.
context
):
l
+=
1
return
l
def
items
(
self
):
get
=
self
.
get
return
[(
key
,
get
(
key
))
for
key
in
self
.
keys
()]
def
__contains__
(
self
,
key
):
return
self
.
get
(
key
)
is
not
None
src/zope/container/folder.py
View file @
71bc46f4
...
@@ -19,15 +19,21 @@ __docformat__ = 'restructuredtext'
...
@@ -19,15 +19,21 @@ __docformat__ = 'restructuredtext'
from
BTrees.OOBTree
import
OOBTree
from
BTrees.OOBTree
import
OOBTree
from
persistent
import
Persistent
from
persistent
import
Persistent
from
zope.container.interfaces
import
IContainer
from
zope.container.interfaces
import
IContainer
,
IContentContainer
from
zope.container.contained
import
Contained
,
setitem
,
uncontained
from
zope.container.contained
import
Contained
,
setitem
,
uncontained
from
zope.exceptions
import
DuplicationError
from
zope.exceptions
import
DuplicationError
from
zope.interface
import
implements
,
directlyProvides
from
zope.interface
import
implements
,
directlyProvides
# XXX This container implementation is really only used by
# zope.site.folder.Folder. Please do not use it.
# XXX Check whether this IContainer implementation cannot really
# be replaced by the BTreeContainer.
class
Folder
(
Persistent
,
Contained
):
class
Folder
(
Persistent
,
Contained
):
"""The standard Zope Folder implementation."""
"""The standard Zope Folder implementation."""
implements
(
IContainer
)
implements
(
ICont
entCont
ainer
)
def
__init__
(
self
):
def
__init__
(
self
):
self
.
data
=
OOBTree
()
self
.
data
=
OOBTree
()
...
...
src/zope/container/interfaces.py
View file @
71bc46f4
...
@@ -126,6 +126,10 @@ class IContainer(IReadContainer, IWriteContainer):
...
@@ -126,6 +126,10 @@ class IContainer(IReadContainer, IWriteContainer):
"""Readable and writable content container."""
"""Readable and writable content container."""
class
IContentContainer
(
IContainer
):
"""A container that is to be used as a content type."""
class
IBTreeContainer
(
IContainer
):
class
IBTreeContainer
(
IContainer
):
"""Container that supports BTree semantics for some methods."""
"""Container that supports BTree semantics for some methods."""
...
...
src/zope/container/tests/directory.txt
0 → 100644
View file @
71bc46f4
===============================
File representation for folders
===============================
Folders can be represented in file-system-like protocols (e.g. FTP). An
adapter abstracts some internals away and adds support for accessing the
'++etc++site' folder from those protocols.
>>> from zope.container.folder import Folder
>>> from zope.container.directory import ReadDirectory
>>> folder = Folder()
The new folder isn't a site manager and doesn't have any entries:
>>> fs_folder = ReadDirectory(folder)
>>> list(fs_folder.keys())
[]
>>> fs_folder.get('test', )
>>> fs_folder['test']
Traceback (most recent call last):
KeyError: 'test'
>>> list(fs_folder.__iter__())
[]
>>> fs_folder.values()
[]
>>> len(fs_folder)
0
>>> fs_folder.items()
[]
>>> 'test' in fs_folder
False
This is a short regression test for #728: we get a KeyError when trying to
access non-existing entries:
>>> from zope.security.proxy import ProxyFactory
>>> from zope.security.checker import NamesChecker
>>> proxied_folder = ProxyFactory(fs_folder, NamesChecker(('get',)))
>>> proxied_fs_folder = ReadDirectory(proxied_folder)
>>> print proxied_fs_folder['i dont exist']
Traceback (most recent call last):
KeyError: 'i dont exist'
src/zope/container/tests/test_directory.py
View file @
71bc46f4
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
$Id$
$Id$
"""
"""
from
unittest
import
TestCase
,
TestSuite
,
main
,
makeSuite
from
unittest
import
TestCase
,
TestSuite
,
main
,
makeSuite
from
zope.testing
import
doctest
from
zope.container
import
testing
import
zope.container.directory
import
zope.container.directory
class
Directory
(
object
):
class
Directory
(
object
):
...
@@ -31,8 +34,12 @@ class Test(TestCase):
...
@@ -31,8 +34,12 @@ class Test(TestCase):
self
.
assertEqual
(
clone
.
__class__
,
d
.
__class__
)
self
.
assertEqual
(
clone
.
__class__
,
d
.
__class__
)
def
test_suite
():
def
test_suite
():
flags
=
doctest
.
ELLIPSIS
|
doctest
.
NORMALIZE_WHITESPACE
return
TestSuite
((
return
TestSuite
((
makeSuite
(
Test
),
makeSuite
(
Test
),
doctest
.
DocFileSuite
(
"directory.txt"
,
setUp
=
testing
.
setUp
,
tearDown
=
testing
.
tearDown
,
optionflags
=
flags
),
))
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment