本文整理汇总了Python中twext.python.filepath.CachingFilePath.childSearchPreauth方法的典型用法代码示例。如果您正苦于以下问题:Python CachingFilePath.childSearchPreauth方法的具体用法?Python CachingFilePath.childSearchPreauth怎么用?Python CachingFilePath.childSearchPreauth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twext.python.filepath.CachingFilePath
的用法示例。
在下文中一共展示了CachingFilePath.childSearchPreauth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: File
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import childSearchPreauth [as 别名]
#.........这里部分代码省略.........
return None
def listChildren(self):
"""
@return: a sequence of the names of all known children of this resource.
"""
children = self.putChildren.keys()
if self.fp.isdir():
children += [c for c in self.fp.listdir() if c not in children]
self.knownChildren = set(children)
return children
def locateChild(self, req, segments):
"""
See L{IResource}C{.locateChild}.
"""
# If getChild() finds a child resource, return it
child = self.getChild(segments[0])
if child is not None: return (child, segments[1:])
# If we're not backed by a directory, we have no children.
# But check for existance first; we might be a collection resource
# that the request wants created.
self.fp.restat(False)
if self.fp.exists() and not self.fp.isdir(): return (None, ())
# OK, we need to return a child corresponding to the first segment
path = segments[0]
if path:
fpath = self.fp.child(path)
else:
# Request is for a directory (collection) resource
return (self, server.StopTraversal)
# Don't run processors on directories - if someone wants their own
# customized directory rendering, subclass File instead.
if fpath.isfile():
processor = self.processors.get(fpath.splitext()[1].lower())
if processor:
return (
processor(fpath.path),
segments[1:])
elif not fpath.exists():
sibling_fpath = fpath.siblingExtensionSearch(*self.ignoredExts)
if sibling_fpath is not None:
fpath = sibling_fpath
return self.createSimilarFile(fpath.path), segments[1:]
def renderHTTP(self, req):
self.fp.changed()
return super(File, self).renderHTTP(req)
def render(self, req):
"""You know what you doing."""
if not self.fp.exists():
return responsecode.NOT_FOUND
if self.fp.isdir():
if req.path[-1] != "/":
# Redirect to include trailing '/' in URI
return http.RedirectResponse(req.unparseURL(path=req.path+'/'))
else:
ifp = self.fp.childSearchPreauth(*self.indexNames)
if ifp:
# Render from the index file
standin = self.createSimilarFile(ifp.path)
else:
# Directory listing is in twistedcaldav.extensions
standin = Data(
"\n".join(["Directory: " + str(req.path), "---"] +
[x.basename() + ("/" if x.isdir() else "")
for x in self.fp.children()]),
"text/plain")
return standin.render(req)
try:
f = self.fp.open()
except IOError, e:
import errno
if e[0] == errno.EACCES:
return responsecode.FORBIDDEN
elif e[0] == errno.ENOENT:
return responsecode.NOT_FOUND
else:
raise
response = http.Response()
response.stream = stream.FileStream(f, 0, self.fp.getsize())
for (header, value) in (
("content-type", self.contentType()),
("content-encoding", self.contentEncoding()),
):
if value is not None:
response.headers.setHeader(header, value)
return response