source: TI05-delivery/trunk/lib/python/pybbftp/client.py @ 1288

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/lib/python/pybbftp/client.py@1288
Revision 1288, 2.5 KB checked in by spascoe, 13 years ago (diff)

Renamed the delivery package pybbftp. This reflects the nature of
the package as a binding between bbftp and python.

Line 
1"""
2Interface to the BBftp client.
3
4@copyright Copyright (C) 2006 CCLRC & NERC
5@license This software may be distributed under the terms of the Q Public Licence, version 1.0 or later.
6
7@author Stephen Pascoe
8"""
9
10import sys
11if sys.modules.has_key('delivery.bbftpd') and not sys.modules.has_key('epydoc'):
12    raise ImportError, "delivery.bbftpd extension already loaded.  You cannot use both client and server extensions together"
13
14import bbftpc
15
16#--------------------------------------------------------------------------------------------------------------
17
18def connect(authClientHandler, args):
19    """Connect to the bbftp server.
20
21    @param authClientHandler an instance of AuthClientHandler
22    @param args a list of command line arguments passed to the client code.
23    @return a list of bbftp client output messages.
24    """
25   
26    return bbftpc.connect(authClientHandler, args)
27
28def close():
29    """Close the connection.
30    """
31
32    if isConnected():
33        return bbftpc.close()
34
35def isConnected():
36    """Returns a bool indicating whether we are connected to a server.
37    """
38
39    return bbftpc.isConnected()
40
41def docommand(cmd):
42    """Execute a BBFtp command.
43
44    @param cmd a string containing the command.
45    @return a list of BBFtp client messages in response.
46    """
47
48    return bbftpc.docommand(cmd)
49
50#--------------------------------------------------------------------------------------------------------------
51
52
53
54class AuthClientHandler(object):
55    """Abstract base class specifying the client authentication callback interface.
56    """
57
58    def send(self, buffer):
59        """Send a message to the server during authentication.
60
61        This method must only be used from within self.authenticate() called from connect().
62
63        @param buffer a string containing the message to send.
64        """
65
66        return bbftpc.send(buffer)
67
68    def recv(self):
69        """Receive a message from the server during authentication.
70
71        This method must only be used from within self.authenticate() called from connect().
72
73        @return a string containing the message received.
74        """
75
76        return bbftpc.recv()
77   
78    def authenticate(self):
79        """Authenticate with the server.
80
81        This method should be overridden in subclasses to implement authentication using
82        the method calls self.send() and send.recv().  It is called by the bbftp layer from within
83        connect().
84
85        @return a value indicating success or failure.
86        """
87       
88        raise NotImplementedError
Note: See TracBrowser for help on using the repository browser.