本文整理汇总了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