summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2014-04-16 15:09:30 -0400
committerJeff Forcier <jeff@bitprophet.org>2014-04-16 15:09:30 -0400
commita0b2ae293ffedcad45883e8a4d04fc067f919d15 (patch)
tree1c949812c158c323232affa7c3f41adc5b65d49d
parentf22fe4b6009c349ae87df671fa9d410a5a6f684c (diff)
parent6e9abc39cfff94e0dc36ebe6b939caa8d2eafee0 (diff)
Merge branch '1.11' into 1.12
-rw-r--r--paramiko/sftp_client.py6
-rw-r--r--sites/www/changelog.rst2
-rwxr-xr-xtests/test_sftp.py23
3 files changed, 29 insertions, 2 deletions
diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py
index 13e830c4..907ec413 100644
--- a/paramiko/sftp_client.py
+++ b/paramiko/sftp_client.py
@@ -105,9 +105,11 @@ class SFTPClient(BaseSFTP):
def _log(self, level, msg, *args):
if isinstance(msg, list):
for m in msg:
- super(SFTPClient, self)._log(level, "[chan %s] " + m, *([ self.sock.get_name() ] + list(args)))
+ self._log(level, m, *args)
else:
- super(SFTPClient, self)._log(level, "[chan %s] " + msg, *([ self.sock.get_name() ] + list(args)))
+ # escape '%' in msg (they could come from file or directory names) before logging
+ msg = msg.replace('%','%%')
+ super(SFTPClient, self)._log(level, "[chan %s] " + msg, *([self.sock.get_name()] + list(args)))
def close(self):
"""
diff --git a/sites/www/changelog.rst b/sites/www/changelog.rst
index acf20c59..5f90614b 100644
--- a/sites/www/changelog.rst
+++ b/sites/www/changelog.rst
@@ -2,6 +2,8 @@
Changelog
=========
+* :bug:`-` Fix logging error in sftp_client for filenames containing the '%'
+ character. Thanks to Antoine Brenner.
* :support:`284` Add Python language trove identifiers to ``setup.py``. Thanks
to Alex Gaynor for catch & patch.
* :bug:`235` Improve string type testing in a handful of spots (e.g. ``s/if
diff --git a/tests/test_sftp.py b/tests/test_sftp.py
index cc512c18..a136f823 100755
--- a/tests/test_sftp.py
+++ b/tests/test_sftp.py
@@ -36,6 +36,7 @@ import StringIO
import paramiko
from stub_sftp import StubServer, StubSFTPServer
from loop import LoopSocket
+import paramiko.util
from paramiko.sftp_attr import SFTPAttributes
ARTICLE = '''
@@ -738,3 +739,25 @@ class SFTPTest (unittest.TestCase):
self.assertNotEqual(attrs, None)
finally:
sftp.remove(target)
+
+
+ def test_N_file_with_percent(self):
+ """
+ verify that we can create a file with a '%' in the filename.
+ ( it needs to be properly escaped by _log() )
+ """
+ self.assertTrue( paramiko.util.get_logger("paramiko").handlers, "This unit test requires logging to be enabled" )
+ f = sftp.open(FOLDER + '/test%file', 'w')
+ try:
+ self.assertEqual(f.stat().st_size, 0)
+ finally:
+ f.close()
+ sftp.remove(FOLDER + '/test%file')
+
+
+if __name__ == '__main__':
+ SFTPTest.init_loopback()
+ # logging is required by test_N_file_with_percent
+ paramiko.util.log_to_file('test_sftp.log')
+ from unittest import main
+ main()