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


Python Resource.getChild方法代码示例

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


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

示例1: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
    def getChild(self, name, request):
        # Python2.6/3.0
        #log.debug("{0} getting child {1} for {2}".format(
        #          self, name, request))
        log.debug("%r getting child %s for %r" % (self, name, request))

        try:
            sizeDesc, suffix = name.split(".")
            size = int(sizeDesc)

        except (TypeError, ValueError):
            child = Resource.getChild(self, name, request)

        else:
            suffix = suffix.upper()

            if suffix == "B":
                child = Junk(size, self._chunkSize)

            elif suffix == "KB":
                child = Junk(size * 1024, self._chunkSize)

            elif suffix == "MB":
                child = Junk(size * 1024 * 1024, self._chunkSize)

            else:
                child = Resource.getChild(self, name, request)

        return child
开发者ID:alexstaytuned,项目名称:tx-pendrell,代码行数:31,代码来源:server.py

示例2: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
    def getChild(self, path, request):
        """ Implement URL routing.

        todo: add memoization
        """

        def potential_match(match, route):
            """ returns route if match is not None """
            if match:
                args = match.groups() or []
                kw = match.groupdict() or {}
                return route[1](*args, **kw)
            return None

        def try_to_match(url, route):
            """ returns route if match found, None otherwise """
            matching_route = potential_match(route[0].match(url), route)
            if not matching_route:
                # no match, now try toggling the ending slash
                newpath = self._toggleTrailingSlash(request.path)
                matching_route = potential_match(route[0].match(newpath), route)
            return matching_route

        for route in self._routes:
            match = try_to_match(request.path, route)
            if match:
                return match

        # let the base class handle 404
        return Resource.getChild(self, path, request)
开发者ID:pdh,项目名称:diablo,代码行数:32,代码来源:api.py

示例3: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
 def getChild(self, name, request):
     """
     should override.
     """
     if name == "":
         return self
     return Resource.getChild(self, name, request)
开发者ID:alenpeacock,项目名称:flud,代码行数:9,代码来源:ServerPrimitives.py

示例4: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
 def getChild(self, name, request):
     mode = request.args.get("hub.mode", [None])[0]
     if mode in ["subscribe", "unsubscribe"]:
         return pubsub.SubscribeResource()
     elif mode == "publish":
         return pubsub.PublishResource()
     return Resource.getChild(self, name, request)
开发者ID:randell,项目名称:hubb,代码行数:9,代码来源:web.py

示例5: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
    def getChild(self, path, request):
        """
        If path is an empty string or index, render_GET should be called,
        if not, we just look at the templates loaded from the view templates
        directory. If we find a template with the same name than the path
        then we render that template.

        .. caution::

            If there is a controller with the same path than the path
            parameter then it will be hidden and the template in templates
            path should be rendered instead

        :param path: the path
        :type path: str
        :param request: the Twisted request object
        """

        if path == '' or path is None or path == 'index':
            return self

        for template in self.environment.list_templates():
            if path == template.rsplit('.', 1)[0]:
                return self

        return TwistedResource.getChild(self, path, request)
开发者ID:cypreess,项目名称:mamba,代码行数:28,代码来源:resource.py

示例6: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
 def getChild(self, name, request):
     port = request.getHost().port
     if name == 'valid-mirror':
         leaf = DistributionMirrorTestHTTPServer()
         leaf.isLeaf = True
         return leaf
     elif name == 'timeout':
         return NeverFinishResource()
     elif name == 'error':
         return FiveHundredResource()
     elif name == 'redirect-to-valid-mirror':
         assert request.path != name, (
             'When redirecting to a valid mirror the path must have more '
             'than one component.')
         remaining_path = request.path.replace('/%s' % name, '')
         leaf = RedirectingResource(
             'http://localhost:%s/valid-mirror%s' % (port, remaining_path))
         leaf.isLeaf = True
         return leaf
     elif name == 'redirect-infinite-loop':
         return RedirectingResource(
             'http://localhost:%s/redirect-infinite-loop' % port)
     elif name == 'redirect-unknown-url-scheme':
         return RedirectingResource(
             'ssh://localhost/redirect-unknown-url-scheme')
     else:
         return Resource.getChild(self, name, request)
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:29,代码来源:distributionmirror_http_server.py

