fbe30a6d |
1 | from dolmod import * |
c5de778c |
2 | import os |
fbe30a6d |
3 | |
4 | def login(useauthless = True, **kw): |
5 | result = [None] |
6 | def mycb(*v): |
7 | result[0] = v |
8 | loginasync(mycb, useauthless, **kw) |
9 | while result[0] is None: |
10 | select() |
11 | return result[0] |
12 | |
13 | def mustconnect(host, port = -1): |
14 | connect(host, port) |
15 | while True: |
16 | resp = getresp() |
17 | if resp is not None and resp.getcmd() == u".connect": |
18 | break |
19 | select() |
20 | if resp.getcode() != 200: |
21 | raise RuntimeError, resp.intresp()[0][0] |
22 | |
c5de778c |
23 | def cnl(host = None, port = -1, useauthless = True, **kw): |
24 | if host is None: |
25 | host = os.getenv("DCSERVER") |
26 | if host is None: |
27 | raise ValueError, "No DC host to connect to" |
fbe30a6d |
28 | mustconnect(host, port) |
29 | err, reason = login(useauthless, **kw) |
30 | if err != "success": |
31 | raise RuntimeError, (err, reason) |
32 | |
33 | def ecmd(*args): |
34 | tag = qcmd(*args) |
35 | while True: |
36 | resp = getresp(tag) |
37 | if resp is not None: |
38 | break; |
39 | select() |
40 | return resp |
41 | |
42 | def ecmda(code, *args): |
43 | resp = ecmd(*args) |
44 | if resp.getcode() != code: |
45 | raise ValueError, resp.getcode() |
46 | return resp |