本文整理汇总了Python中twisted.python.filepath.InsecurePath方法的典型用法代码示例。如果您正苦于以下问题:Python filepath.InsecurePath方法的具体用法?Python filepath.InsecurePath怎么用?Python filepath.InsecurePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath
的用法示例。
在下文中一共展示了filepath.InsecurePath方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getChild
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def getChild(self, path, request):
"""
If this L{File}'s path refers to a directory, return a L{File}
referring to the file named C{path} in that directory.
If C{path} is the empty string, return a L{DirectoryLister} instead.
"""
self.restat(reraise=False)
if not self.isdir():
return self.childNotFound
if path:
try:
fpath = self.child(path)
except filepath.InsecurePath:
return self.childNotFound
else:
fpath = self.childSearchPreauth(*self.indexNames)
if fpath is None:
return self.directoryListing()
if not fpath.exists():
fpath = fpath.siblingExtensionSearch(*self.ignoredExts)
if fpath is None:
return self.childNotFound
if platformType == "win32":
# don't want .RPY to be different than .rpy, since that would allow
# source disclosure.
processor = InsensitiveDict(self.processors).get(fpath.splitext()[1])
else:
processor = self.processors.get(fpath.splitext()[1])
if processor:
return resource.IResource(processor(fpath.path, self.registry))
return self.createSimilarFile(fpath.path)
# methods to allow subclasses to e.g. decrypt files on the fly:
示例2: testPreauthChild
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def testPreauthChild(self):
fp = filepath.FilePath(b'.')
fp.preauthChild(b'foo/bar')
self.assertRaises(filepath.InsecurePath, fp.child, u'/mon\u20acy')
示例3: testInsecureUNIX
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def testInsecureUNIX(self):
self.assertRaises(filepath.InsecurePath, self.path.child, b"..")
self.assertRaises(filepath.InsecurePath, self.path.child, b"/etc")
self.assertRaises(filepath.InsecurePath, self.path.child, b"../..")
示例4: testInsecureWin32
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def testInsecureWin32(self):
self.assertRaises(filepath.InsecurePath, self.path.child, b"..\\..")
self.assertRaises(filepath.InsecurePath, self.path.child, b"C:randomfile")
示例5: testInsecureWin32Whacky
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def testInsecureWin32Whacky(self):
"""
Windows has 'special' filenames like NUL and CON and COM1 and LPR
and PRN and ... god knows what else. They can be located anywhere in
the filesystem. For obvious reasons, we do not wish to normally permit
access to these.
"""
self.assertRaises(filepath.InsecurePath, self.path.child, b"CON")
self.assertRaises(filepath.InsecurePath, self.path.child, b"C:CON")
self.assertRaises(filepath.InsecurePath, self.path.child, r"C:\CON")
示例6: test_descendantOnly
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def test_descendantOnly(self):
"""
If C{".."} is in the sequence passed to L{FilePath.descendant},
L{InsecurePath} is raised.
"""
self.assertRaises(
filepath.InsecurePath,
self.path.descendant, [u'mon\u20acy', u'..'])
示例7: statusForFailure
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def statusForFailure(failure, what=None):
"""
@param failure: a L{Failure}.
@param what: a decription of what was going on when the failure occurred.
If what is not C{None}, emit a cooresponding message via L{log.err}.
@return: a response code cooresponding to the given C{failure}.
"""
def msg(err):
if what is not None:
log.debug("{err} while {what}", err=err, what=what)
if failure.check(IOError, OSError):
e = failure.value[0]
if e == errno.EACCES or e == errno.EPERM:
msg("Permission denied")
return responsecode.FORBIDDEN
elif e == errno.ENOSPC:
msg("Out of storage space")
return responsecode.INSUFFICIENT_STORAGE_SPACE
elif e == errno.ENOENT:
msg("Not found")
return responsecode.NOT_FOUND
else:
failure.raiseException()
elif failure.check(NotImplementedError):
msg("Unimplemented error")
return responsecode.NOT_IMPLEMENTED
elif failure.check(InsecurePath):
msg("Insecure path")
return responsecode.FORBIDDEN
elif failure.check(HTTPError):
code = IResponse(failure.value.response).code
msg("%d response" % (code,))
return code
else:
failure.raiseException()
示例8: locateChild
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def locateChild(self, req, segments):
"""
See L{IResource}C{.locateChild}.
"""
# If getChild() finds a child resource, return it
try:
child = self.getChild(segments[0])
if child is not None:
return (child, segments[1:])
except InsecurePath:
raise HTTPError(StatusResponse(responsecode.FORBIDDEN, "Invalid URL path"))
# 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 == "":
# Request is for a directory (collection) resource
return (self, ())
return (self.createSimilarFile(self.fp.child(path).path), segments[1:])
示例9: testPreauthChild
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def testPreauthChild(self):
fp = filepath.FilePath('.')
fp.preauthChild('foo/bar')
self.assertRaises(filepath.InsecurePath, fp.child, '/foo')
示例10: testInsecureUNIX
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def testInsecureUNIX(self):
self.assertRaises(filepath.InsecurePath, self.path.child, "..")
self.assertRaises(filepath.InsecurePath, self.path.child, "/etc")
self.assertRaises(filepath.InsecurePath, self.path.child, "../..")
示例11: testInsecureWin32
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def testInsecureWin32(self):
self.assertRaises(filepath.InsecurePath, self.path.child, r"..\..")
self.assertRaises(filepath.InsecurePath, self.path.child, r"C:randomfile")
示例12: testInsecureWin32Whacky
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def testInsecureWin32Whacky(self):
"""Windows has 'special' filenames like NUL and CON and COM1 and LPR
and PRN and ... god knows what else. They can be located anywhere in
the filesystem. For obvious reasons, we do not wish to normally permit
access to these.
"""
self.assertRaises(filepath.InsecurePath, self.path.child, "CON")
self.assertRaises(filepath.InsecurePath, self.path.child, "C:CON")
self.assertRaises(filepath.InsecurePath, self.path.child, r"C:\CON")
示例13: do
# 需要导入模块: from twisted.python import filepath [as 别名]
# 或者: from twisted.python.filepath import InsecurePath [as 别名]
def do(self, player, line, topic):
topic = topic.lower().strip()
try:
helpFile = self.helpContentPath.child(topic).open()
except (OSError, IOError, filepath.InsecurePath):
player.send("No help available on ", topic, ".", "\n")
else:
player.send(helpFile.read(), '\n')