本文整理汇总了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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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()
示例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)
示例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)
示例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
示例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)
示例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
示例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)
示例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)