Python twisted.web.http.NO_CONTENT Examples

The following are 5 code examples of twisted.web.http.NO_CONTENT(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module twisted.web.http , or try the search function .
Example #1
Source File: backup_account_resource.py    From pixelated-user-agent with GNU Affero General Public License v3.0 6 votes vote down vote up
def render_POST(self, request):
        account_recovery = AccountRecovery(
            self._authenticator.bonafide_session,
            self.soledad(request),
            self._service(request, '_leap_session').smtp_config,
            self._get_backup_email(request),
            self._leap_provider.server_name,
            language=self._get_language(request))

        def update_response(response):
            request.setResponseCode(NO_CONTENT)
            request.finish()

        def error_response(response):
            request.setResponseCode(INTERNAL_SERVER_ERROR)
            request.finish()

        d = account_recovery.update_recovery_code()
        d.addCallbacks(update_response, error_response)
        return NOT_DONE_YET 
Example #2
Source File: server.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def write(self, data):
        """
        Write data to the transport (if not responding to a HEAD request).

        @param data: A string to write to the response.
        @type data: L{bytes}
        """
        if not self.startedWriting:
            # Before doing the first write, check to see if a default
            # Content-Type header should be supplied. We omit it on
            # NOT_MODIFIED and NO_CONTENT responses. We also omit it if there
            # is a Content-Length header set to 0, as empty bodies don't need
            # a content-type.
            needsCT = self.code not in (http.NOT_MODIFIED, http.NO_CONTENT)
            contentType = self.responseHeaders.getRawHeaders(b'content-type')
            contentLength = self.responseHeaders.getRawHeaders(
                b'content-length'
            )
            contentLengthZero = contentLength and (contentLength[0] == b'0')

            if (needsCT and contentType is None and
                self.defaultContentType is not None and
                not contentLengthZero
                    ):
                self.responseHeaders.setRawHeaders(
                    b'content-type', [self.defaultContentType])

        # Only let the write happen if we're not generating a HEAD response by
        # faking out the request method.  Note, if we are doing that,
        # startedWriting will never be true, and the above logic may run
        # multiple times.  It will only actually change the responseHeaders
        # once though, so it's still okay.
        if not self._inFakeHead:
            if self._encoder:
                data = self._encoder.encode(data)
            http.Request.write(self, data) 
Example #3
Source File: test_web.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def render(self, request):
        request.setResponseCode(http.NO_CONTENT)
        return b'' 
Example #4
Source File: test_ical.py    From ccs-calendarserver with Apache License 2.0 5 votes vote down vote up
def test_deleteEvent(self):
        """
        L{OS_X_10_11.deleteEvent} DELETEs the event at the relative
        URL passed to it and updates local state to reflect its
        removal.
        """
        requests = self.interceptRequests()

        calendar = Calendar(caldavxml.calendar, set(('VEVENT',)), u'calendar', u'/foo/', None)
        event = Event(None, calendar.url + u'bar.ics', None)
        self.client._calendars[calendar.url] = calendar
        self.client._setEvent(event.url, event)

        d = self.client.deleteEvent(event.url)

        result, req = requests.pop()

        expectedResponseCode, method, url = req

        self.assertEqual(expectedResponseCode, (NO_CONTENT, NOT_FOUND))
        self.assertEqual(method, 'DELETE')
        self.assertEqual(url, 'http://127.0.0.1' + event.url)
        self.assertIsInstance(url, str)

        self.assertNotIn(event.url, self.client._events)
        self.assertNotIn(u'bar.ics', calendar.events)

        response = MemoryResponse(
            ('HTTP', '1', '1'), NO_CONTENT, "No Content", None,
            StringProducer(""))
        result.callback((response, ""))
        return d 
Example #5
Source File: benchlib.py    From ccs-calendarserver with Apache License 2.0 5 votes vote down vote up
def deleteResource(self, path):
        url = self._makeURL(path)
        d = self.agent.request('DELETE', url)

        def deleted(response):
            if response.code not in (NO_CONTENT, NOT_FOUND):
                raise Exception(
                    "Unexpected response to DELETE %s: %d" % (
                        url, response.code))
        d.addCallback(deleted)
        return d