Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@_setdoc(Path)
def with_suffix(self, suffix, depth=1):
if (suffix and not suffix.startswith('.') or suffix == '.'):
raise ValueError("Invalid suffix %r" % (suffix))
name = self.name
depth = len(self.suffixes) if depth is None else min(
depth, len(self.suffixes))
for i in range(depth):
name, ext = name.rsplit('.', 1)
return self.__class__(self.remote, self.dirname) / (name + suffix)
@_setdoc(Path)
def write(self, data):
with self.open("w") as f:
f.write(data)
@_setdoc(Path)
def read(self, encoding=None, mode='r'):
if encoding and 'b' not in mode:
mode = mode + 'b'
with self.open(mode) as f:
data = f.read()
if encoding:
data = data.decode(encoding)
return data
@_setdoc(BaseRemoteMachine)
def session(self,
isatty=False,
term="vt100",
width=80,
height=24,
new_session=False):
# new_session is ignored for ParamikoMachine
trans = self._client.get_transport()
trans.set_keepalive(self._keep_alive)
chan = trans.open_session()
if isatty:
chan.get_pty(term, width, height)
chan.set_combine_stderr(True)
chan.invoke_shell()
stdin = chan.makefile('wb', -1)
stdout = chan.makefile('rb', -1)
@_setdoc(Path)
def iterdir(self):
if not self.is_dir():
return ()
return (self.join(fn) for fn in self.remote._path_listdir(self))
@_setdoc(Path)
def is_dir(self):
return os.path.isdir(str(self))
@_setdoc(BaseRemoteMachine)
def upload(self, src, dst):
if isinstance(src, RemotePath):
raise TypeError("src of upload cannot be %r" % (src, ))
if isinstance(dst, LocalPath):
raise TypeError("dst of upload cannot be %r" % (dst, ))
if isinstance(dst, RemotePath) and dst.remote != self:
raise TypeError(
"dst %r points to a different remote machine" % (dst, ))
if IS_WIN32:
src = self._translate_drive_letter(src)
dst = self._translate_drive_letter(dst)
self._scp_command(src, "%s:%s" % (self._fqhost, shquote(dst)))
@_setdoc(Path)
def suffix(self):
return os.path.splitext(str(self))[1]
@_setdoc(Path)
def dirname(self):
return LocalPath(os.path.dirname(str(self)))
@_setdoc(Path)
def is_file(self):
return os.path.isfile(str(self))