def login(self, user, passwd, authsrv): maxbuf, vers = self.rpc.version(16 * 1024, P9.version) if vers != P9.version: raise Error("version mismatch: %r" % vers) afid = self.AFID try: self.rpc.auth(afid, user, '') needauth = 1 except P9.RpcError as e: afid = P9.nofid if afid != P9.nofid: if passwd is None: raise Error("Password required") import P9sk1 try: P9sk1.clientAuth(self.rpc, afid, user, P9sk1.makeKey(passwd), authsrv, P9sk1.AUTHPORT) except socket.error as e: raise Error("%s: %s" % (authsrv, e.args[1])) self.rpc.attach(self.ROOT, afid, user, "") if afid != P9.nofid: self.rpc.clunk(afid) self.rpc.walk(self.ROOT, self.CWD, [])
class Client(object): """ A tiny 9p client. """ AFID = 10 ROOT = 11 CWD = 12 F = 13 def __init__(self, fd, user, passwd, authsrv): self.rpc = P9.RpcClient(fd) self.login(user, passwd, authsrv) def login(self, user, passwd, authsrv): maxbuf, vers = self.rpc.version(16 * 1024, P9.version) if vers != P9.version: raise Error("version mismatch: %r" % vers) afid = self.AFID try: self.rpc.auth(afid, user, '') needauth = 1 except P9.RpcError, e: afid = P9.nofid if afid != P9.nofid: if passwd is None: raise Error("Password required") import P9sk1 try: P9sk1.clientAuth(self.rpc, afid, user, P9sk1.makeKey(passwd), authsrv, P9sk1.AUTHPORT) except socket.error, e: raise Error("%s: %s" % (authsrv, e.args[1]))