(self, environ, start_response)
return output
Parse the request body as JSON, look up the method on the
        controller and if it exists, dispatch to it.
Parse the request body as JSON, look up the method on the
        controller and if it exists, dispatch to it.
Parse the request body as JSON look up the method on the controller and if it exists dispatch to it .
def __call__(self, environ, start_response):
        """Parse the request body as JSON, look up the method on the
        controller and if it exists, dispatch to it.
        """
        length = 0
        if 'CONTENT_LENGTH' not in environ:
            log.debug("No Content-Length")
            abort(411)
        else:
            if environ['CONTENT_LENGTH'] == '':
                abort(411)
            length = int(environ['CONTENT_LENGTH'])
            log.debug('Content-Length: %s', length)
        if length == 0:
            log.debug("Content-Length is 0")
            abort(411)

        raw_body = environ['wsgi.input'].read(length)
        json_body = json.loads(urllib.unquote_plus(raw_body))

        self._req_id = json_body['id']
        self._req_method = json_body['method']
        self._req_params = json_body['params']
        log.debug('id: %s, method: %s, params: %s',
                  self._req_id,
                  self._req_method,
                  self._req_params)

        self._error = None
        try:
            self._func = self._find_method()
        except AttributeError:
            err = jsonrpc_error(self._req_id, 'method_not_found')
            return err(environ, start_response)

        # now that we have a method, make sure we have enough
        # parameters and pass off control to the controller.
        if not isinstance(self._req_params, dict):
            # JSON-RPC version 1 request.
            arglist = inspect.getargspec(self._func)[0][1:]
            if len(self._req_params) < len(arglist):
                err = jsonrpc_error(self._req_id, 'invalid_params')
                return err(environ, start_response)
            else:
                kargs = dict(zip(arglist, self._req_params))
        else:
            # JSON-RPC version 2 request.  Params may be default, and
            # are already a dict, so skip the parameter length check here.
            kargs = self._req_params

        # XX Fix this namespace clash. One cannot use names below as
        # method argument names as this stands!
        kargs['action'], kargs['environ'] = self._req_method, environ
        kargs['start_response'] = start_response
        self._rpc_args = kargs

        status = []
        headers = []
        exc_info = []

        def change_content(new_status, new_headers, new_exc_info=None):
            status.append(new_status)
            headers.extend(new_headers)
            exc_info.append(new_exc_info)

        output = WSGIController.__call__(self, environ, change_content)
        output = list(output)
        headers.append(('Content-Length', str(len(output[0]))))
        replace_header(headers, 'Content-Type', 'application/json')
        start_response(status[0], headers, exc_info[0])

        return output
def __call__ ( self , environ , start_response ) : length = 0 if 'CONTENT_LENGTH' not in environ : log . debug ( "No Content-Length" ) abort ( 411 ) else : if environ [ 'CONTENT_LENGTH' ] == '' : abort ( 411 ) length = int ( environ [ 'CONTENT_LENGTH' ] ) log . debug ( 'Content-Length: %s' , length ) if length == 0 : log . debug ( "Content-Length is 0" ) abort ( 411 ) raw_body = environ [ 'wsgi.input' ] . read ( length ) json_body = json . loads ( urllib . unquote_plus ( raw_body ) ) self . _req_id = json_body [ 'id' ] self . _req_method = json_body [ 'method' ] self . _req_params = json_body [ 'params' ] log . debug ( 'id: %s, method: %s, params: %s' , self . _req_id , self . _req_method , self . _req_params ) self . _error = None try : self . _func = self . _find_method ( ) except AttributeError : err = jsonrpc_error ( self . _req_id , 'method_not_found' ) return err ( environ , start_response ) # now that we have a method, make sure we have enough # parameters and pass off control to the controller. if not isinstance ( self . _req_params , dict ) : # JSON-RPC version 1 request. arglist = inspect . getargspec ( self . _func ) [ 0 ] [ 1 : ] if len ( self . _req_params ) < len ( arglist ) : err = jsonrpc_error ( self . _req_id , 'invalid_params' ) return err ( environ , start_response ) else : kargs = dict ( zip ( arglist , self . _req_params ) ) else : # JSON-RPC version 2 request.  Params may be default, and # are already a dict, so skip the parameter length check here. kargs = self . _req_params # XX Fix this namespace clash. One cannot use names below as # method argument names as this stands! kargs [ 'action' ] , kargs [ 'environ' ] = self . _req_method , environ kargs [ 'start_response' ] = start_response self . _rpc_args = kargs status = [ ] headers = [ ] exc_info = [ ] def change_content ( new_status , new_headers , new_exc_info = None ) : status . append ( new_status ) headers . extend ( new_headers ) exc_info . append ( new_exc_info ) output = WSGIController . __call__ ( self , environ , change_content ) output = list ( output ) headers . append ( ( 'Content-Length' , str ( len ( output [ 0 ] ) ) ) ) replace_header ( headers , 'Content-Type' , 'application/json' ) start_response ( status [ 0 ] , headers , exc_info [ 0 ] ) return output