def __call__(self, http_request): """ Processes and dispatches the request. @param http_request: The C{HTTPRequest} object. @type http_request: C{HTTPRequest} @return: The response to the request. @rtype: C{HTTPResponse} """ if http_request.method != 'POST': return http.HttpResponseNotAllowed(['POST']) context = pyamf.get_context(pyamf.AMF0) stream = None http_response = http.HttpResponse() # Decode the request try: request = remoting.decode(http_request.raw_post_data, context) except pyamf.DecodeError: self.logger.debug(gateway.format_exception()) http_response.status_code = 400 return http_response self.logger.debug("AMF Request: %r" % request) # Process the request try: response = self.getResponse(http_request, request) except (KeyboardInterrupt, SystemExit): raise except: self.logger.debug(gateway.format_exception()) return http.HttpResponseServerError() self.logger.debug("AMF Response: %r" % response) # Encode the response try: stream = remoting.encode(response, context) except pyamf.EncodeError: self.logger.debug(gateway.format_exception()) return http.HttpResponseServerError( 'Unable to encode the response') buf = stream.getvalue() http_response['Content-Type'] = remoting.CONTENT_TYPE http_response['Content-Length'] = str(len(buf)) http_response.write(buf) return http_response
def __call__(self, http_request): """ Processes and dispatches the request. @param http_request: The C{HTTPRequest} object. @type http_request: C{HTTPRequest} @return: The response to the request. @rtype: C{HTTPResponse} """ if http_request.method != 'POST': return http.HttpResponseNotAllowed(['POST']) context = pyamf.get_context(pyamf.AMF0) stream = None http_response = http.HttpResponse() # Decode the request try: request = remoting.decode(http_request.raw_post_data, context) except pyamf.DecodeError: self.logger.exception(gateway.format_exception()) http_response.status_code = 400 return http_response self.logger.debug("AMF Request: %r" % request) # Process the request try: response = self.getResponse(http_request, request) except (KeyboardInterrupt, SystemExit): raise except: self.logger.exception(gateway.format_exception()) return http.HttpResponseServerError() self.logger.debug("AMF Response: %r" % response) # Encode the response try: stream = remoting.encode(response, context) except pyamf.EncodeError: self.logger.exception(gateway.format_exception()) return http.HttpResponseServerError('Unable to encode the response') buf = stream.getvalue() http_response['Content-Type'] = remoting.CONTENT_TYPE http_response['Content-Length'] = str(len(buf)) http_response['Server'] = gateway.SERVER_NAME http_response.write(buf) return http_response
def post(self): body = self.request.body_file.read() stream = None timezone_offset = self._get_timezone_offset() # Decode the request try: request = remoting.decode(body, strict=self.strict, logger=self.logger, timezone_offset=timezone_offset) except (DecodeError, IOError): if self.logger: self.logger.exception('Error decoding AMF request') response = ("400 Bad Request\n\nThe request body was unable to " "be successfully decoded.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() self.error(400) self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Server'] = gateway.SERVER_NAME self.response.out.write(response) return except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Unexpected error decoding AMF request') response = ('500 Internal Server Error\n\n' 'An unexpected error occurred.') if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() self.error(500) self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Server'] = gateway.SERVER_NAME self.response.out.write(response) return if self.logger: self.logger.debug("AMF Request: %r" % request) # Process the request try: response = self.getResponse(request) except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Error processing AMF request') response = ("500 Internal Server Error\n\nThe request was " \ "unable to be successfully processed.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() self.error(500) self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Server'] = gateway.SERVER_NAME self.response.out.write(response) return if self.logger: self.logger.debug("AMF Response: %r" % response) # Encode the response try: stream = remoting.encode(response, strict=self.strict, logger=self.logger, timezone_offset=timezone_offset) except: if self.logger: self.logger.exception('Error encoding AMF request') response = ("500 Internal Server Error\n\nThe request was " \ "unable to be encoded.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() self.error(500) self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Server'] = gateway.SERVER_NAME self.response.out.write(response) return response = stream.getvalue() self.response.headers['Content-Type'] = remoting.CONTENT_TYPE self.response.headers['Content-Length'] = str(len(response)) self.response.headers['Server'] = gateway.SERVER_NAME self.response.out.write(response)
def post(self): body = self.request.body_file.read() stream = None context = pyamf.get_context(pyamf.AMF0) # Decode the request try: request = remoting.decode(body, context, strict=self.strict) except: fe = gateway.format_exception() self.logger.exception(fe) response = "400 Bad Request\n\nThe request body was unable to " \ "be successfully decoded." if self.debug: response += "\n\nTraceback:\n\n%s" % fe self.error(400) self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Server'] = gateway.SERVER_NAME self.response.out.write(response) return self.logger.debug("AMF Request: %r" % request) # Process the request try: response = self.getResponse(request) except (KeyboardInterrupt, SystemExit): raise except: fe = gateway.format_exception() self.logger.exception(fe) response = "500 Internal Server Error\n\nThe request was " \ "unable to be successfully processed." if self.debug: response += "\n\nTraceback:\n\n%s" % fe self.error(500) self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Server'] = gateway.SERVER_NAME self.response.out.write(response) return self.logger.debug("AMF Response: %r" % response) # Encode the response try: stream = remoting.encode(response, context, strict=self.strict) except: fe = gateway.format_exception() self.logger.exception(fe) response = "500 Internal Server Error\n\nThe request was " \ "unable to be encoded." if self.debug: response += "\n\nTraceback:\n\n%s" % fe self.error(500) self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Server'] = gateway.SERVER_NAME self.response.out.write(response) return response = stream.getvalue() self.response.headers['Content-Type'] = remoting.CONTENT_TYPE self.response.headers['Content-Length'] = str(len(response)) self.response.headers['Server'] = gateway.SERVER_NAME self.response.out.write(response)
def __call__(self, http_request): """ Processes and dispatches the request. """ if http_request.method != 'POST': return http.HttpResponseNotAllowed(['POST']) stream = None timezone_offset = self._get_timezone_offset() try: body = http_request.body except AttributeError: body = http_request.raw_post_data # Decode the request try: request = remoting.decode(body, strict=self.strict, logger=self.logger, timezone_offset=timezone_offset) except (pyamf.DecodeError, IOError): if self.logger: self.logger.exception('Error decoding AMF request') response = ("400 Bad Request\n\nThe request body was unable to " "be successfully decoded.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() # support for Django 0.96 http_response = http.HttpResponse(content_type='text/plain', content=response) http_response.status_code = 400 return http_response except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Unexpected error decoding AMF request') response = ('500 Internal Server Error\n\n' 'An unexpected error occurred.') if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return http.HttpResponseServerError(content_type='text/plain', content=response) # Process the request try: response = self.getResponse(http_request, request) except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Error processing AMF request') response = ("500 Internal Server Error\n\nThe request was " "unable to be successfully processed.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return http.HttpResponseServerError(content_type='text/plain', content=response) # Encode the response try: stream = remoting.encode(response, strict=self.strict, logger=self.logger, timezone_offset=timezone_offset) except: if self.logger: self.logger.exception('Error encoding AMF request') response = ("500 Internal Server Error\n\nThe request was " "unable to be encoded.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return http.HttpResponseServerError(content_type='text/plain', content=response) buf = stream.getvalue() http_response = http.HttpResponse(content_type=remoting.CONTENT_TYPE) http_response['Server'] = gateway.SERVER_NAME http_response['Content-Length'] = str(len(buf)) http_response.write(buf) return http_response
def __call__(self, http_request): """ Processes and dispatches the request. """ if http_request.method != 'POST': return http.HttpResponseNotAllowed(['POST']) stream = None timezone_offset = self._get_timezone_offset() # Decode the request try: request = remoting.decode(http_request.raw_post_data, strict=self.strict, logger=self.logger, timezone_offset=timezone_offset) except (pyamf.DecodeError, IOError): if self.logger: self.logger.exception('Error decoding AMF request') response = ("400 Bad Request\n\nThe request body was unable to " "be successfully decoded.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() # support for Django 0.96 http_response = http.HttpResponse(mimetype='text/plain', content=response) http_response.status_code = 400 return http_response except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Unexpected error decoding AMF request') response = ('500 Internal Server Error\n\n' 'An unexpected error occurred.') if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return http.HttpResponseServerError(mimetype='text/plain', content=response) if self.logger: self.logger.debug("AMF Request: %r" % request) # Process the request try: response = self.getResponse(http_request, request) except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Error processing AMF request') response = ("500 Internal Server Error\n\nThe request was " "unable to be successfully processed.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return http.HttpResponseServerError(mimetype='text/plain', content=response) if self.logger: self.logger.debug("AMF Response: %r" % response) # Encode the response try: stream = remoting.encode(response, strict=self.strict, logger=self.logger, timezone_offset=timezone_offset) except: if self.logger: self.logger.exception('Error encoding AMF request') response = ("500 Internal Server Error\n\nThe request was " "unable to be encoded.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return http.HttpResponseServerError( mimetype='text/plain', content=response) buf = stream.getvalue() http_response = http.HttpResponse(mimetype=remoting.CONTENT_TYPE) http_response['Server'] = gateway.SERVER_NAME http_response['Content-Length'] = str(len(buf)) http_response.write(buf) return http_response
def __call__(self, environ, start_response): """ @rtype: C{StringIO} @return: File-like object. """ if environ["REQUEST_METHOD"] != "POST": return self.badRequestMethod(environ, start_response) body = environ["wsgi.input"].read(int(environ["CONTENT_LENGTH"])) stream = None context = pyamf.get_context(pyamf.AMF0) # Decode the request try: request = remoting.decode(body, context, strict=self.strict) except (pyamf.DecodeError, EOFError): self.logger.exception(gateway.format_exception()) response = "400 Bad Request\n\nThe request body was unable to " "be successfully decoded." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response( "400 Bad Request", [ ("Content-Type", "text/plain"), ("Content-Length", str(len(response))), ("Server", gateway.SERVER_NAME), ], ) return [response] except (KeyboardInterrupt, SystemExit): raise except: self.logger.exception(gateway.format_exception()) response = "500 Internal Server Error\n\nAn unexpected error occurred whilst decoding." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response( "500 Internal Server Error", [ ("Content-Type", "text/plain"), ("Content-Length", str(len(response))), ("Server", gateway.SERVER_NAME), ], ) return [response] self.logger.debug("AMF Request: %r" % request) # Process the request try: response = self.getResponse(request, environ) except (KeyboardInterrupt, SystemExit): raise except: self.logger.exception(gateway.format_exception()) response = "500 Internal Server Error\n\nThe request was " "unable to be successfully processed." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response( "500 Internal Server Error", [ ("Content-Type", "text/plain"), ("Content-Length", str(len(response))), ("Server", gateway.SERVER_NAME), ], ) return [response] self.logger.debug("AMF Response: %r" % response) # Encode the response try: stream = remoting.encode(response, context, strict=self.strict) except: self.logger.exception(gateway.format_exception()) response = "500 Internal Server Error\n\nThe request was " "unable to be encoded." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response( "500 Internal Server Error", [ ("Content-Type", "text/plain"), ("Content-Length", str(len(response))), ("Server", gateway.SERVER_NAME), ], ) return [response] response = stream.getvalue() start_response( "200 OK", [ ("Content-Type", remoting.CONTENT_TYPE), ("Content-Length", str(len(response))), ("Server", gateway.SERVER_NAME), ], ) return [response]
def __call__(self, http_request): """ Processes and dispatches the request. @param http_request: The C{HTTPRequest} object. @type http_request: C{HTTPRequest} @return: The response to the request. @rtype: C{HTTPResponse} """ if http_request.method != 'POST': return http.HttpResponseNotAllowed(['POST']) context = pyamf.get_context(pyamf.AMF0) stream = None # Decode the request try: request = remoting.decode(http_request.raw_post_data, context, strict=self.strict) except (pyamf.DecodeError, EOFError): fe = gateway.format_exception() self.logger.exception(fe) response = "400 Bad Request\n\nThe request body was unable to " \ "be successfully decoded." if self.debug: response += "\n\nTraceback:\n\n%s" % fe return http.HttpResponseBadRequest(mimetype='text/plain', content=response) except (KeyboardInterrupt, SystemExit): raise except: fe = gateway.format_exception() self.logger.exception(fe) response = "500 Internal Server Error\n\nAn unexpected error occurred." if self.debug: response += "\n\nTraceback:\n\n%s" % fe return http.HttpResponseServerError(mimetype='text/plain', content=response) self.logger.debug("AMF Request: %r" % request) # Process the request try: response = self.getResponse(http_request, request) except (KeyboardInterrupt, SystemExit): raise except: fe = gateway.format_exception() self.logger.exception(fe) response = "500 Internal Server Error\n\nThe request was " \ "unable to be successfully processed." if self.debug: response += "\n\nTraceback:\n\n%s" % fe return http.HttpResponseServerError(mimetype='text/plain', content=response) self.logger.debug("AMF Response: %r" % response) # Encode the response try: stream = remoting.encode(response, context, strict=self.strict) except: fe = gateway.format_exception() self.logger.exception(fe) response = "500 Internal Server Error\n\nThe request was " \ "unable to be encoded." if self.debug: response += "\n\nTraceback:\n\n%s" % fe return http.HttpResponseServerError(mimetype='text/plain', content=response) buf = stream.getvalue() http_response = http.HttpResponse(mimetype=remoting.CONTENT_TYPE) http_response['Server'] = gateway.SERVER_NAME http_response['Content-Length'] = str(len(buf)) http_response.write(buf) return http_response
def __call__(self, environ, start_response): """ @rtype: C{StringIO} @return: File-like object. """ if environ['REQUEST_METHOD'] != 'POST': return self.badRequestMethod(environ, start_response) body = environ['wsgi.input'].read(int(environ['CONTENT_LENGTH'])) stream = None context = pyamf.get_context(pyamf.AMF0) # Decode the request try: request = remoting.decode(body, context) except pyamf.DecodeError: self.logger.debug(gateway.format_exception()) response = "400 Bad Request\n\nThe request body was unable to " \ "be successfully decoded." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response('400 Bad Request', [ ('Content-Type', 'text/plain'), ('Content-Length', str(len(response))), ]) return [response] # Process the request try: response = self.getResponse(request, environ) except (KeyboardInterrupt, SystemExit): raise except: self.logger.debug(gateway.format_exception()) response = "500 Internal Server Error\n\nThe request was " \ "unable to be successfully processed." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response('500 Internal Server Error', [ ('Content-Type', 'text/plain'), ('Content-Length', str(len(response))), ]) return [response] # Encode the response try: stream = remoting.encode(response, context) except pyamf.EncodeError: self.logger.debug(gateway.format_exception()) response = "500 Internal Server Error\n\nThe request was " \ "unable to be encoded." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response('500 Internal Server Error', [ ('Content-Type', 'text/plain'), ('Content-Length', str(len(response))), ]) return [response] response = stream.getvalue() start_response('200 OK', [ ('Content-Type', remoting.CONTENT_TYPE), ('Content-Length', str(len(response))), ]) return [response]
def __call__(self, environ, start_response): """ @type environ: @param environ: @type start_response: @param start_response: @rtype: C{StringIO} @return: File-like object. """ if environ['REQUEST_METHOD'] != 'POST': return self.badRequestMethod(environ, start_response) body = environ['wsgi.input'].read(int(environ['CONTENT_LENGTH'])) stream = None context = pyamf.get_context(pyamf.AMF0) # Decode the request try: request = remoting.decode(body, context) except pyamf.DecodeError: self.logger.debug(gateway.format_exception()) response = "400 Bad Request\n\nThe request body was unable to " \ "be successfully decoded." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response('400 Bad Request', [ ('Content-Type', 'text/plain'), ('Content-Length', str(len(response))), ]) return [response] # Process the request try: response = self.getResponse(request, environ) except (KeyboardInterrupt, SystemExit): raise except: self.logger.debug(gateway.format_exception()) response = "500 Internal Server Error\n\nThe request was " \ "unable to be successfully processed." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response('500 Internal Server Error', [ ('Content-Type', 'text/plain'), ('Content-Length', str(len(response))), ]) return [response] # Encode the response try: stream = remoting.encode(response, context) except pyamf.EncodeError: self.logger.debug(gateway.format_exception()) response = "500 Internal Server Error\n\nThe request was " \ "unable to be encoded." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response('500 Internal Server Error', [ ('Content-Type', 'text/plain'), ('Content-Length', str(len(response))), ]) return [response] response = stream.getvalue() start_response('200 OK', [ ('Content-Type', remoting.CONTENT_TYPE), ('Content-Length', str(len(response))), ]) return [response]
def __call__(self, http_request): """ Processes and dispatches the request. @param http_request: The C{HTTPRequest} object. @type http_request: C{HTTPRequest} @return: The response to the request. @rtype: C{HTTPResponse} """ if http_request.method != 'POST': return http.HttpResponseNotAllowed(['POST']) stream = None timezone_offset = self._get_timezone_offset() # Decode the request try: request = remoting.decode(http_request.raw_post_data, strict=self.strict, logger=self.logger, timezone_offset=timezone_offset) except (pyamf.DecodeError, IOError): fe = gateway.format_exception() if self.logger: self.logger.exception(fe) response = "400 Bad Request\n\nThe request body was unable to " \ "be successfully decoded." if self.debug: response += "\n\nTraceback:\n\n%s" % fe return http.HttpResponseBadRequest(mimetype='text/plain', content=response) except (KeyboardInterrupt, SystemExit): raise except: fe = gateway.format_exception() if self.logger: self.logger.exception(fe) response = ('500 Internal Server Error\n\n' 'An unexpected error occurred.') if self.debug: response += "\n\nTraceback:\n\n%s" % fe return http.HttpResponseServerError(mimetype='text/plain', content=response) if self.logger: self.logger.info("AMF Request: %r" % request) # Process the request try: response = self.getResponse(http_request, request) except (KeyboardInterrupt, SystemExit): raise except: fe = gateway.format_exception() if self.logger: self.logger.exception(fe) response = "500 Internal Server Error\n\nThe request was " \ "unable to be successfully processed." if self.debug: response += "\n\nTraceback:\n\n%s" % fe return http.HttpResponseServerError(mimetype='text/plain', content=response) if self.logger: self.logger.info("AMF Response: %r" % response) # Encode the response try: stream = remoting.encode(response, strict=self.strict, logger=self.logger, timezone_offset=timezone_offset) except: fe = gateway.format_exception() if self.logger: self.logger.exception(fe) response = ("500 Internal Server Error\n\nThe request was " "unable to be encoded.") if self.debug: response += "\n\nTraceback:\n\n%s" % fe return http.HttpResponseServerError(mimetype='text/plain', content=response) buf = stream.getvalue() http_response = http.HttpResponse(mimetype=remoting.CONTENT_TYPE) http_response['Server'] = gateway.SERVER_NAME http_response['Content-Length'] = str(len(buf)) http_response.write(buf) return http_response
def __call__(self, request): """Processes and dispatches the request""" if request.method != 'POST': return HTTPMethodNotAllowed(['POST']) body = request.body stream = None timezone_offset = self._get_timezone_offset() # Decode the request try: amf_request = remoting.decode(body, strict=self.strict, logger=self.logger, timezone_offset=timezone_offset) except (pyamf.DecodeError, IOError): if self.logger: self.logger.exception('Error decoding AMF request') response = "400 Bad Request\n\nThe request body was unable to " \ "be successfully decoded." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return HTTPBadRequest(detail=response) except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Unexpected error decoding AMF request') response = ("500 Internal Server Error\n\nAn unexpected error " "occurred whilst decoding.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return HTTPInternalServerError(detail=response) if self.logger: self.logger.debug("AMF Request: %r" % amf_request) # Process the request try: response = self.getResponse(request, amf_request) except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Error processing AMF request') response = ("500 Internal Server Error\n\nThe request was " "unable to be successfully processed.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return HTTPInternalServerError(detail=response) if self.logger: self.logger.debug("AMF Response: %r" % response) # Encode the response try: stream = remoting.encode(response, strict=self.strict, timezone_offset=timezone_offset) except: if self.logger: self.logger.exception('Error encoding AMF request') response = ("500 Internal Server Error\n\nThe request was " "unable to be encoded.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return HTTPInternalServerError(detail=response) buf = stream.getvalue() http_response = Response(content_type=remoting.CONTENT_TYPE) http_response.headers['Server'] = gateway.SERVER_NAME http_response.write(buf) return http_response
def __call__(self, environ, start_response): """ @rtype: C{StringIO} @return: File-like object. """ if environ['REQUEST_METHOD'] != 'POST': return self.badRequestMethod(environ, start_response) body = environ['wsgi.input'].read(int(environ['CONTENT_LENGTH'])) stream = None timezone_offset = self._get_timezone_offset() # Decode the request try: request = remoting.decode(body, strict=self.strict, logger=self.logger, timezone_offset=timezone_offset) except (pyamf.DecodeError, IOError): if self.logger: self.logger.exception('Error decoding AMF request') response = "400 Bad Request\n\nThe request body was unable to " \ "be successfully decoded." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response('400 Bad Request', [ ('Content-Type', 'text/plain'), ('Content-Length', str(len(response))), ('Server', gateway.SERVER_NAME), ]) return [response] except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Unexpected error decoding AMF request') response = ("500 Internal Server Error\n\nAn unexpected error " "occurred whilst decoding.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response('500 Internal Server Error', [ ('Content-Type', 'text/plain'), ('Content-Length', str(len(response))), ('Server', gateway.SERVER_NAME), ]) return [response] if self.logger: self.logger.debug("AMF Request: %r" % request) # Process the request try: response = self.getResponse(request, environ) except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Error processing AMF request') response = ("500 Internal Server Error\n\nThe request was " "unable to be successfully processed.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response('500 Internal Server Error', [ ('Content-Type', 'text/plain'), ('Content-Length', str(len(response))), ('Server', gateway.SERVER_NAME), ]) return [response] if self.logger: self.logger.debug("AMF Response: %r" % response) # Encode the response try: stream = remoting.encode(response, strict=self.strict, timezone_offset=timezone_offset) except: if self.logger: self.logger.exception('Error encoding AMF request') response = ("500 Internal Server Error\n\nThe request was " "unable to be encoded.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() start_response('500 Internal Server Error', [ ('Content-Type', 'text/plain'), ('Content-Length', str(len(response))), ('Server', gateway.SERVER_NAME), ]) return [response] response = stream.getvalue() start_response('200 OK', [ ('Content-Type', remoting.CONTENT_TYPE), ('Content-Length', str(len(response))), ('Server', gateway.SERVER_NAME), ]) return [response]
def __call__(self, request): """Processes and dispatches the request""" if request.method != 'POST': return httpexceptions.HTTPMethodNotAllowed(['POST']) body = request.body stream = None timezone_offset = self._get_timezone_offset() # Decode the request try: amf_request = remoting.decode(body, strict=self.strict, logger=self.logger, timezone_offset=timezone_offset) except (pyamf.DecodeError, IOError): if self.logger: self.logger.exception('Error decoding AMF request') response = "400 Bad Request\n\nThe request body was unable to " \ "be successfully decoded." if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return httpexceptions.HTTPBadRequest(detail=response) except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Unexpected error decoding AMF request') response = ("500 Internal Server Error\n\nAn unexpected error " "occurred whilst decoding.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return httpexceptions.HTTPInternalServerError(detail=response) if self.logger: self.logger.debug("AMF Request: %r" % amf_request) # Process the request try: response = self.getResponse(request, amf_request) except (KeyboardInterrupt, SystemExit): raise except: if self.logger: self.logger.exception('Error processing AMF request') response = ("500 Internal Server Error\n\nThe request was " "unable to be successfully processed.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return httpexceptions.HTTPInternalServerError(detail=response) if self.logger: self.logger.debug("AMF Response: %r" % response) # Encode the response try: stream = remoting.encode(response, strict=self.strict, timezone_offset=timezone_offset) except: if self.logger: self.logger.exception('Error encoding AMF request') response = ("500 Internal Server Error\n\nThe request was " "unable to be encoded.") if self.debug: response += "\n\nTraceback:\n\n%s" % gateway.format_exception() return httpexceptions.HTTPInternalServerError(detail=response) buf = stream.getvalue() http_response = Response(content_type=remoting.CONTENT_TYPE) http_response.headers['Server'] = gateway.SERVER_NAME http_response.write(buf) return http_response