當前位置: 首頁>>代碼示例>>Python>>正文


Python http.NOT_FOUND屬性代碼示例

本文整理匯總了Python中twisted.web.http.NOT_FOUND屬性的典型用法代碼示例。如果您正苦於以下問題:Python http.NOT_FOUND屬性的具體用法?Python http.NOT_FOUND怎麽用?Python http.NOT_FOUND使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在twisted.web.http的用法示例。


在下文中一共展示了http.NOT_FOUND屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: response_no_results

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def response_no_results(self, bucket):
        """
        Send "404 Not Found" response body in text/plain
        format describing HTTP API query interface.
        """
        # FIXME: Some words about "now-10d" being the default for "from", see influx.py.
        # FIXME: Maybe refactor "now-10d" to transformation machinery to make it accessible from here.
        error_message = u'# 404 Not Found\n#\n'\
                        u'# No data for query expression "{expression}"\n'\
                        u'# Please recognize absolute datetimes are expected to be in ISO 8601 format. '\
                        u'Default is UTC, optionally specify an appropriate timezone offset.\n'.format(expression=bucket.tdata.expression)
        error_message += u'#\n# Examples:\n#\n'\
                         u'#   ?from=2016-06-25T22:00:00.000Z\n'\
                         u'#   ?from=2016-06-26T00:00:00.000%2B02:00    (%2B is "+" urlencoded)\n'\
                         u'#   ?from=now-4h&to=now-2h\n'\
                         u'#   ?from=now-8d5h3m&to=now-6d'
        bucket.request.setResponseCode(http.NOT_FOUND)
        bucket.request.setHeader('Content-Type', 'text/plain; charset=utf-8')
        return error_message.encode('utf-8') 
開發者ID:daq-tools,項目名稱:kotori,代碼行數:21,代碼來源:target.py

示例2: test_notFoundChild

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def test_notFoundChild(self):
        """
        L{ResourceScriptDirectory.getChild} returns a resource which renders an
        response with the HTTP I{NOT FOUND} status code if the indicated child
        does not exist as an entry in the directory used to initialized the
        L{ResourceScriptDirectory}.
        """
        path = self.mktemp()
        os.makedirs(path)
        resource = ResourceScriptDirectory(path)
        request = DummyRequest([b'foo'])
        child = resource.getChild("foo", request)
        d = _render(child, request)
        def cbRendered(ignored):
            self.assertEqual(request.responseCode, NOT_FOUND)
        d.addCallback(cbRendered)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:test_script.py

示例3: test_notFoundChild

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def test_notFoundChild(self):
        """
        L{twcgi.CGIDirectory.getChild} returns a resource which renders an
        response with the HTTP I{NOT FOUND} status code if the indicated child
        does not exist as an entry in the directory used to initialized the
        L{twcgi.CGIDirectory}.
        """
        path = self.mktemp()
        os.makedirs(path)
        resource = twcgi.CGIDirectory(path)
        request = DummyRequest(['foo'])
        child = resource.getChild("foo", request)
        d = _render(child, request)
        def cbRendered(ignored):
            self.assertEqual(request.responseCode, NOT_FOUND)
        d.addCallback(cbRendered)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:test_cgi.py

示例4: render_GET

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def render_GET(self, request):
        id = extractSessionId(request)

        if not id:
           message = "id not provided in GET request"
           logging.error(message)
           request.setResponseCode(http.BAD_REQUEST)
           return jsonResponse({"error":message})

        logging.info("GET request received for id: %s" % id)

        session = self.session_manager.getSession(id)
        if not session:
           message = "No session with id: %s" % id
           logging.error(message)
           request.setResponseCode(http.NOT_FOUND)
           return jsonResponse({"error":message})

        # Return session meta-data
        request.setResponseCode(http.OK)
        return jsonResponse(filterResponse(session, self.field_filter))

    # =========================================================================
    # Handle DELETE request
    # ========================================================================= 
開發者ID:Kitware,項目名稱:wslink,代碼行數:27,代碼來源:launcher.py

示例5: render

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def render(self, request):
        """Render me to a web client.

        Load my file, execute it in a special namespace (with 'request' and
        '__file__' global vars) and finish the request.  Output to the web-page
        will NOT be handled with print - standard output goes to the log - but
        with request.write.
        """
        request.setHeader("x-powered-by","Twisted/%s" % copyright.version)
        namespace = {'request': request,
                     '__file__': self.filename,
                     'registry': self.registry}
        try:
            execfile(self.filename, namespace, namespace)
        except IOError, e:
            if e.errno == 2: #file not found
                request.setResponseCode(http.NOT_FOUND)
                request.write(resource.NoResource("File not found.").render(request)) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:20,代碼來源:script.py

示例6: render

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def render(self, request):
        """Render me to a web client.

        Load my file, execute it in a special namespace (with 'request' and
        '__file__' global vars) and finish the request.  Output to the web-page
        will NOT be handled with print - standard output goes to the log - but
        with request.write.
        """
        request.setHeader("x-powered-by","Twisted/%s" % copyright.version)
        namespace = {'request': request,
                     '__file__': self.filename,
                     'registry': self.registry}
        try:
            execfile(self.filename, namespace, namespace)
        except IOError, e:
            if e.errno == 2: #file not found
                request.setResponseCode(http.NOT_FOUND)
                request.write(error.NoResource("File not found.").render(request)) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:20,代碼來源:script.py

