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 , environ , start_response ) : 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 ( ) 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 ) 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 ) 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 ]
@rtype: C{StringIO}
        @return: File-like object.