4 def login(useauthless = True, **kw):
5 """A convenience function for loginasync.
7 This function will initiate an asynchronous login per the
8 loginasync command, and then run a select loop while waiting for
9 it to complete. It will return a tuple (res, reason), where res is
10 the result code, and reason is an explanatory text for any error.
12 res can be any of the following:
13 * success: Login completed successfully
14 * nologin: No authentication mechanism could be negotiated
15 * server: An error occurred on the server
16 * user: An error occurred in the library
17 * conv: The password conversation mechanism failed
18 * authfail: The server refused the login (due to e.g. bad credentials)
23 loginasync(mycb, useauthless, **kw)
24 while result[0] is None:
28 def mustconnect(host, port = -1):
29 """A convenience function for connect.
31 This function will connect to the given host, perform a select
32 loop, and ensure that the server approves of the connection. If
33 any of these steps fail, an exception is raised. If successful,
34 the file descriptor for the server connection is returned.
36 fd = connect(host, port)
39 if resp is not None and resp.getcmd() == u".connect":
42 if resp.getcode() != 200:
43 raise RuntimeError, resp.intresp()[0][0]
46 def cnl(host = None, port = -1, useauthless = True, **kw):
47 """A convenience function for connect and loginasync.
49 This function will connect to the given server, or the server in
50 the environment variable $DCSERVER if none is given, and
51 authenticate to the server. If any of the steps fail, an exception
55 host = os.getenv("DCSERVER")
57 raise ValueError, "No DC host to connect to"
58 fd = mustconnect(host, port)
59 err, reason = login(useauthless, **kw)
61 raise RuntimeError, (err, reason)
65 """A convenience function for qcmd.
67 This function will queue the given command, and then wait in a
68 select loop until the command has been carried out. The return
69 value is a Response object, corresponding to the reponse from the
80 def ecmda(code, *args):
81 """A convenience function for ecmd.
83 This function does essentially the same as ecmd, but it will also
84 check so that the response has the given numerical code. If not,
85 an exception is raised.
88 if resp.getcode() != code:
89 raise ValueError, resp.getcode()