当前位置: 首页>>代码示例>>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;未经允许,请勿转载。