X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fpython%2Fdolcon%2F__init__.py;fp=lib%2Fpython%2Fdolcon%2F__init__.py;h=e7adb29ec4644989a11632ba694d479c7abe8325;hb=fbe30a6da13729c16770608bb5a7f11d79b22fb2;hp=0000000000000000000000000000000000000000;hpb=05fe12f8b0ff970b8fa04b6c4b68ae20c48c4e09;p=doldaconnect.git diff --git a/lib/python/dolcon/__init__.py b/lib/python/dolcon/__init__.py new file mode 100644 index 0000000..e7adb29 --- /dev/null +++ b/lib/python/dolcon/__init__.py @@ -0,0 +1,41 @@ +from dolmod import * + +def login(useauthless = True, **kw): + result = [None] + def mycb(*v): + result[0] = v + loginasync(mycb, useauthless, **kw) + while result[0] is None: + select() + return result[0] + +def mustconnect(host, port = -1): + connect(host, port) + while True: + resp = getresp() + if resp is not None and resp.getcmd() == u".connect": + break + select() + if resp.getcode() != 200: + raise RuntimeError, resp.intresp()[0][0] + +def cnl(host, port = -1, useauthless = True, **kw): + mustconnect(host, port) + err, reason = login(useauthless, **kw) + if err != "success": + raise RuntimeError, (err, reason) + +def ecmd(*args): + tag = qcmd(*args) + while True: + resp = getresp(tag) + if resp is not None: + break; + select() + return resp + +def ecmda(code, *args): + resp = ecmd(*args) + if resp.getcode() != code: + raise ValueError, resp.getcode() + return resp