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

« back to all changes in this revision

Viewing changes to twisted/vfs/ivfs.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
from zope.interface import Interface, Attribute
 
2
 
 
3
class VFSError(Exception):
 
4
    """Base class for all VFS errors."""
 
5
 
 
6
class PermissionError(VFSError):
 
7
    """The user does not have permission to perform the requested operation."""
 
8
 
 
9
class NotFoundError(VFSError):
 
10
    """The file or directory does not exist."""
 
11
 
 
12
class AlreadyExistsError(VFSError):
 
13
    """The file or directory already exists."""
 
14
 
 
15
 
 
16
class IFileSystemNode(Interface):
 
17
 
 
18
    parent = Attribute(
 
19
        """parent node"""
 
20
    )
 
21
 
 
22
    def getMetadata():
 
23
        """
 
24
        returns a map of arbitrary metadata. As an example, here's what SFTP
 
25
        expects (but doesn't require):
 
26
 
 
27
            - C{'size'}: size of file in bytes
 
28
            - C{'uid'}: owner of the file
 
29
            - C{'gid'}: group owner of the file
 
30
            - C{'permissions'}: file permissions
 
31
            - C{'atime'}: last time the file was accessed
 
32
            - C{'mtime'}: last time the file was modified
 
33
            - C{'nlink'}: number of links to the file
 
34
 
 
35
        Protocols that need metadata should handle the case when a particular
 
36
        value isn't available as gracefully as possible.
 
37
        """
 
38
 
 
39
    # XXX: There should be a setMetadata, probably taking a map of the same form
 
40
    # returned by getMetadata (although obviously keys like 'nlink' aren't
 
41
    # settable.  Something like:
 
42
    # def setMetadata(metadata):
 
43
    #     """Sets metadata for a node.
 
44
    #
 
45
    #     Unrecognised keys will be ignored (but invalid values for a recognised
 
46
    #     key may cause an error to be raised).
 
47
    #     
 
48
    #     Typical keys are 'permissions', 'uid', 'gid', 'atime' and 'mtime'.
 
49
    #     
 
50
    #     @param metadata: a dict, like the one getMetadata returns.
 
51
    #     """
 
52
    # osfs.OSNode implements this; other backends should be similarly updated.
 
53
    #   -- spiv, 2006-06-02
 
54
 
 
55
    def remove():
 
56
        """
 
57
        Removes this node.
 
58
        An error is raised if the node is a directory and is not empty.
 
59
        """
 
60
 
 
61
    def rename(newName):
 
62
        """
 
63
        Renames this node to newName.  newName can be in a different
 
64
        directory.  If the destination is an existing directory, an
 
65
        error will be raised.
 
66
        """
 
67
 
 
68
 
 
69
class IFileSystemLeaf(IFileSystemNode):
 
70
    def open(flags):
 
71
        """
 
72
        Opens the file with flags. Flags should be a bitmask based on
 
73
        the os.O_* flags.
 
74
        """
 
75
 
 
76
    def close():
 
77
        """closes this node"""
 
78
 
 
79
    def readChunk(offset, length):
 
80
        """
 
81
        Leaf should have been previously opened with suitable flags.
 
82
        Reads length bytes or until the end of file from this leaf from
 
83
        the given offset.
 
84
        """
 
85
 
 
86
    def writeChunk(offset, data):
 
87
        """
 
88
        Leaf should have been previously opened with suitable flags.
 
89
        Writes data to leaf from the given offset.
 
90
        """
 
91
 
 
92
class IFileSystemContainer(IFileSystemNode):
 
93
 
 
94
    def children():
 
95
        """
 
96
        returns a list of 2 element tuples
 
97
        [ ( path, nodeObject ) ]
 
98
        """
 
99
 
 
100
    def child(childName):
 
101
        """
 
102
        Returns a node object for child childName
 
103
 
 
104
        @raises NotFoundError if no child with that name exists.
 
105
        """
 
106
 
 
107
    def createDirectory(childName):
 
108
        """
 
109
        Creates a new folder named childName under this folder.
 
110
        An error is raised if the folder already exists.
 
111
        """
 
112
 
 
113
    def createFile(childName, exclusive=True):
 
114
        """
 
115
        Creates a new file named childName under this folder.
 
116
 
 
117
        If exclusive is True (the default), an AlreadyExistsError is raised if
 
118
        the file already exists.
 
119
        """
 
120
 
 
121
    def exists(childName):
 
122
        """
 
123
        returns True if container has a child childName, False otherwise
 
124
        """