def respond(result): if isinstance(result, Exception): # Package exception into XML-RPC Fault instance. message = getattr(result, "message", "") if not message: message = str(result) typename = type(result).__name__ if typename == "instance": typename = result.__class__.__name__ faultstring = "%s: %s" % (typename, message) if isinstance(faultstring, unicode): try: faultstring = str(faultstring) except UnicodeEncodeError: faultstring = faultstring.encode('utf') result = xmlrpclib.Fault(1, faultstring) else: # Dumps requires tuple or Fault type. result = (result,) xmlresult = xmlrpclib.dumps(result, methodresponse=True) response = Response(request) response.set_header('Content-Length', len(xmlresult)) response.set_header('Content-Type', 'text/xml') response.send(xmlresult) self.debugout("Response sent to client.")
def handle_request(self, request): print 'handle_request' if not self.running: return request.error(503) #service unavailable try: self.data = data = request.get_data().read_all() if not data: raise EProtocol('could not get DATA parameter from posted data') ## process xmlrpc, getting the name of the method ## and parameters params, method = xmlrpclib.loads(data) return object_alias = '' method_name = '' ## get the name of the object ## and the name of method ## They are delimited by a colon. except: msglog.exception() raise MpxException('Error occurred while processing Brivo XMLRPC command') # XML-RPC Call was successful. # Send back the XML result to client reply = Response(request) reply.set_header('Content-Length', len(response)) reply.set_header('Content-Type', 'text/xml') reply.send(response) return
def respond(result): if isinstance(result, Exception): # Package exception into XML-RPC Fault instance. message = getattr(result, "message", "") if not message: message = str(result) typename = type(result).__name__ if typename == "instance": typename = result.__class__.__name__ faultstring = "%s: %s" % (typename, message) if isinstance(faultstring, unicode): try: faultstring = str(faultstring) except UnicodeEncodeError: faultstring = faultstring.encode('utf') result = xmlrpclib.Fault(1, faultstring) else: # Dumps requires tuple or Fault type. result = (result, ) xmlresult = xmlrpclib.dumps(result, methodresponse=True) response = Response(request) response.set_header('Content-Length', len(xmlresult)) response.set_header('Content-Type', 'text/xml') response.send(xmlresult) self.debugout("Response sent to client.")
def handle_request(self, request): print 'handle_request' if not self.running: return request.error(503) #service unavailable try: self.data = data = request.get_data().read_all() if not data: raise EProtocol( 'could not get DATA parameter from posted data') ## process xmlrpc, getting the name of the method ## and parameters params, method = xmlrpclib.loads(data) return object_alias = '' method_name = '' ## get the name of the object ## and the name of method ## They are delimited by a colon. except: msglog.exception() raise MpxException( 'Error occurred while processing Brivo XMLRPC command') # XML-RPC Call was successful. # Send back the XML result to client reply = Response(request) reply.set_header('Content-Length', len(response)) reply.set_header('Content-Type', 'text/xml') reply.send(response) return
def download_backup(self, request, file): response = Response(request) response.set_header('Content-Type', 'application/octet-stream') response.set_header('Content-Disposition', 'attachment; filename="%s.tgz"' % file.f_name) response.push(FileProducer(file)) response.done() return
def download_backup(self, request, file): response = Response(request) response.set_header('Content-Type','application/octet-stream') response.set_header('Content-Disposition', 'attachment; filename="%s.tgz"' % file.f_name) response.push(FileProducer(file)) response.done() return
def download_data(self, request, log, data, formatter): response = Response(request) response.set_header('Content-Type','application/octet-stream') response.set_header( 'Content-Disposition', 'attachment; filename="%s.csv"' % log.name) output = formatter.format(data) if not output: return request.reply(204) if type(output) != type(''): output = StreamingProducer(output) response.push(output) response.done() request._DynamicLogHandler__success = True return
def handle_request(self, request): response = Response(request) response.set_header('Content-Type', 'text/xml') try: path = request.get_path().split('/') node_path = '/%s' % string.join(path[3:], '/') # # # # just for testing right now # # # if node_path == '' and len(path) < 4: results = self.invoke(request) xml = xmlrpclib.dumps((results, ), methodresponse=1) response.set_header('Content-Length', len(xml)) response.set_header('Content-Type', 'text/xml') response.send(xml) else: node = self._as_node(node_path) data = self._get_data(request) # process xmlrpc, getting the name of the method # and parameters params, method = xmlrpclib.loads(data) method_name = '' # get the name of the object # and the name of method m = getattr(node, method) if params == '': params = None result = (apply(m, params), ) if hasattr(result[0], 'has_key'): for k in result[0].keys(): if hasattr(result[0][k], 'has_key') \ and result[0][k].has_key('value') \ and isinstance(result[0][k]['value'],Exception): result[0][k][ 'value'] = 'error: %s' % result[0][k]['value'] xml = xmlrpclib.dumps(result, methodresponse=1) # XML-RPC Call was successful. # Send back the XML result to client response = Response(request) response.set_header('Content-Length', len(xml)) response.set_header('Content-Type', 'text/xml') response.send(xml) except Exception, err: if self.log_n_exceptions: msglog.exception() if self.log_n_exceptions > 0: self.log_n_exceptions -= 1 try: faultString = """<exception> <module>%s</module> <class>%s.%s</class> <str>%r</str> </exception>""" % (err.__class__.__module__, err.__class__.__module__, err.__class__.__name__, str(err)) except: msglog.exception() faultString = "%s" % err fault_xml = xmlrpclib.dumps(xmlrpclib.Fault(1, faultString)) response.set_header('Content-Length', len(fault_xml)) response.send(fault_xml)
if exceptions: messages = ["Some actions failed:"] for errdata in exceptions: messages.append(" " + str(errdata)) request['Content-Type'] = 'text/plain' request.error(405, "\n".join(messages)) return data = "" response = Response(request) style = request_data.get('type', self.default) if isinstance(style, (list, tuple)): style = style[0] if style != "none": interface = self.interfaces.get(style) if interface is None: request['Content-Type'] = 'text/plain' request.error(405, 'Invalid or unsupported feed type.') return try: syndicator = interface(self._subject) except ComponentLookupError, error: request['Content-Type'] = 'text/plain' request.error(404, 'No adapter for requested node.') return clientid = request_data.get('clientid') if clientid is not None: clientid = clientid[0] data = syndicator.render(request.get_path(), clientid) response.set_header('Content-Type', 'text/xml') response.send(data)
if exceptions: messages = ["Some actions failed:"] for errdata in exceptions: messages.append(" " + str(errdata)) request["Content-Type"] = "text/plain" request.error(405, "\n".join(messages)) return data = "" response = Response(request) style = request_data.get("type", self.default) if isinstance(style, (list, tuple)): style = style[0] if style != "none": interface = self.interfaces.get(style) if interface is None: request["Content-Type"] = "text/plain" request.error(405, "Invalid or unsupported feed type.") return try: syndicator = interface(self._subject) except ComponentLookupError, error: request["Content-Type"] = "text/plain" request.error(404, "No adapter for requested node.") return clientid = request_data.get("clientid") if clientid is not None: clientid = clientid[0] data = syndicator.render(request.get_path(), clientid) response.set_header("Content-Type", "text/xml") response.send(data)
def handle_request(self, request): response = Response(request) response.set_header('Content-Type', 'text/xml') try: path = request.get_path().split('/') node_path = '/%s' % string.join(path[3:],'/') # # # # just for testing right now # # # if node_path == '' and len(path) < 4: results = self.invoke(request) xml = xmlrpclib.dumps((results,),methodresponse=1) response.set_header('Content-Length', len(xml)) response.set_header('Content-Type', 'text/xml') response.send(xml) else: node = self._as_node(node_path) data = self._get_data(request) # process xmlrpc, getting the name of the method # and parameters params, method = xmlrpclib.loads(data) method_name = '' # get the name of the object # and the name of method m = getattr(node, method) if params == '': params = None result = (apply(m,params),) if hasattr(result[0],'has_key'): for k in result[0].keys(): if hasattr(result[0][k], 'has_key') \ and result[0][k].has_key('value') \ and isinstance(result[0][k]['value'],Exception): result[0][k]['value'] = 'error: %s' % result[0][k]['value'] xml = xmlrpclib.dumps(result,methodresponse=1) # XML-RPC Call was successful. # Send back the XML result to client response = Response(request) response.set_header('Content-Length', len(xml)) response.set_header('Content-Type', 'text/xml') response.send(xml) except Exception,err: if self.log_n_exceptions: msglog.exception() if self.log_n_exceptions > 0: self.log_n_exceptions -= 1 try: faultString = """<exception> <module>%s</module> <class>%s.%s</class> <str>%r</str> </exception>""" % (err.__class__.__module__, err.__class__.__module__, err.__class__.__name__, str(err)) except: msglog.exception() faultString = "%s" % err fault_xml = xmlrpclib.dumps( xmlrpclib.Fault(1, faultString) ) response.set_header('Content-Length', len(fault_xml)) response.send(fault_xml)