~landscape/zope3/newer-from-ztk

« back to all changes in this revision

Viewing changes to src/twisted/conch/interfaces.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
 
from zope.interface import Interface
2
 
 
3
 
class IConchUser(Interface):
4
 
    """A user who has been authenticated to Cred through Conch.  This is 
5
 
    the interface between the SSH connection and the user.
6
 
 
7
 
    @ivar conn: The SSHConnection object for this user.
8
 
    """
9
 
 
10
 
    def lookupChannel(channelType, windowSize, maxPacket, data):
11
 
        """
12
 
        The other side requested a channel of some sort.
13
 
        channelType is the type of channel being requested,
14
 
        windowSize is the initial size of the remote window,
15
 
        maxPacket is the largest packet we should send,
16
 
        data is any other packet data (often nothing).
17
 
 
18
 
        We return a subclass of L{SSHChannel<ssh.channel.SSHChannel>}.  If
19
 
        an appropriate channel can not be found, an exception will be
20
 
        raised.  If a L{ConchError<error.ConchError>} is raised, the .value
21
 
        will be the message, and the .data will be the error code.
22
 
 
23
 
        @type channelType:  C{str}
24
 
        @type windowSize:   C{int}
25
 
        @type maxPacket:    C{int}
26
 
        @type data:         C{str}
27
 
        @rtype:             subclass of L{SSHChannel}/C{tuple}
28
 
        """
29
 
 
30
 
    def lookupSubsystem(subsystem, data):
31
 
        """
32
 
        The other side requested a subsystem.
33
 
        subsystem is the name of the subsystem being requested.
34
 
        data is any other packet data (often nothing).
35
 
        
36
 
        We return a L{Protocol}.
37
 
        """
38
 
 
39
 
    def gotGlobalRequest(requestType, data):
40
 
        """
41
 
        A global request was sent from the other side.
42
 
        
43
 
        By default, this dispatches to a method 'channel_channelType' with any
44
 
        non-alphanumerics in the channelType replace with _'s.  If it cannot 
45
 
        find a suitable method, it returns an OPEN_UNKNOWN_CHANNEL_TYPE error. 
46
 
        The method is called with arguments of windowSize, maxPacket, data.
47
 
        """
48
 
 
49
 
class ISession(Interface):
50
 
 
51
 
    def getPty(term, windowSize, modes):
52
 
        """
53
 
        Get a psuedo-terminal for use by a shell or command.
54
 
 
55
 
        If a psuedo-terminal is not available, or the request otherwise
56
 
        fails, raise an exception.
57
 
        """
58
 
 
59
 
    def openShell(proto):
60
 
        """
61
 
        Open a shell and connect it to proto.
62
 
 
63
 
        @param proto: a L{ProcessProtocol} instance.
64
 
        """
65
 
 
66
 
    def execCommand(proto, command):
67
 
        """
68
 
        Execute a command.
69
 
 
70
 
        @param proto: a L{ProcessProtocol} instance.
71
 
        """
72
 
 
73
 
    def windowChanged(newWindowSize):
74
 
        """
75
 
        Called when the size of the remote screen has changed.
76
 
        """
77
 
 
78
 
    def eofReceived():
79
 
        """
80
 
        Called when the other side has indicated no more data will be sent.
81
 
        """
82
 
        
83
 
    def closed():
84
 
        """
85
 
        Called when the session is closed.
86
 
        """
87
 
 
88
 
 
89
 
class ISFTPServer(Interface):
90
 
    """
91
 
    The only attribute of this class is "avatar".  It is the avatar
92
 
    returned by the Realm that we are authenticated with, and
93
 
    represents the logged-in user.  Each method should check to verify
94
 
    that the user has permission for their actions.
95
 
    """
96
 
 
97
 
    def gotVersion(otherVersion, extData):
98
 
        """
99
 
        Called when the client sends their version info.
100
 
 
101
 
        otherVersion is an integer representing the version of the SFTP
102
 
        protocol they are claiming.
103
 
        extData is a dictionary of extended_name : extended_data items.
104
 
        These items are sent by the client to indicate additional features.
105
 
 
106
 
        This method should return a dictionary of extended_name : extended_data
107
 
        items.  These items are the additional features (if any) supported
108
 
        by the server.
109
 
        """
110
 
        return {}
111
 
 
112
 
    def openFile(filename, flags, attrs):
