diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-02-10 20:38:22 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-02-10 20:38:22 +0100 |
commit | 272d24bc521aa932128ed9ab9a6f20a70d572768 (patch) | |
tree | 1f8a9ec07c09cdcdad333ff650a68580d26ac897 /module/remote/thriftbackend/Processor.py | |
parent | closed #238 (diff) | |
download | pyload-272d24bc521aa932128ed9ab9a6f20a70d572768.tar.xz |
thriftbackend cleanup
Diffstat (limited to 'module/remote/thriftbackend/Processor.py')
-rw-r--r-- | module/remote/thriftbackend/Processor.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/module/remote/thriftbackend/Processor.py b/module/remote/thriftbackend/Processor.py new file mode 100644 index 000000000..b3a0991dd --- /dev/null +++ b/module/remote/thriftbackend/Processor.py @@ -0,0 +1,41 @@ +from thriftgen.pyload import Pyload + +class Processor(Pyload.Processor): + def __init__(self, *args, **kwargs): + Pyload.Processor.__init__(self, *args, **kwargs) + self.authenticated = {} + + def process(self, iprot, oprot): + trans = oprot.trans + if not self.authenticated.has_key(trans): + self.authenticated[trans] = False + oldclose = trans.close + def wrap(): + del self.authenticated[trans] + oldclose() + trans.close = wrap + authenticated = self.authenticated[trans] + (name, type, seqid) = iprot.readMessageBegin() + if name not in self._processMap or (not authenticated and not name == "login"): + iprot.skip(Pyload.TType.STRUCT) + iprot.readMessageEnd() + x = Pyload.TApplicationException(Pyload.TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) + oprot.writeMessageBegin(name, Pyload.TMessageType.EXCEPTION, seqid) + x.write(oprot) + oprot.writeMessageEnd() + oprot.trans.flush() + return + elif not authenticated and name == "login": + args = Pyload.login_args() + args.read(iprot) + iprot.readMessageEnd() + result = Pyload.login_result() + self.authenticated[trans] = self._handler.login(args.username, args.password) + result.success = self.authenticated[trans] + oprot.writeMessageBegin("login", Pyload.TMessageType.REPLY, seqid) + result.write(oprot) + oprot.writeMessageEnd() + oprot.trans.flush() + else: + self._processMap[name](self, seqid, iprot, oprot) + return True
\ No newline at end of file |