當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。