113
 
        """
114
 
        Called when the clients asks to open a file.
115
 
 
116
 
        @param filename: a string representing the file to open.
117
 
 
118
 
        @param flags: an integer of the flags to open the file with, ORed together.
119
 
        The flags and their values are listed at the bottom of this file.
120
 
 
121
 
        @param attrs: a list of attributes to open the file with.  It is a
122
 
        dictionary, consisting of 0 or more keys.  The possible keys are::
123
 
 
124
 
            size: the size of the file in bytes
125
 
            uid: the user ID of the file as an integer
126
 
            gid: the group ID of the file as an integer
127
 
            permissions: the permissions of the file with as an integer.
128
 
            the bit representation of this field is defined by POSIX.
129
 
            atime: the access time of the file as seconds since the epoch.
130
 
            mtime: the modification time of the file as seconds since the epoch.
131
 
            ext_*: extended attributes.  The server is not required to
132
 
            understand this, but it may.
133
 
 
134
 
        NOTE: there is no way to indicate text or binary files.  it is up
135
 
        to the SFTP client to deal with this.
136
 
 
137
 
        This method returns an object that meets the ISFTPFile interface.
138
 
        Alternatively, it can return a L{Deferred} that will be called back
139
 
        with the object.
140
 
        """
141
 
 
142
 
    def removeFile(filename):
143
 
        """
144
 
        Remove the given file.
145
 
 
146
 
        This method returns when the remove succeeds, or a Deferred that is
147
 
        called back when it succeeds.
148
 
 
149
 
        @param filename: the name of the file as a string.
150
 
        """
151
 
 
152
 
    def renameFile(oldpath, newpath):
153
 
        """
154
 
        Rename the given file.
155
 
 
156
 
        This method returns when the rename succeeds, or a L{Deferred} that is
157
 
        called back when it succeeds.
158
 
 
159
 
        @param oldpath: the current location of the file.
160
 
        @param newpath: the new file name.
161
 
        """
162
 
 
163
 
    def makeDirectory(path, attrs):
164
 
        """
165
 
        Make a directory.
166
 
 
167
 
        This method returns when the directory is created, or a Deferred that
168
 
        is called back when it is created.
169
 
 
170
 
        @param path: the name of the directory to create as a string.
171
 
        @param attrs: a dictionary of attributes to create the directory with.
172
 
        Its meaning is the same as the attrs in the L{openFile} method.
173
 
        """
174
 
 
175
 
    def removeDirectory(path):
176
 
        """
177
 
        Remove a directory (non-recursively)
178
 
 
179
 
        It is an error to remove a directory that has files or directories in
180
 
        it.
181
 
 
182
 
        This method returns when the directory is removed, or a Deferred that
183
 
        is called back when it is removed.
184
 
 
185
 
        @param path: the directory to remove.
186
 
        """
187
 
 
188
 
    def openDirectory(path):
189
 
        """
190
 
        Open a directory for scanning.
191
 
 
192
 
        This method returns an iterable object that has a close() method,
193
 
        or a Deferred that is called back with same.
194
 
 
195
 
        The close() method is called when the client is finished reading
196
 
        from the directory.  At this point, the iterable will no longer
197
 
        be used.
198
 
 
199
 
        The iterable should return triples of the form (filename,
200
 
        longname, attrs) or Deferreds that return the same.  The
201
 
        sequence must support __getitem__, but otherwise may be any
202
 
        'sequence-like' object.
203
 
 
204
 
        filename is the name of the file relative to the directory.
205
 
        logname is an expanded format of the filename.  The recommended format
206
 
        is:
207
 
        -rwxr-xr-x   1 mjos     staff      348911 Mar 25 14:29 t-filexfer
208
 
        1234567890 123 12345678 12345678 12345678 123456789012
209
 
 
210
 
        The first line is sample output, the second is the length of the field.
211
 
        The fields are: permissions, link count, user owner, group owner,
212
 
        size in bytes, modification time.
213
 
 
214
 
        attrs is a dictionary in the format of the attrs argument to openFile.
215
 
 
216
 
        @param path: the directory to open.
217
 
        """
218
 
 
219
 
    def getAttrs(path, followLinks):
