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