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


Python resource.NoResource类代码示例

本文整理汇总了Python中twisted.web.resource.NoResource的典型用法代码示例。如果您正苦于以下问题:Python NoResource类的具体用法?Python NoResource怎么用?Python NoResource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NoResource类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: return_404

    def return_404(self, request):
        """Return a 404 HTTP response.
        :param request: The request to which we are responding.
        :returns: NoResource's rendering of the request.

        Performed if a request tries to access a nonexistent table.
        """
        page = NoResource(message="Table %s could not be found" %
                          self.table_name)
        return page.render(request)
开发者ID:auntieNeo,项目名称:asterisk-testsuite,代码行数:10,代码来源:realtime_test_module.py

示例2: render_POST

 def render_POST(self, request):
     if request.path != self._path:
         page = NoResource(
             message="API path %s is not supported" % request.URLPath())
         return page.render(request)
     if request.getHeader(b"Content-Type") != b"application/json":
         page = NoResource(
             message="Unsupported Content-Type (must be \"application/json"
                     "\")" % request.URLPath())
         return page.render(request)
     request.setHeader(b"Content-Type", b"application/json")
     self._callback(request)
     return NOT_DONE_YET
开发者ID:2php,项目名称:veles,代码行数:13,代码来源:restful_api.py

示例3: CgiDirectory

    class CgiDirectory(Resource, FilePath):

        cgiscript = CgiScript

        def __init__(self, pathname, filter, childNotFound=None):
            Resource.__init__(self)
            FilePath.__init__(self, pathname)
            self.filter = filter
            if childNotFound:
                self.childNotFound = childNotFound
            else:
                self.childNotFound = NoResource("CGI directories do not support directory listing.")

        def getChild(self, path, request):
            fnp = self.child(path)
            if not fnp.exists():
                return File.childNotFound
            elif fnp.isdir():
                return CgiDirectory(fnp.path, self.filter, self.childNotFound)
            else:
                return self.cgiscript(fnp.path, self.filter)
            return NoResource()

        def render(self, request):
            return self.childNotFound.render(request)
开发者ID:OspreyX,项目名称:crossbar,代码行数:25,代码来源:resource.py

示例4: render

 def render(self, request):
     if self.type == self.types.REDIRECT:
         return ""
     elif self.type == self.types.QUEUE:
         return NOT_DONE_YET
     else:
         return NoResource.render(self, request)
开发者ID:fullcounter,项目名称:txoffer,代码行数:7,代码来源:txoffer.py

示例5: __init__

 def __init__(self, pathname, filter, childNotFound=None):
     Resource.__init__(self)
     FilePath.__init__(self, pathname)
     self.filter = filter
     if childNotFound:
         self.childNotFound = childNotFound
     else:
         self.childNotFound = NoResource("CGI directories do not support directory listing.")
开发者ID:OspreyX,项目名称:crossbar,代码行数:8,代码来源:resource.py

