comparison mercurial/sshserver.py @ 11625:cdeb861335d5

protocol: wrap non-string protocol responses in classes
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Tue, 20 Jul 2010 20:53:33 +0200
parents 31d0a6d50ee2
children c327bfa5e831
comparison
equal deleted inserted replaced
11624:67260651d09d 11625:cdeb861335d5
70 self.fout.write("%d\n" % len(v)) 70 self.fout.write("%d\n" % len(v))
71 self.fout.write(v) 71 self.fout.write(v)
72 self.fout.flush() 72 self.fout.flush()
73 73
74 def sendstream(self, source): 74 def sendstream(self, source):
75 for chunk in source: 75 for chunk in source.gen:
76 self.fout.write(chunk) 76 self.fout.write(chunk)
77 self.fout.flush() 77 self.fout.flush()
78 78
79 def sendpushresponse(self, ret): 79 def sendpushresponse(self, rsp):
80 self.sendresponse('') 80 self.sendresponse('')
81 self.sendresponse(str(ret)) 81 self.sendresponse(str(rsp.res))
82 82
83 def serve_forever(self): 83 def serve_forever(self):
84 try: 84 try:
85 while self.serve_one(): 85 while self.serve_one():
86 pass 86 pass
87 finally: 87 finally:
88 if self.lock is not None: 88 if self.lock is not None:
89 self.lock.release() 89 self.lock.release()
90 sys.exit(0) 90 sys.exit(0)
91 91
92 handlers = {
93 str: sendresponse,
94 wireproto.streamres: sendstream,
95 wireproto.pushres: sendpushresponse,
96 }
97
92 def serve_one(self): 98 def serve_one(self):
93 cmd = self.fin.readline()[:-1] 99 cmd = self.fin.readline()[:-1]
94 if cmd and cmd in wireproto.commands: 100 if cmd and cmd in wireproto.commands:
95 wireproto.dispatch(self.repo, self, cmd) 101 rsp = wireproto.dispatch(self.repo, self, cmd)
102 self.handlers[rsp.__class__](self, rsp)
96 elif cmd: 103 elif cmd:
97 impl = getattr(self, 'do_' + cmd, None) 104 impl = getattr(self, 'do_' + cmd, None)
98 if impl: 105 if impl:
99 r = impl() 106 r = impl()
100 if r is not None: 107 if r is not None: