From 3a4ca74e0a16d07296fc51391d466819b2ca3dad Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Sat, 11 Sep 2004 20:50:39 +0000 Subject: [PATCH] [project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-84] add sftp.normalize kevin c. dorff pointed out that it would be nice to expose a way to determine the server's "current working directory", so this new method (normalize) directly maps to REALPATH. --- paramiko/sftp_client.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index c72d490..f9b8e69 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -310,9 +310,9 @@ class SFTPClient (BaseSFTP): relative pathname. @param path: path of the symbolic link file. - @type path: string + @type path: str @return: target path. - @rtype: string + @rtype: str """ t, msg = self._request(CMD_READLINK, path) if t != CMD_NAME: @@ -324,6 +324,26 @@ class SFTPClient (BaseSFTP): raise SFTPError('Readlink returned %d results' % count) return msg.get_string() + def normalize(self, path): + """ + Return the normalized path (on the server) of a given path. This + can be used to quickly resolve symbolic links or determine what the + server is considering to be the "current folder" (by passing C{'.'} + as C{path}). + + @param path: path to be normalized. + @type path: str + @return: normalized form of the given path. + @rtype: str + """ + t, msg = self._request(CMD_REALPATH, path) + if t != CMD_NAME: + raise SFTPError('Expected name response') + count = msg.get_int() + if count != 1: + raise SFTPError('Realpath returned %d results' % count) + return msg.get_string() + ### internals...