示例7: testTriggerNotFound

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def testTriggerNotFound(self):
        response, body = yield self.request('GET', 'trigger/{0}'.format(self.trigger.id), state=http.NOT_FOUND) 
開發者ID:moira-alert,項目名稱:worker,代碼行數:4,代碼來源:test_api.py

示例8: render_GET

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def render_GET(self, request):
        json, trigger = yield self.db.getTrigger(self.trigger_id)
        if json is None:
            request.setResponseCode(http.NOT_FOUND)
            request.finish()
        else:
            throttling = yield self.db.getTriggerThrottling(self.trigger_id)
            trigger["throttling"] = throttling
            self.write_json(request, trigger) 
開發者ID:moira-alert,項目名稱:worker,代碼行數:11,代碼來源:trigger.py

示例9: render

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def render(self, request):
        """
        Render me to a web client.

        Load my file, execute it in a special namespace (with 'request' and
        '__file__' global vars) and finish the request.  Output to the web-page
        will NOT be handled with print - standard output goes to the log - but
        with request.write.
        """
        request.setHeader(b"x-powered-by", networkString("Twisted/%s" % copyright.version))
        namespace = {'request': request,
                     '__file__': _coerceToFilesystemEncoding("", self.filename),
                     'registry': self.registry}
        try:
            execfile(self.filename, namespace, namespace)
        except IOError as e:
            if e.errno == 2: #file not found
                request.setResponseCode(http.NOT_FOUND)
                request.write(resource.NoResource("File not found.").render(request))
        except:
            io = NativeStringIO()
            traceback.print_exc(file=io)
            output = util._PRE(io.getvalue())
            if _PY3:
                output = output.encode("utf8")
            request.write(output)
        request.finish()
        return server.NOT_DONE_YET 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:30,代碼來源:script.py

示例10: test_renderNotFound

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def test_renderNotFound(self):
        """
        L{ResourceScriptDirectory.render} sets the HTTP response code to I{NOT
        FOUND}.
        """
        resource = ResourceScriptDirectory(self.mktemp())
        request = DummyRequest([b''])
        d = _render(resource, request)
        def cbRendered(ignored):
            self.assertEqual(request.responseCode, NOT_FOUND)
        d.addCallback(cbRendered)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:14,代碼來源:test_script.py

示例11: test_notFoundRender

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def test_notFoundRender(self):
        """
        If the source file a L{PythonScript} is initialized with doesn't exist,
        L{PythonScript.render} sets the HTTP response code to I{NOT FOUND}.
        """
        resource = PythonScript(self.mktemp(), None)
        request = DummyRequest([b''])
        d = _render(resource, request)
        def cbRendered(ignored):
            self.assertEqual(request.responseCode, NOT_FOUND)
        d.addCallback(cbRendered)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:14,代碼來源:test_script.py

示例12: test_childrenNotFound

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def test_childrenNotFound(self):
        """
        Any child resource of L{static.DirectoryLister} renders an HTTP
        I{NOT FOUND} response code.
        """
        path = FilePath(self.mktemp())
        path.makedirs()
        lister = static.DirectoryLister(path.path)
        request = self._request(b'')
        child = resource.getChildForRequest(lister, request)
        result = _render(child, request)
        def cbRendered(ignored):
            self.assertEqual(request.responseCode, http.NOT_FOUND)
        result.addCallback(cbRendered)
        return result 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:17,代碼來源:test_static.py

示例13: test_renderWithUnknownHostNoDefault

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def test_renderWithUnknownHostNoDefault(self):
        """
        L{NameVirtualHost.render} returns a response with a status of I{NOT
        FOUND} if the instance's C{default} is L{None} and there is no host
        matching the value of the I{Host} header in the request.
        """
        virtualHostResource = NameVirtualHost()
        request = DummyRequest([''])
        request.requestHeaders.addRawHeader(b'host', b'example.com')
        d = _render(virtualHostResource, request)
        def cbRendered(ignored):
            self.assertEqual(request.responseCode, NOT_FOUND)
        d.addCallback(cbRendered)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:16,代碼來源:test_vhost.py

示例14: test_render

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def test_render(self):
        """
        L{twcgi.CGIDirectory.render} sets the HTTP response code to I{NOT
        FOUND}.
        """
        resource = twcgi.CGIDirectory(self.mktemp())
        request = DummyRequest([''])
        d = _render(resource, request)
        def cbRendered(ignored):
            self.assertEqual(request.responseCode, NOT_FOUND)
        d.addCallback(cbRendered)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:14,代碼來源:test_cgi.py

示例15: test_unknown_uri

# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import NOT_FOUND [as 別名]
def test_unknown_uri(self):
        """
        If an unknown URI path is requested the 404 Not Found response code is
        returned.
        """
        return self.assertResponseCode(
            b"BAD_METHOD", b"/xxxnotthere", None, NOT_FOUND) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:9,代碼來源:test_api.py


注:本文中的twisted.web.http.NOT_FOUND屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。