Beispiel #1
0
 def _process_get(self, fields=[]):
     response = HttpResponse(node=self,
                             content_type=self._matching_outputs[0])
     
     request_range = self.request.META.get('HTTP_RANGE')
     kwparams = {}
     if not request_range:
         response['Accept-Range'] = self.range_unit
     else:
         kwparams = {'offset': request_range.offset,
                     'limit' : request_range.limit}    
     items = self._call_http_method_handler(**kwparams)
     if items is None:
         raise ValueError('%s() method of node %s returned None.' % 
                          (self.method_handlers.get(self.request.method),
                           self.__class__.__name__))
     
     if not len(items) and request_range: 
         raise RequestedRangeNotSatisfiableError(self)
     
     response.payload = []
     for item in items:
         try:
             response.payload.append(item.render_in_collection())
         except ForbiddenError:
             pass
     
     if not len(response.payload):
         response.status = 204
     elif request_range:
         response.status = 206 
     else:
         response.status = 200
         
     return response
Beispiel #2
0
    def _process_get(self):
        response = HttpResponse(node=self,
                                content_type=self._matching_outputs[0])
        data = self._call_http_method_handler(method='GET')
        for node_cls in self.__class__.get_children_nodes():
            try:
                child_node = node_cls(self.request, parent_node=self, **self._chained_args)
                data.update(child_node.render_in_parent())
            except ForbiddenError:
                continue

        response.payload = data
        return response
Beispiel #3
0
    def _process_get(self):
        response = HttpResponse(node=self,
                                content_type=self._matching_outputs[0])
        data = self._call_http_method_handler(method='GET')

        for node_cls in self.__class__.get_children_nodes():
            try:
                child_node = node_cls(self.request, **self._chained_args)
                data.update(child_node.render_in_parent())
            except ForbiddenError:
                continue

        response.payload = data
        return response
Beispiel #4
0
 def _process_delete(self):
     '''The handler should return a boolean specifying whether the deleted
     resource should be included in the body of the response'''
     self._post_mortem_etag = self.get_etag()
     if self._call_http_method_handler() is False:
         return HttpResponse(node=self, status=204)
     return self._process_get()
Beispiel #5
0
    def process(cls, request, **kwargs):
        if request.method not in cls.get_allowed_methods():
            raise MethodNotAllowedError(cls)

        response = HttpResponse(status=301 if cls.permanent else 302)
        response['Location'] = (cls(
            request, **kwargs).get_canonical_node(**kwargs).build_url())
        return response
Beispiel #6
0
    def _process_options(self):
        '''The OPTIONS method represents a request for information about
        the communication options available on the request/response chain
        identified by the Request-URL. This method allows the client to
        determine the options and/or requirements associated with a resource,
        or the capabilities of a server, without implying a resource action or
        initiating a resource retrieval.
        [...]
        The response body, if any, SHOULD also include information about
        the communication options.
        (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2)

        Nuages uses the docstring of each HTTP method handler allowed for
        the current node to generate a doc and add it to the body of the
        response.'''
        allowed = self.__class__.get_allowed_methods(implicits=False)
        response = HttpResponse(node=self, status=200)
        response['Allow'] = ', '.join(map(lambda x: x.upper(), allowed))
        response.content = self.__class__.generate_doc()
        return response
Beispiel #7
0
 def _process_options(self):
     '''The OPTIONS method represents a request for information about
     the communication options available on the request/response chain 
     identified by the Request-URL. This method allows the client to 
     determine the options and/or requirements associated with a resource, 
     or the capabilities of a server, without implying a resource action or 
     initiating a resource retrieval.
     [...]
     The response body, if any, SHOULD also include information about
     the communication options.
     (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2)
     
     Nuages uses the docstring of each HTTP method handler allowed for
     the current node to generate a doc and add it to the body of the 
     response.'''
     allowed = self.__class__.get_allowed_methods(implicits=False)
     response = HttpResponse(node=self, status=200)
     response['Allow'] = ', '.join(map(lambda x: x.upper(), allowed))
     response.content = self.__class__.generate_doc()
     return response
Beispiel #8
0
    def _process_get(self, fields=[]):
        response = HttpResponse(node=self,
                                content_type=self._matching_outputs[0])

        request_range = self.request.META.get('HTTP_RANGE')
        kwparams = {}
        if not request_range:
            response['Accept-Range'] = self.range_unit
        else:
            kwparams = {
                'offset': request_range.offset,
                'limit': request_range.limit
            }
        items = self._call_http_method_handler(**kwparams)
        if items is None:
            raise ValueError('%s() method of node %s returned None.' %
                             (self.method_handlers.get(self.request.method),
                              self.__class__.__name__))

        if not len(items) and request_range:
            raise RequestedRangeNotSatisfiableError(self)

        response.payload = []
        for item in items:
            try:
                response.payload.append(item.render_in_collection())
            except ForbiddenError:
                pass

        if not len(response.payload):
            response.status = 204
        elif request_range:
            response.status = 206
        else:
            response.status = 200

        return response
Beispiel #9
0
 def _process_post(self):
     '''Redirects the client to the Node returned by the handler.'''
     created_node = self._call_http_method_handler()
     response = HttpResponse(node=self, status=201)
     response['Location'] = created_node.build_url()
     return response
Beispiel #10
0
 def _process_patch(self):
     '''If not exception is raised, the resource is serialized and included
     in the body of the response'''
     if self._call_http_method_handler() is False:
         return HttpResponse(node=self, status=204)
     return self._process_get()