本文整理匯總了Python中fs.memoryfs.MemoryFS.exists方法的典型用法代碼示例。如果您正苦於以下問題:Python MemoryFS.exists方法的具體用法?Python MemoryFS.exists怎麽用?Python MemoryFS.exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類fs.memoryfs.MemoryFS
的用法示例。
在下文中一共展示了MemoryFS.exists方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_safety_wrapper
# 需要導入模塊: from fs.memoryfs import MemoryFS [as 別名]
# 或者: from fs.memoryfs.MemoryFS import exists [as 別名]
def test_safety_wrapper(self):
rawfs = MemoryFS()
safefs = dokan.Win32SafetyFS(rawfs)
rawfs.setcontents("autoRun.inf", b("evilcodeevilcode"))
self.assertTrue(safefs.exists("_autoRun.inf"))
self.assertTrue("autoRun.inf" not in safefs.listdir("/"))
safefs.setcontents("file:stream",b("test"))
self.assertFalse(rawfs.exists("file:stream"))
self.assertTrue(rawfs.exists("file__colon__stream"))
self.assertTrue("file:stream" in safefs.listdir("/"))
示例2: test_movedir_root
# 需要導入模塊: from fs.memoryfs import MemoryFS [as 別名]
# 或者: from fs.memoryfs.MemoryFS import exists [as 別名]
def test_movedir_root(self):
"""Test movedir to root dir"""
fs1 = MemoryFS()
fs2 = MemoryFS()
fs1sub = fs1.makeopendir("from")
self._make_fs(fs1sub)
utils.movedir((fs1, "from"), fs2)
self.assert_(not fs1.exists("from"))
self._check_fs(fs2)
fs1 = TempFS()
fs2 = TempFS()
fs1sub = fs1.makeopendir("from")
self._make_fs(fs1sub)
utils.movedir((fs1, "from"), fs2)
self.assert_(not fs1.exists("from"))
self._check_fs(fs2)
示例3: test_movedir_indir
# 需要導入模塊: from fs.memoryfs import MemoryFS [as 別名]
# 或者: from fs.memoryfs.MemoryFS import exists [as 別名]
def test_movedir_indir(self):
"""Test movedir in a directory"""
fs1 = MemoryFS()
fs2 = MemoryFS()
fs1sub = fs1.makeopendir("from")
self._make_fs(fs1sub)
utils.movedir((fs1, "from"), (fs2, "copy"))
self.assert_(not fs1.exists("from"))
self._check_fs(fs2.opendir("copy"))
fs1 = TempFS()
fs2 = TempFS()
fs1sub = fs1.makeopendir("from")
self._make_fs(fs1sub)
utils.movedir((fs1, "from"), (fs2, "copy"))
self.assert_(not fs1.exists("from"))
self._check_fs(fs2.opendir("copy"))
示例4: VirtualFilesystem
# 需要導入模塊: from fs.memoryfs import MemoryFS [as 別名]
# 或者: from fs.memoryfs.MemoryFS import exists [as 別名]
class VirtualFilesystem(AbstractedFS):
"""Represents a virtual filesystem (currently only memory and s3 are supported)
"""
def __init__(self, root, cmd_channel):
AbstractedFS.__init__(self, root, cmd_channel)
self.cwd = root
self.type = cmd_channel.type
self.s3_bucket = cmd_channel.s3_bucket
self.aws_access_key = cmd_channel.aws_access_key
self.aws_secret_key = cmd_channel.aws_secret_key
self.seperator = cmd_channel.seperator
self.thread_synchronize = cmd_channel.thread_synchronize
self.key_sync_timeout = cmd_channel.key_sync_timeout
if not self.cmd_channel.fs_obj:
if self.type == "memory":
self.fs_obj = MemoryFS()
elif self.type == "s3":
self.fs_obj = S3FS(bucket=self.bucket, prefix=self.prefix, aws_access_key=self.aws_access_key, aws_secret_key=self.aws_secret_key, separator=self.seperator, thread_synchronize=self.thread_synchronize, key_sync_timeout=self.key_sync_timeout)
self.cmd_channel.fs_obj = self.fs_obj
else:
self.fs_obj = self.cmd_channel.fs_obj
def ftp2fs(self, ftppath):
return self.ftpnorm(ftppath)
def fs2ftp(self, fspath):
return fspath
def validpath(self, path):
# validpath was used to check symlinks escaping user home
# directory; this is no longer necessary.
return True
def open(self, filename, mode):
f = self.fs_obj.open(filename, mode)
f.name=filename
return f
def mkdir(self, path):
return self.fs_obj.makedir(path)
def chdir(self, path):
return self.fs_obj.opendir(path)
def listdir(self,path):
return self.fs_obj.listdir(path)
def rmdir(self, path):
return self.fs_obj.removedir(path)
def remove(self, path):
return self.fs_obj.remove(path)
def rename(self, src, dst):
return self.fs_obj.rename(src, dst)
def chmod(self, path, mode):
return True
def readlink(self, path):
return self.ftp2fs(path)
def isfile(self, path):
return self.fs_obj.isfile(path)
def islink(self, path):
return False
def getsize(self, path):
return self.fs_obj.getsize(path)
def getmtime(self, path):
return self.fs_obj.getinfo(path)['modified_time']
def realpath(self, path):
return path
def lexists(self, path):
return self.fs_obj.exists(path)
def mkstemp(self, suffix='', prefix='', mode='wb'):
from tempfile import _RandomNameSequence as RandomName
name = RandomName()
if suffix != '':
suffix = 'tmp'
fname = suffix + name.next()
return self.fs_obj.open(fname,mode)
示例5: BigFS
# 需要導入模塊: from fs.memoryfs import MemoryFS [as 別名]
# 或者: from fs.memoryfs.MemoryFS import exists [as 別名]
#.........這裏部分代碼省略.........
return True, unpack(">I", g.read(4))[0]
else:
# use only 3 bytes
return True, unpack(">I", "\0" + g.read(3))[0]
return False, size
def _add_resource(self, path):
if path.endswith('/'):
path = path[:-1]
if path:
self._path_fs.makedir(path, recursive=True, allow_recreate=True)
else:
dirpath, filename = pathsplit(path)
if dirpath:
self._path_fs.makedir(dirpath, recursive=True, allow_recreate=True)
f = self._path_fs.open(path, 'w')
f.close()
def close(self):
"""Finalizes the zip file so that it can be read.
No further operations will work after this method is called."""
if hasattr(self, 'bf') and self.bf:
self.bf.close()
self.bf = _ExceptionProxy()
@synchronize
def open(self, path, mode="r", **kwargs):
path = normpath(relpath(path))
if 'r' in mode:
if self.file_mode not in 'ra':
raise OperationFailedError("open file", path=path, msg="Big file must be opened for reading ('r') or appending ('a')")
try:
return self.entries[path].getfile(self.bf)
except KeyError:
raise ResourceNotFoundError(path)
if 'w' in mode:
raise OperationFailedError("open file", path=path, msg="Big file cannot be edited ATM")
raise ValueError("Mode must contain be 'r' or 'w'")
@synchronize
def getcontents(self, path):
if not self.exists(path):
raise ResourceNotFoundError(path)
path = normpath(path)
try:
contents = self.entries[path].getcontents(self.bf)
except KeyError:
raise ResourceNotFoundError(path)
except RuntimeError:
raise OperationFailedError("read file", path=path, msg="Big file must be oppened with 'r' or 'a' to read")
return contents
def desc(self, path):
if self.isdir(path):
return "Dir in big file: %s" % self.big_path
else:
return "File in big file: %s" % self.big_path
def isdir(self, path):
return self._path_fs.isdir(path)
def isfile(self, path):
return self._path_fs.isfile(path)
def exists(self, path):
return self._path_fs.exists(path)
@synchronize
def makedir(self, dirname, recursive=False, allow_recreate=False):
dirname = normpath(dirname)
if self.file_mode not in "wa":
raise OperationFailedError("create directory", path=dirname, msg="Big file must be opened for writing ('w') or appending ('a')")
if not dirname.endswith('/'):
dirname += '/'
self._add_resource(dirname)
def listdir(self, path="/", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
return self._path_fs.listdir(path, wildcard, full, absolute, dirs_only, files_only)
@synchronize
def getinfo(self, path):
if not self.exists(path):
raise ResourceNotFoundError(path)
path = normpath(path).lstrip('/')
info = {'size': 0}
if path in self.entries:
be = self.entries[path]
info['size'] = be.realSize
info['file_size'] = be.realSize
info['stored_size'] = be.storedSize
info['is_compressed'] = be.isCompressed
info['offset'] = be.offset
info['internal_filename'] = be.filename
info['filename'] = path
return info