示例6: Server

	class Server(Resource):

		def __init__(self):
			Resource.__init__(self)
			self.isLeaf = True
			self.r404 = NoResource()

			fp = file(sys.argv[0])
			self.src = fp.read()
			fp.close()

			from subprocess import PIPE, Popen
			try:
				self.src_syn = Popen(['pandoc', '-s'], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate("~~~~ {.python}\n" + self.src + "~~~~\n")[0]
			except OSError:
				sys.stderr.write("pandoc not found; /src/ will default to plain text rather than syntax highlighted code\n")
				self.src_syn = None

		def render_GET(self, request):
			host, path = request.client.host, request.path
			print_flush_log("R %s %s" % (host, path))
			request.setHeader("content-type", "text/plain")

			if path == "/":
				return "%s %s\n%s\n/tcp/[port]\n/udp/[port]\n/src/\n/src/raw\n/src/get\n" % (NAME, VERSION, __doc__)

			try:
				type, port = path[1:].split('/', 2)

				if type == "src":
					if port == "raw":
						return self.src
					elif port == "get":
						request.setHeader("content-type", "text/x-python")
						request.setHeader("content-disposition", "attachment; filename=\"%s\"" % FNAME);
						return self.src
					elif self.src_syn is not None:
						request.setHeader("content-type", "text/html")
						return self.src_syn
					else:
						return self.src

				elif type not in PROTOCOL:
					raise KeyError

				port = int(port)

			except (ValueError, KeyError):
				return self.r404.render(request)

			else:
				start_connect(host, type, port, reactor.callLater)
				return "awaiting connection to %s %s %s" % (host, type, port)
开发者ID:infinity0,项目名称:l33tutils,代码行数:53,代码来源:conntest.py

示例7: __init__

		def __init__(self):
			Resource.__init__(self)
			self.isLeaf = True
			self.r404 = NoResource()

			fp = file(sys.argv[0])
			self.src = fp.read()
			fp.close()

			from subprocess import PIPE, Popen
			try:
				self.src_syn = Popen(['pandoc', '-s'], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate("~~~~ {.python}\n" + self.src + "~~~~\n")[0]
			except OSError:
				sys.stderr.write("pandoc not found; /src/ will default to plain text rather than syntax highlighted code\n")
				self.src_syn = None
开发者ID:infinity0,项目名称:l33tutils,代码行数:15,代码来源:conntest.py

示例8: render_DELETE

    def render_DELETE(self, request):
        # print "KeyResource.render_DELETE"
        if not self.isRemovable():
            epage = NoResource(
                "deleting collection %s failed." % request.uri)
            return epage.render(request)
            
        if self.isdir():
            depth = get_depth(request)
            if not depth:
                epage = BadRequestResource(
                    "deleting collection %s failed."
                    "because depth is not "infinity""
                    % request.uri)
                return epage.render(request)

            self.rmtree()
        else:
            self.remove()

        epage = NoContentResource("%s deleted" % request.uri)
        return epage.render(request)
开发者ID:steder,项目名称:AkaDAV,代码行数:22,代码来源:davresource.py

示例9: __init__

 def __init__(self):
     NoResource.__init__(self, "No pack number specified")
     self.brief = "No Such Pack"
     self.types = collections.namedtuple("Pack_Types", ["ERROR", "REDIRECT", "QUEUE"])._make(range(3))
     self.type = self.types.ERROR
开发者ID:fullcounter,项目名称:txoffer,代码行数:5,代码来源:txoffer.py

示例10: render

 def render(self, request):
    notFound = NoResource("CGI directories do not support directory listing.")
    return notFound.render(request)
开发者ID:Inspire2Innovate,项目名称:crossbar,代码行数:3,代码来源:cgiresource.py

示例11: __init__

 def __init__(self):
     NoResource.__init__(self, b'Resource not found')
开发者ID:jonathanj,项目名称:txspinneret,代码行数:2,代码来源:resource.py

示例12: getChild

    def getChild(self, path, request):
        """Find the appropriate child resource depending on request type

        Possible URLs:
        - /foo/bar/info/refs -> info refs (file / SmartHTTP hybrid)
        - /foo/bar/git-upload-pack -> SmartHTTP RPC
        - /foo/bar/git-receive-pack -> SmartHTTP RPC
        - /foo/bar/HEAD -> file (dumb http)
        - /foo/bar/objects/* -> file (dumb http)
        """
        path = request.path  # alternatively use path + request.postpath
        pathparts = path.split('/')
        writerequired = False
        script_name = '/'
        new_path = path
        resource = NoResource()

        # Path lookup / translation
        path_info = self.git_configuration.path_lookup(path,
                                                       protocol_hint='http')
        if path_info is None:
            log.msg('User %s tried to access %s '
                    'but the lookup failed' % (self.username, path))
            return resource

        log.msg('Lookup of %s gave %r' % (path, path_info))

        if (path_info['repository_fs_path'] is None and
            path_info['repository_base_fs_path'] is None):
            log.msg('Neither a repository base nor a repository were returned')
            return resource

        # split script_name / new_path according to path info
        if path_info['repository_base_url_path'] is not None:
            script_name = '/'
            script_name += path_info['repository_base_url_path'].strip('/')
            new_path = path[len(script_name.rstrip('/')):]

        # since pretty much everything needs read access, check for it now
        if not self.authnz.can_read(self.username, path_info):
            if self.username is None:
                return UnauthorizedResource(self.credentialFactories)
            else:
                return ForbiddenResource("You don't have read access")

        # Smart HTTP requests
        # /info/refs
        if (len(pathparts) >= 2 and
            pathparts[-2] == 'info' and
            pathparts[-1] == 'refs'):
            writerequired = ('service' in request.args and
                             request.args['service'][0] == 'git-receive-pack')
            resource = InfoRefs(path_info['repository_fs_path'])

        # /git-upload-pack (client pull)
        elif len(pathparts) >= 1 and pathparts[-1] == 'git-upload-pack':
            cmd = 'git'
            args = [os.path.basename(cmd), 'upload-pack', '--stateless-rpc',
                    path_info['repository_fs_path']]
            resource = GitCommand(cmd, args)
            request.setHeader('Content-Type',
                              'application/x-git-upload-pack-result')

        # /git-receive-pack (client push)
        elif len(pathparts) >= 1 and pathparts[-1] == 'git-receive-pack':
            writerequired = True
            cmd = 'git'
            args = [os.path.basename(cmd), 'receive-pack',
                    '--stateless-rpc', path_info['repository_fs_path']]
            resource = GitCommand(cmd, args)
            request.setHeader('Content-Type',
                              'application/x-git-receive-pack-result')

        # static files as specified in file_headers or fallback webfrontend
        else:
            # determine the headers for this file
            filename, headers = None, None
            for matcher, get_headers in file_headers.items():
                m = matcher.match(path)
                if m:
                    filename = m.group(1)
                    headers = get_headers()
                    break

            if filename is not None:
                for key, val in headers.items():
                    request.setHeader(key, val)

                log.msg("Returning file %s" % os.path.join(
                                    path_info['repository_fs_path'], filename))
                resource = File(os.path.join(path_info['repository_fs_path'],
                                        filename), headers['Content-Type'])
                resource.isLeaf = True  # static file -> it is a leaf

            else:
                # No match -> fallback to git viewer
                if script_name is not None:
                    # patch pre/post path of request according to
                    # script_name and path
                    request.prepath = script_name.strip('/').split('/')
#.........这里部分代码省略.........
开发者ID:mensi,项目名称:gitserverglue,代码行数:101,代码来源:http.py

示例13: responseNotFound

 def responseNotFound(self, request, failure):
     errorPage = NoResource(message=failure.getErrorMessage())
     request.write(errorPage.render(request))
     request.finish()
开发者ID:dir01,项目名称:lrcs,代码行数:4,代码来源:site.py


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