本文整理匯總了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')