本文整理匯總了Python中twisted.web.http.NO_CONTENT屬性的典型用法代碼示例。如果您正苦於以下問題:Python http.NO_CONTENT屬性的具體用法?Python http.NO_CONTENT怎麽用?Python http.NO_CONTENT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類twisted.web.http
的用法示例。
在下文中一共展示了http.NO_CONTENT屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: render_POST
# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NO_CONTENT [as 別名]
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
示例2: write
# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NO_CONTENT [as 別名]
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)
示例3: render
# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NO_CONTENT [as 別名]
def render(self, request):
request.setResponseCode(http.NO_CONTENT)
return b''
示例4: test_deleteEvent
# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NO_CONTENT [as 別名]
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
示例5: deleteResource
# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NO_CONTENT [as 別名]
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