220
 
        """
221
 
        Return the attributes for the given path.
222
 
 
223
 
        This method returns a dictionary in the same format as the attrs
224
 
        argument to openFile or a Deferred that is called back with same.
225
 
 
226
 
        @param path: the path to return attributes for as a string.
227
 
        @param followLinks: a boolean.  If it is True, follow symbolic links
228
 
        and return attributes for the real path at the base.  If it is False,
229
 
        return attributes for the specified path.
230
 
        """
231
 
 
232
 
    def setAttrs(path, attrs):
233
 
        """
234
 
        Set the attributes for the path.
235
 
 
236
 
        This method returns when the attributes are set or a Deferred that is
237
 
        called back when they are.
238
 
 
239
 
        @param path: the path to set attributes for as a string.
240
 
        @param attrs: a dictionary in the same format as the attrs argument to
241
 
        L{openFile}.
242
 
        """
243
 
 
244
 
    def readLink(path):
245
 
        """
246
 
        Find the root of a set of symbolic links.
247
 
 
248
 
        This method returns the target of the link, or a Deferred that
249
 
        returns the same.
250
 
 
251
 
        @param path: the path of the symlink to read.
252
 
        """
253
 
 
254
 
    def makeLink(linkPath, targetPath):
255
 
        """
256
 
        Create a symbolic link.
257
 
 
258
 
        This method returns when the link is made, or a Deferred that
259
 
        returns the same.
260
 
 
261
 
        @param linkPath: the pathname of the symlink as a string.
262
 
        @param targetPath: the path of the target of the link as a string.
263
 
        """
264
 
 
265
 
    def realPath(path):
266
 
        """
267
 
        Convert any path to an absolute path.
268
 
 
269
 
        This method returns the absolute path as a string, or a Deferred
270
 
        that returns the same.
271
 
 
272
 
        @param path: the path to convert as a string.
273
 
        """
274
 
 
275
 
    def extendedRequest(extendedName, extendedData):
276
 
        """
277
 
        This is the extension mechanism for SFTP.  The other side can send us
278
 
        arbitrary requests.
279
 
 
280
 
        If we don't implement the request given by extendedName, raise
281
 
        NotImplementedError.
282
 
 
283
 
        The return value is a string, or a Deferred that will be called
284
 
        back with a string.
285
 
 
286
 
        @param extendedName: the name of the request as a string.
287
 
        @param extendedData: the data the other side sent with the request,
288
 
        as a string.
289
 
        """
290
 
 
291
 
class ISFTPFile(Interface):
292
 
    """
293
 
    This represents an open file on the server.  An object adhering to this
294
 
    interface should be returned from L{openFile}().
295
 
    """
296
 
 
297
 
    def close():
298
 
        """
299
 
        Close the file.
300
 
 
301
 
        This method returns nothing if the close succeeds immediately, or a
302
 
        Deferred that is called back when the close succeeds.
303
 
        """
304
 
 
305
 
    def readChunk(offset, length):
306
 
        """
307
 
        Read from the file.
308
 
 
309
 
        If EOF is reached before any data is read, raise EOFError.
310
 
 
311
 
        This method returns the data as a string, or a Deferred that is
312
 
        called back with same.
313
 
 
314
 
        @param offset: an integer that is the index to start from in the file.
315
 
        @param length: the maximum length of data to return.  The actual amount
316
 
        returned may less than this.  For normal disk files, however,
317
 
        this should read the requested number (up to the end of the file).
318
 
        """
319
 
 
320
 
    def writeChunk(offset, data):
321
 
        """
322
 
        Write to the file.
323
 
 
324
 
        This method returns when the write completes, or a Deferred that is
325
 
        called when it completes.
326
 
 
327
 
        @param offset: an integer that is the index to start from in the file.
328
 
        @param data: a string that is the data to write.
329
 
        """
330
 
 
331
 
    def getAttrs():
332
 
        """
333
 
        Return the attributes for the file.
334
 
 
335
 
        This method returns a dictionary in the same format as the attrs
336
 
        argument to L{openFile} or a L{Deferred} that is called back with same.
337
 
        """
338
 
 
339
 
    def setAttrs(attrs):
340
 
        """
341
 
        Set the attributes for the file.
342
 
 
343
 
        This method returns when the attributes are set or a Deferred that is
344
 
        called back when they are.
345
 
 
346
 
        @param attrs: a dictionary in the same format as the attrs argument to
347
 
        L{openFile}.
348
 
        """
349
 
 
350