twisted.web.http.NO_CONTENT

Here are the examples of the python api twisted.web.http.NO_CONTENT taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

12 Examples 7

Example 1

Project: idavoll Source File: gateway.py
    def render_POST(self, request):
        if request.requestHeaders.hasHeader(b'Event'):
            payload = None
        else:
            payload = parseXml(request.content.read())

        self.callback(payload, request.requestHeaders)

        request.setResponseCode(http.NO_CONTENT)
        return b''

Example 2

Project: idavoll Source File: test_gateway.py
Function: test_post
    def test_post(self):
        """
        The body posted is passed to the callback.
        """
        request = DummyRequest([b''])
        request.method = 'POST'
        request.content = StringIO(b'<root><child/></root>')

        def rendered(result):
            self.assertEqual(1, len(self.callbackEvents))
            payload, headers = self.callbackEvents[-1]
            self.assertEqual('root', payload.name)

            self.assertEqual(http.NO_CONTENT, request.responseCode)
            self.assertFalse(b''.join(request.written))

        d = _render(self.resource, request)
        d.addCallback(rendered)
        return d

Example 3

Project: shinysdr Source File: testutil.py
def _handle_agent_response(d):
    def callback(response):
        finished = Deferred()
        if response.code == http.NO_CONTENT:
            # TODO: properly get whether there is a body from the response
            # this is a special case because with no content deliverBody never signals connectionLost
            finished.callback((response, None))
        else:
            response.deliverBody(_Accuemulator(finished))
            finished.addCallback(lambda data: (response, data))
        return finished
    d.addCallback(callback)
    return d

Example 4

Project: txyoga Source File: test_deleting.py
    def _checkSuccessfulDeletion(self, _):
        """
        Test that deleting an element succeeded.
        """
        self.assertEqual(self.request.code, http.NO_CONTENT)
        self._checkContentType(None)

Example 5

Project: idavoll Source File: gateway.py
    @_asyncResponse
    def render_POST(self, request):
        """
        Respond to a POST request to create a new node.
        """
        def toResponse(result):
            request.setResponseCode(http.NO_CONTENT)

        def trapNotFound(failure):
            failure.trap(error.NodeNotFound)
            raise Error(http.NOT_FOUND, "Node not found")

        if not request.args.get('uri'):
            raise Error(http.BAD_REQUEST, "No URI given")

        try:
            jid, nodeIdentifier = getServiceAndNode(request.args['uri'][0])
        except XMPPURIParseError, e:
            raise Error(http.BAD_REQUEST, "Malformed XMPP URI: %s" % e)


        data = request.content.read()
        if data:
            params = simplejson.loads(data)
            redirectURI = params.get('redirect_uri', None)
        else:
            redirectURI = None

        d = self.backend.deleteNode(nodeIdentifier, self.owner,
                                    redirectURI)
        d.addCallback(toResponse)
        d.addErrback(trapNotFound)
        return d

Example 6

Project: idavoll Source File: gateway.py
    @_asyncResponse
    def render_POST(self, request):
        def trapNotFound(failure):
            err = failure.trap(*self.errorMap.keys())
            status, message = self.errorMap[err]
            raise Error(status, message)

        def toResponse(result):
            request.setResponseCode(http.NO_CONTENT)
            return b''

        def trapXMPPURIParseError(failure):
            failure.trap(XMPPURIParseError)
            raise Error(http.BAD_REQUEST,
                        "Malformed XMPP URI: %s" % failure.value)

        data = request.content.read()
        self.params = simplejson.loads(data)

        uri = self.params['uri']
        callback = self.params['callback']

        jid, nodeIdentifier = getServiceAndNode(uri)
        method = getattr(self.service, self.serviceMethod)
        d = method(jid, nodeIdentifier, callback)
        d.addCallback(toResponse)
        d.addErrback(trapNotFound)
        d.addErrback(trapXMPPURIParseError)
        return d

Example 7

Project: idavoll Source File: test_gateway.py
Function: test_post
    def test_post(self):
        """
        Upon a POST, a new node is created and the URI returned.
        """
        request = DummyRequest([b''])
        request.method = b'POST'

        def rendered(result):
            self.assertEqual(http.NO_CONTENT, request.responseCode)

        def nodeCreated(nodeIdentifier):
            uri = gateway.getXMPPURI(componentJID, nodeIdentifier)
            request.args[b'uri'] = [uri]
            request.content = StringIO(b'')

            return _render(self.resource, request)

        d = self.backend.createNode(u'test', ownerJID)
        d.addCallback(nodeCreated)
        d.addCallback(rendered)
        return d

