def offline_reply(start_response, msg=None): """Send a ServerOffline reply""" faultCode = koji.ServerOffline.faultCode if msg is None: faultString = "server is offline" else: faultString = msg response = dumps(Fault(faultCode, faultString)) headers = [ ('Content-Length', str(len(response))), ('Content-Type', "text/xml"), ] start_response('200 OK', headers) return [response]
def _wrap_handler(self, handler, environ): """Catch exceptions and encode response of handler""" # generate response try: response = handler(environ) # wrap response in a singleton tuple response = (response, ) response = dumps(response, methodresponse=1, marshaller=Marshaller) except Fault as fault: self.traceback = True response = dumps(fault, marshaller=Marshaller) except Exception: self.traceback = True # report exception back to server faultCode, faultString = self._log_exception() response = dumps(Fault(faultCode, faultString), marshaller=Marshaller) return response
def _wrap_handler(self, handler, environ): """Catch exceptions and encode response of handler""" # generate response try: response = handler(environ) # wrap response in a singleton tuple response = (response, ) response = dumps(response, methodresponse=1, marshaller=Marshaller) except Fault as fault: self.traceback = True response = dumps(fault, marshaller=Marshaller) except: self.traceback = True # report exception back to server e_class, e = sys.exc_info()[:2] faultCode = getattr(e_class, 'faultCode', 1) tb_type = context.opts.get('KojiTraceback', None) tb_str = ''.join(traceback.format_exception(*sys.exc_info())) if issubclass(e_class, koji.GenericError): if context.opts.get('KojiDebug'): if tb_type == "extended": faultString = koji.format_exc_plus() else: faultString = tb_str else: faultString = str(e) else: if tb_type == "normal": faultString = tb_str elif tb_type == "extended": faultString = koji.format_exc_plus() else: faultString = "%s: %s" % (e_class, e) self.logger.warning(tb_str) response = dumps(Fault(faultCode, faultString), marshaller=Marshaller) return response
def _callMethod(self, name, args, kwargs=None, retry=True): if self.multicall: return super(FakeClientSession, self)._callMethod(name, args, kwargs, retry) key = self._munge([name, args, kwargs]) # we may have a series of calls for each key calls = self._calldata.get(key) ofs = self._offsets.get(key, 0) call = calls[ofs] ofs += 1 if ofs < len(calls): # don't go past the end self._offsets[key] = ofs if call: if 'fault' in call: fault = Fault(call['fault']['faultCode'], call['fault']['faultString']) raise koji.convertFault(fault) else: return call['result'] else: return mock.MagicMock()
if context.opts.get('KojiDebug'): if tb_type == "extended": faultString = koji.format_exc_plus() else: faultString = tb_str else: faultString = str(e) else: if tb_type == "normal": faultString = tb_str elif tb_type == "extended": faultString = koji.format_exc_plus() else: faultString = "%s: %s" % (e_class, e) self.logger.warning(tb_str) response = dumps(Fault(faultCode, faultString), marshaller=Marshaller) return response def handle_upload(self, environ): #uploads can't be in a multicall context.method = None self.check_session() self.enforce_lockout() return kojihub.handle_upload(environ) def handle_rpc(self, environ): params, method = self._read_request(environ['wsgi.input']) return self._dispatch(method, params)