Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
identifier
mode: str
normally "rb", "wb" or "ab"
"""
if mode in ["rb", "ab", "rb+"]:
if path in self.store:
f = self.store[path]
if mode == "rb":
f.seek(0)
else:
f.seek(0, 2)
return f
else:
raise FileNotFoundError(path)
if mode == "wb":
m = MemoryFile(self, path)
if not self._intrans:
m.commit()
return m
**kwargs
):
if mode in ["rb", "ab", "rb+"]:
if path in self.store:
f = self.store[path]
if mode == "ab":
# position at the end of file
f.seek(0, 2)
else:
# position at the beginning of file
f.seek(0)
return f
else:
raise FileNotFoundError(path)
if mode == "wb":
m = MemoryFile(self, path)
if not self._intrans:
m.commit()
return m
def copy(self, path1, path2, **kwargs):
self.store[path2] = MemoryFile(self, path2, self.store[path1].getbuffer())
def _open(
self,
path,
mode="rb",
block_size=None,
autocommit=True,
cache_options=None,
ref=None,
**kwargs
):
obj = self._path_to_object(path, ref or self.ref)
return MemoryFile(data=obj.data)
block_size=None,
autocommit=True,
cache_options=None,
sha=None,
**kwargs
):
if mode != "rb":
raise NotImplementedError
url = self.rurl.format(
org=self.org, repo=self.repo, path=path, sha=sha or self.root
)
r = requests.get(url)
if r.status_code == 404:
raise FileNotFoundError(path)
r.raise_for_status()
return MemoryFile(None, None, r.content)
def cp_file(self, path1, path2, **kwargs):
if self.isfile(path1):
self.store[path2] = MemoryFile(self, path2, self.store[path1].getbuffer())
elif self.isdir(path1):
if path2 not in self.pseudo_dirs:
self.pseudo_dirs.append(path2)
else:
raise FileNotFoundError