Example 8

Project: idavoll Source File: test_gateway.py
    def test_postWithRedirect(self):
        """
        Upon a POST, a new node is created and the URI returned.
        """
        request = DummyRequest([b''])
        request.method = b'POST'
        otherNodeURI = b'xmpp:pubsub.example.org?node=other'

        def rendered(result):
            self.assertEqual(http.NO_CONTENT, request.responseCode)
            self.assertEqual(1, len(deletes))
            nodeIdentifier, owner, redirectURI = deletes[-1]
            self.assertEqual(otherNodeURI, redirectURI)

        def nodeCreated(nodeIdentifier):
            uri = gateway.getXMPPURI(componentJID, nodeIdentifier)
            request.args[b'uri'] = [uri]
            payload = {b'redirect_uri': otherNodeURI}
            body = simplejson.dumps(payload)
            request.content = StringIO(body)
            return _render(self.resource, request)

        def deleteNode(nodeIdentifier, owner, redirectURI):
            deletes.append((nodeIdentifier, owner, redirectURI))
            return defer.succeed(nodeIdentifier)

        deletes = []
        self.patch(self.backend, 'deleteNode', deleteNode)
        d = self.backend.createNode(u'test', ownerJID)
        d.addCallback(nodeCreated)
        d.addCallback(rendered)
        return d

Example 9

Project: crossbar Source File: longpoll.py
    def render_POST(self, request):
        """
        A client sends a message via WAMP-over-Longpoll by HTTP/POSTing
        to this Web resource. The body of the POST should contain a batch
        of WAMP messages which are serialized according to the selected
        serializer, and delimited by a single ``\0`` byte in between two WAMP
        messages in the batch.
        """
        payload = request.content.read()
        self.log.debug(
            "WampLongPoll: receiving data for transport '{tid}'\n{octets}",
            tid=self._parent._transport_id,
            octets=_LazyHexFormatter(payload),
        )

        try:
            # process (batch of) WAMP message(s)
            self._parent.onMessage(payload, None)

        except Exception:
            f = create_failure()
            self.log.error(
                "Could not unserialize WAMP message: {msg}",
                msg=failure_message(f),
            )
            self.log.debug("{tb}", tb=failure_format_traceback(f))
            return self._parent._parent._fail_request(
                request,
                b"could not unserialize WAMP message."
            )

        else:
            request.setResponseCode(http.NO_CONTENT)
            self._parent._parent._set_standard_headers(request)
            self._parent._isalive = True
            return b""

Example 10

Project: crossbar Source File: longpoll.py
Function: render_post
    def render_POST(self, request):
        """
        A client may actively close a session (and the underlying long-poll transport)
        by issuing a HTTP/POST with empty body to this resource.
        """
        self.log.debug(
            "WampLongPoll: closing transport '{tid}'",
            tid=self._parent._transport_id,
        )

        # now actually close the session
        self._parent.close()

        self.log.debug(
            "WampLongPoll: session ended and transport {tid} closed",
            tid=self._parent._transport_id,
        )

        request.setResponseCode(http.NO_CONTENT)
        self._parent._parent._set_standard_headers(request)
        return b""

Example 11

Project: shinysdr Source File: test_db.py
    def test_update_good(self):
        new_data = {
            u'type': u'channel',
            u'lowerFreq': 20e6,
            u'upperFreq': 20e6,
            u'label': u'modified',
        }
        index = u'1'
        modified = dict(self.response_json[u'records'])
        modified[index] = db.normalize_record(new_data)

        d = testutil.http_post(reactor, self.__url('/' + str(index)), {
            'old': self.response_json[u'records'][index],
            'new': new_data
        })

        def proceed((response, data)):
            if response.code >= 300:
                print data
            self.assertEqual(response.code, http.NO_CONTENT)
            
            def check(s):
                j = json.loads(s)
                self.assertEqual(j[u'records'], modified)
            
            return client.getPage(self.__url('/')).addCallback(check)

Example 12

Project: txyoga Source File: resource.py
Function: render
    def render(self, request):
        request.setResponseCode(http.NO_CONTENT)
        return ""