def format(self, data, datatype, expires): response_data = '' func = self.supporttypes[datatype] if datatype not in self.supporttypes: response.status = 406 expires = 0 response_data = self.supporttypes['text/plain']({'exception': 406, 'type': 'HTTPError', 'message': '%s is not supported. Valid accept headers are: %s' %\ (datatype, list(self.supporttypes))}) try: response_data = self.supporttypes[datatype](data) except HTTPError as h: # This won't be triggered with a default formatter, but could be by a subclass response.status = h.args[0] expires = 0 rec = { 'exception': h.args[0], 'type': 'HTTPError', 'message': h.args[1] } response_data = func(rec) except Exception as e: response.status = 500 expires = 0 rec = { 'exception': 500, 'type': e.__class__.__name__, 'message': 'Server Error' } response_data = func(rec) _setCherryPyHeaders(response_data, datatype, expires) return response_data
def format(self, data, datatype, expires): response_data = '' func = self.supporttypes[datatype] if datatype not in self.supporttypes.keys(): response.status = 406 expires=0 response_data = self.supporttypes['text/plain']({'exception': 406, 'type': 'HTTPError', 'message': '%s is not supported. Valid accept headers are: %s' %\ (datatype, self.supporttypes.keys())}) try: response_data = self.supporttypes[datatype](data) except HTTPError as h: # This won't be triggered with a default formatter, but could be by a subclass response.status = h[0] expires=0 rec = {'exception': h[0],'type': 'HTTPError','message': h[1]} response_data = func(rec) except Exception as e: response.status = 500 expires=0 rec = {'exception': 500, 'type': e.__class__.__name__, 'message': 'Server Error'} response_data = func(rec) _setCherryPyHeaders(response_data, datatype, expires) return response_data
response_data = self.supporttypes['text/plain']({'exception': 406, 'type': 'HTTPError', 'message': '%s is not supported. Valid accept headers are: %s' %\ (datatype, self.supporttypes.keys())}) try: response_data = self.supporttypes[datatype](data) except HTTPError, h: # This won't be triggered with a default formatter, but could be by a subclass response.status = h[0] expires = 0 response_data = self.supporttypes[datatype]({ 'exception': h[0], 'type': 'HTTPError', 'message': h[1] }, expires=0) except Exception, e: response.status = 500 expires = 0 response_data = self.supporttypes[datatype]({ 'exception': 500, 'type': e.__class__.__name__, 'message': 'Server Error' }) _setCherryPyHeaders(response_data, datatype, expires) return response_data
def to_string(self, data): return str(data) def format(self, data, datatype, expires): response_data = '' if datatype not in self.supporttypes.keys(): response.status = 406 expires=0 response_data = self.supporttypes['text/plain']({'exception': 406, 'type': 'HTTPError', 'message': '%s is not supported. Valid accept headers are: %s' %\ (datatype, self.supporttypes.keys())}) try: response_data = self.supporttypes[datatype](data) except HTTPError, h: # This won't be triggered with a default formatter, but could be by a subclass response.status = h[0] expires=0 response_data = self.supporttypes[datatype]({'exception': h[0], 'type': 'HTTPError', 'message': h[1]}, expires=0) except Exception, e: response.status = 500 expires=0 response_data = self.supporttypes[datatype]({'exception': 500, 'type': e.__class__.__name__, 'message': 'Server Error'}) _setCherryPyHeaders(response_data, datatype, expires) return response_data