~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-17 14:52:35 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20070117145235-btmig6qfmqfen0om
Tags: 2.5.0-0ubuntu1
New upstream version, compatible with python2.5.

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