~landscape/zope3/newer-from-ztk

« back to all changes in this revision

Viewing changes to src/twisted/vfs/backends/adhoc.py

  • Committer: Thomas Hervé
  • Date: 2009-07-08 13:52:04 UTC
  • Revision ID: thomas@canonical.com-20090708135204-df5eesrthifpylf8
Remove twisted copy

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Ad-hoc backend for VFS."""
2
 
 
3
 
from zope.interface import implements
4
 
 
5
 
from twisted.vfs import ivfs
6
 
 
7
 
class AdhocDirectory:
8
 
    """Ad-hoc directory.
9
 
 
10
 
    Can contain arbitrary other directories (but not files) as children.
11
 
    """
12
 
 
13
 
    implements(ivfs.IFileSystemContainer)
14
 
 
15
 
    def __init__(self, children=None, name=None, parent=None):
16
 
        if not parent : self.parent = self
17
 
        else : self.parent = parent
18
 
        self.name = name
19
 
        if children is None:
20
 
            children = {}
21
 
        self._children = children
22
 
 
23
 
    def children(self):
24
 
        return [ ('.', self), ('..', self.parent) ] + [
25
 
            ( childName, self.child(childName) )
26
 
            for childName in self._children.keys() ]
27
 
 
28
 
    def child(self, childName):
29
 
        try:
30
 
            return self._children[childName]
31
 
        except KeyError:
32
 
            raise ivfs.NotFoundError(childName)
33
 
 
34
 
    def getMetadata(self):
35
 
        return {}
36
 
 
37
 
    def exists(self, childName):
38
 
        return self._children.has_key(childName)
39
 
 
40
 
    def putChild(self, name, node):
41
 
        node.parent = self
42
 
        self._children[name] = node
43
 
 
44
 
    def createDirectory(self, childName):
45
 
        # Users cannot add directories to an AdhocDirectory, so raise
46
 
        # PermissionError.
47
 
        raise ivfs.PermissionError()
48
 
    
49
 
    def createFile(self, childName, exclusive=True):
50
 
        # AdhocDirectories cannot contain files directly, so give permission
51
 
        # denied if someone tries to create one.
52
 
        raise ivfs.PermissionError()
53