本文整理汇总了Python中twisted.web.http.NOT_ALLOWED属性的典型用法代码示例。如果您正苦于以下问题:Python http.NOT_ALLOWED属性的具体用法?Python http.NOT_ALLOWED怎么用?Python http.NOT_ALLOWED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类twisted.web.http
的用法示例。
在下文中一共展示了http.NOT_ALLOWED属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _nonce_response
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import NOT_ALLOWED [as 别名]
def _nonce_response(url, nonce):
"""
Construct an expected request for an initial nonce check.
:param bytes url: The url being requested.
:param bytes nonce: The nonce to return.
:return: A request/response tuple suitable for use with
:class:`~treq.testing.RequestSequence`.
"""
return (
MatchesListwise([
Equals(b'HEAD'),
Equals(url),
Equals({}),
ContainsDict({b'User-Agent':
MatchesListwise([StartsWith(b'txacme/')])}),
Equals(b'')]),
(http.NOT_ALLOWED,
{b'content-type': JSON_CONTENT_TYPE,
b'replay-nonce': b64encode(nonce)},
b'{}'))
示例2: _handleStar
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import NOT_ALLOWED [as 别名]
def _handleStar(self):
"""
Handle receiving a request whose path is '*'.
RFC 7231 defines an OPTIONS * request as being something that a client
can send as a low-effort way to probe server capabilities or readiness.
Rather than bother the user with this, we simply fast-path it back to
an empty 200 OK. Any non-OPTIONS verb gets a 405 Method Not Allowed
telling the client they can only use OPTIONS.
"""
if self.method == b'OPTIONS':
self.setResponseCode(http.OK)
else:
self.setResponseCode(http.NOT_ALLOWED)
self.setHeader(b'Allow', b'OPTIONS')
# RFC 7231 says we MUST set content-length 0 when responding to this
# with no body.
self.setHeader(b'Content-Length', b'0')
self.finish()
示例3: test_errorGet
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import NOT_ALLOWED [as 别名]
def test_errorGet(self):
"""
A classic GET on the xml server should return a NOT_ALLOWED.
"""
agent = client.Agent(reactor)
d = agent.request(b"GET", networkString("http://127.0.0.1:%d/" % (self.port,)))
def checkResponse(response):
self.assertEqual(response.code, http.NOT_ALLOWED)
d.addCallback(checkResponse)
return d
示例4: test_unsupported_method
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import NOT_ALLOWED [as 别名]
def test_unsupported_method(self):
"""
If an unsupported method is requested the 405 Not Allowed response
code is returned.
"""
return self.assertResponseCode(
b"BAD_METHOD", b"/VolumeDriver.Path", None, NOT_ALLOWED)
示例5: test_errorGet
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import NOT_ALLOWED [as 别名]
def test_errorGet(self):
"""
A classic GET on the xml server should return a NOT_ALLOWED.
"""
d = client.getPage("http://127.0.0.1:%d/" % (self.port,))
d = self.assertFailure(d, error.Error)
d.addCallback(
lambda exc: self.assertEquals(int(exc.args[0]), http.NOT_ALLOWED))
return d
示例6: render
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import NOT_ALLOWED [as 别名]
def render(self, resrc):
try:
body = resrc.render(self)
except UnsupportedMethod, e:
allowedMethods = e.allowedMethods
if (self.method == "HEAD") and ("GET" in allowedMethods):
# We must support HEAD (RFC 2616, 5.1.1). If the
# resource doesn't, fake it by giving the resource
# a 'GET' request and then return only the headers,
# not the body.
log.msg("Using GET to fake a HEAD request for %s" %
(resrc,))
self.method = "GET"
body = resrc.render(self)
if body is NOT_DONE_YET:
log.msg("Tried to fake a HEAD request for %s, but "
"it got away from me." % resrc)
# Oh well, I guess we won't include the content length.
else:
self.setHeader('content-length', str(len(body)))
self.write('')
self.finish()
return
if self.method in (supportedMethods):
# We MUST include an Allow header
# (RFC 2616, 10.4.6 and 14.7)
self.setHeader('Allow', allowedMethods)
s = ('''Your browser approached me (at %(URI)s) with'''
''' the method "%(method)s". I only allow'''
''' the method%(plural)s %(allowed)s here.''' % {
'URI': self.uri,
'method': self.method,
'plural': ((len(allowedMethods) > 1) and 's') or '',
'allowed': string.join(allowedMethods, ', ')
})
epage = resource.ErrorPage(http.NOT_ALLOWED,
"Method Not Allowed", s)
body = epage.render(self)
else:
epage = resource.ErrorPage(http.NOT_IMPLEMENTED, "Huh?",
"I don't know how to treat a"
" %s request." % (self.method,))
body = epage.render(self)
# end except UnsupportedMethod
示例7: render
# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import NOT_ALLOWED [as 别名]
def render(self, resrc):
try:
body = resrc.render(self)
except UnsupportedMethod, e:
allowedMethods = e.allowedMethods
if (self.method == "HEAD") and ("GET" in allowedMethods):
# We must support HEAD (RFC 2616, 5.1.1). If the
# resource doesn't, fake it by giving the resource
# a 'GET' request and then return only the headers,
# not the body.
log.msg("Using GET to fake a HEAD request for %s" %
(resrc,))
self.method = "GET"
body = resrc.render(self)
if body is NOT_DONE_YET:
log.msg("Tried to fake a HEAD request for %s, but "
"it got away from me." % resrc)
# Oh well, I guess we won't include the content length.
else:
self.setHeader('content-length', str(len(body)))
self.write('')
self.finish()
return
if self.method in (supportedMethods):
# We MUST include an Allow header
# (RFC 2616, 10.4.6 and 14.7)
self.setHeader('Allow', allowedMethods)
s = ('''Your browser approached me (at %(URI)s) with'''
''' the method "%(method)s". I only allow'''
''' the method%(plural)s %(allowed)s here.''' % {
'URI': self.uri,
'method': self.method,
'plural': ((len(allowedMethods) > 1) and 's') or '',
'allowed': string.join(allowedMethods, ', ')
})
epage = error.ErrorPage(http.NOT_ALLOWED,
"Method Not Allowed", s)
body = epage.render(self)
else:
epage = error.ErrorPage(http.NOT_IMPLEMENTED, "Huh?",
"""I don't know how to treat a"""
""" %s request."""
% (self.method))
body = epage.render(self)
# end except UnsupportedMethod