示例7: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
 def getChild(self, name, request):
     """
     Get the child page for the name given
     """
     if name == '':
         return self
     else:
         return Resource.getChild(self, name, request)
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:10,代码来源:errorpage.py

示例8: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
 def getChild(self, action, request):
     if action == '':
         return self
     else:
         if action in VIEWS.keys():
             return Resource.getChild(self, action, request)
         else:
             return NotFound()
开发者ID:goododd,项目名称:dcTorrent,代码行数:10,代码来源:dcTorrentAdmin.py

示例9: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
 def getChild(self, path, request):
     if path == '':
         return self
     
     if len(request.postpath) >= 1:
         return APITMSID(path)
     
     return Resource.getChild(self, path, request)
开发者ID:robhemsley,项目名称:3form,代码行数:10,代码来源:APIV1.py

示例10: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
 def getChild(self, path, request):
     """override Resource"""
     # TODO: Either add a cache here or throw out the cache in BlockResource which this is defeating, depending on a performance comparison
     path = path.decode('utf-8')  # TODO centralize this 'urls are utf-8'
     if path in self.__cap_table:
         return IResource(self.__resource_factory(self.__cap_table[path]))
     else:
         # old-style-class super call
         return Resource.getChild(self, path, request)
开发者ID:thefinn93,项目名称:shinysdr,代码行数:11,代码来源:export_http.py

示例11: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
    def getChild(self, name, request):
        if name.lower() == "valid":
            child = ValidMD5()
        elif name.lower() == "invalid":
            child = InvalidMD5()
        else:
            child = Resource.getChild(self, name, request)

        return child
开发者ID:alexstaytuned,项目名称:tx-pendrell,代码行数:11,代码来源:md5_server.py

示例12: _getDeferredChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
    def _getDeferredChild(self, name, request):
        try:
            entity = yield self.pubSvc.getEntity(name)

        except KeyError:
            baseName, sfx = self.splitResourceSuffix(name)
            try:
                entity = yield self.pubSvc.getEntity(baseName)
            except KeyError:
                resource = Resource.getChild(self, name, request)
            else:
                resource = self.buildEntityResource(baseName, entity, sfx)
                if not resource.suffixIsSupported(sfx):
                    resource = Resource.getChild(self, name, request)
        else:
            resource = self.buildEntityResource(name, entity)

        returnValue(resource)
开发者ID:olix0r,项目名称:pub,代码行数:20,代码来源:ws.py

示例13: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
    def getChild(self, name, request):
        out = Resource.getChild(self, name, request)
        print name

        if name and out.code == 404 and os.path.exists(os.path.join(self.pdfdir, name)):
            c = self.add_child(name)
            return c
        else:
            return out
开发者ID:sdockray,项目名称:looseleaf,代码行数:11,代码来源:pdfserver.py

示例14: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
 def getChild(self, name, request):
     """Follow the web tree to find the correct resource according to the URL
     
     name    The path specified by the URL
     request A twisted.web.server.Request specifying meta-information about
             the request
     """
     if name == '':
         return self
     return Resource.getChild(self, name, request)
开发者ID:Letractively,项目名称:blkmon,代码行数:12,代码来源:blk_web.py

示例15: getChild

# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import getChild [as 别名]
  def getChild(self, path, request):
	if "media" in path or "favicon.ico" in path:
		return Resource.getChild(self, path, request)
	if len(path) == 0:
		path = "redirect.html"
	template = self.env.get_template(path)
	context = self.contexts.get(path, lambda x,y: {})(self, request)
	context["pairing_supported"]=bluetooth.isPairingSupported()
	context["version"] = __version__
	return TemplateResource(template, context)
开发者ID:aircable,项目名称:AIRi,代码行数:12,代码来源:jinja.py


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