当前位置: 首页>>代码示例>>Python>>正文


Python http.NOT_ALLOWED属性代码示例

本文整理汇总了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'{}')) 
开发者ID:twisted,项目名称:txacme,代码行数:24,代码来源:test_client.py

示例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() 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:22,代码来源:server.py

示例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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_xmlrpc.py

示例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) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:9,代码来源:test_api.py

示例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 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:11,代码来源:test_xmlrpc.py

示例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 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:49,代码来源:server.py

示例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 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:50,代码来源:server.py


注:本文中的twisted.web.http.NOT_ALLOWED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。