comparison libervia.tac @ 296:92d76ab67156

server+browser side: fixed bridge errback handling
author Goffi <goffi@goffi.org>
date Tue, 17 Dec 2013 01:35:59 +0100
parents 33e0eb212b14
children 19bcd39c77f6
comparison
equal deleted inserted replaced
295:33e0eb212b14 296:92d76ab67156
49 LIBERVIA_DIR = "output/" 49 LIBERVIA_DIR = "output/"
50 MEDIA_DIR = "media/" 50 MEDIA_DIR = "media/"
51 AVATARS_DIR = "avatars/" 51 AVATARS_DIR = "avatars/"
52 CARDS_DIR = "games/cards/tarot" 52 CARDS_DIR = "games/cards/tarot"
53 53
54 ERRNUM_BRIDGE_ERRBACK = 0 # FIXME
55 ERRNUM_LIBERVIA = 0 # FIXME
56
54 # Security limit for Libervia (get/set params) 57 # Security limit for Libervia (get/set params)
55 SECURITY_LIMIT = 0 58 SECURITY_LIMIT = 0
56 59
57 class ISATSession(Interface): 60 class ISATSession(Interface):
58 profile = Attribute("Sat profile") 61 profile = Attribute("Sat profile")
144 if len(args) != 1: 147 if len(args) != 1:
145 Exception("Multiple return arguments not supported") 148 Exception("Multiple return arguments not supported")
146 d.callback(args[0]) 149 d.callback(args[0])
147 150
148 def _errback(result): 151 def _errback(result):
149 d.errback(Failure(unicode(result))) 152 d.errback(Failure(jsonrpclib.Fault(ERRNUM_BRIDGE_ERRBACK, unicode(result))))
150 153
151 kwargs["callback"] = _callback 154 kwargs["callback"] = _callback
152 kwargs["errback"] = _errback 155 kwargs["errback"] = _errback
153 getattr(self.sat_host.bridge, method_name)(*args, **kwargs) 156 getattr(self.sat_host.bridge, method_name)(*args, **kwargs)
154 return d 157 return d
164 self.session = request.getSession() 167 self.session = request.getSession()
165 profile = ISATSession(self.session).profile 168 profile = ISATSession(self.session).profile
166 if not profile: 169 if not profile:
167 #user is not identified, we return a jsonrpc fault 170 #user is not identified, we return a jsonrpc fault
168 parsed = jsonrpclib.loads(request.content.read()) 171 parsed = jsonrpclib.loads(request.content.read())
169 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia 172 fault = jsonrpclib.Fault(ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia
170 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) 173 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc'))
171 return jsonrpc.JSONRPC.render(self, request) 174 return jsonrpc.JSONRPC.render(self, request)
172 175
173 def jsonrpc_getProfileJid(self): 176 def jsonrpc_getProfileJid(self):
174 """Return the jid of the profile""" 177 """Return the jid of the profile"""
545 if parsed.get("method")!="isRegistered": 548 if parsed.get("method")!="isRegistered":
546 #if we don't call login or isRegistered, we need to be identified 549 #if we don't call login or isRegistered, we need to be identified
547 profile = ISATSession(_session).profile 550 profile = ISATSession(_session).profile
548 if not profile: 551 if not profile:
549 #user is not identified, we return a jsonrpc fault 552 #user is not identified, we return a jsonrpc fault
550 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia 553 fault = jsonrpclib.Fault(ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia
551 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) 554 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc'))
552 self.request = request 555 self.request = request
553 return jsonrpc.JSONRPC.render(self, request) 556 return jsonrpc.JSONRPC.render(self, request)
554 557
555 def login(self, request): 558 def login(self, request):
711 714
712 def jsonrpc_connect(self): 715 def jsonrpc_connect(self):
713 _session = self.request.getSession() 716 _session = self.request.getSession()
714 profile = ISATSession(_session).profile 717 profile = ISATSession(_session).profile
715 if self.profiles_waiting.has_key(profile): 718 if self.profiles_waiting.has_key(profile):
716 raise jsonrpclib.Fault('1','Already waiting') #FIXME: define some standard error codes for libervia 719 raise jsonrpclib.Fault(1,'Already waiting') #FIXME: define some standard error codes for libervia
717 self.profiles_waiting[profile] = self.request 720 self.profiles_waiting[profile] = self.request
718 self.sat_host.bridge.connect(profile) 721 self.sat_host.bridge.connect(profile)
719 return server.NOT_DONE_YET 722 return server.NOT_DONE_YET
720 723
721 def jsonrpc_isRegistered(self): 724 def jsonrpc_isRegistered(self):
816 _session = request.getSession() 819 _session = request.getSession()
817 parsed = jsonrpclib.loads(request.content.read()) 820 parsed = jsonrpclib.loads(request.content.read())
818 profile = ISATSession(_session).profile 821 profile = ISATSession(_session).profile
819 if not profile: 822 if not profile:
820 #user is not identified, we return a jsonrpc fault 823 #user is not identified, we return a jsonrpc fault
821 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia 824 fault = jsonrpclib.Fault(ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia
822 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) 825 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc'))
823 self.request = request 826 self.request = request
824 return jsonrpc.JSONRPC.render(self, request) 827 return jsonrpc.JSONRPC.render(self, request)
825 828
826 class UploadManager(Resource): 829 class UploadManager(Resource):