From ff076c0adebb0b8495465cb59531046eb158eab9 Mon Sep 17 00:00:00 2001 From: fredrik Date: Wed, 22 Nov 2006 15:48:43 +0000 Subject: [PATCH] Add docstrings for the functions. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/doldaconnect@751 959494ce-11ee-0310-bf91-de5d638817bd --- lib/python/dolcon/__init__.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lib/python/dolcon/__init__.py b/lib/python/dolcon/__init__.py index d8a2b75..11cb6d4 100644 --- a/lib/python/dolcon/__init__.py +++ b/lib/python/dolcon/__init__.py @@ -2,6 +2,21 @@ from dolmod import * import os def login(useauthless = True, **kw): + """A convenience function for loginasync. + + This function will initiate an asynchronous login per the + loginasync command, and then run a select loop while waiting for + it to complete. It will return a tuple (res, reason), where res is + the result code, and reason is an explanatory text for any error. + + res can be any of the following: + * success: Login completed successfully + * nologin: No authentication mechanism could be negotiated + * server: An error occurred on the server + * user: An error occurred in the library + * conv: The password conversation mechanism failed + * authfail: The server refused the login (due to e.g. bad credentials) + """ result = [None] def mycb(*v): result[0] = v @@ -11,6 +26,13 @@ def login(useauthless = True, **kw): return result[0] def mustconnect(host, port = -1): + """A convenience function for connect. + + This function will connect to the given host, perform a select + loop, and ensure that the server approves of the connection. If + any of these steps fail, an exception is raised. If successful, + the file descriptor for the server connection is returned. + """ fd = connect(host, port) while True: resp = getresp() @@ -22,6 +44,13 @@ def mustconnect(host, port = -1): return fd def cnl(host = None, port = -1, useauthless = True, **kw): + """A convenience function for connect and loginasync. + + This function will connect to the given server, or the server in + the environment variable $DCSERVER if none is given, and + authenticate to the server. If any of the steps fail, an exception + is raised. + """ if host is None: host = os.getenv("DCSERVER") if host is None: @@ -33,6 +62,13 @@ def cnl(host = None, port = -1, useauthless = True, **kw): return fd def ecmd(*args): + """A convenience function for qcmd. + + This function will queue the given command, and then wait in a + select loop until the command has been carried out. The return + value is a Response object, corresponding to the reponse from the + server. + """ tag = qcmd(*args) while True: resp = getresp(tag) @@ -42,6 +78,12 @@ def ecmd(*args): return resp def ecmda(code, *args): + """A convenience function for ecmd. + + This function does essentially the same as ecmd, but it will also + check so that the response has the given numerical code. If not, + an exception is raised. + """ resp = ecmd(*args) if resp.getcode() != code: raise ValueError, resp.getcode() -- 2.11.0