Fix logging error in sftp_client for filenames containing the character.
Bug reported here: http://vlists.pepperfish.net/pipermail/obnam-flarn.net/2013-May/000767.html Antoine Brenner Backported to 1.11 by @bitprophet Conflicts: paramiko/sftp_client.py sites/www/changelog.rst tests/test_sftp.py
This commit is contained in:
parent
dd2e23a23e
commit
6e9abc39cf
|
@ -105,8 +105,10 @@ class SFTPClient(BaseSFTP):
|
||||||
def _log(self, level, msg, *args):
|
def _log(self, level, msg, *args):
|
||||||
if isinstance(msg, list):
|
if isinstance(msg, list):
|
||||||
for m in msg:
|
for m in msg:
|
||||||
super(SFTPClient, self)._log(level, "[chan %s] " + m, *([ self.sock.get_name() ] + list(args)))
|
self._log(level, m, *args)
|
||||||
else:
|
else:
|
||||||
|
# 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)))
|
super(SFTPClient, self)._log(level, "[chan %s] " + msg, *([self.sock.get_name()] + list(args)))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
Changelog
|
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
|
* :support:`284` Add Python language trove identifiers to ``setup.py``. Thanks
|
||||||
to Alex Gaynor for catch & patch.
|
to Alex Gaynor for catch & patch.
|
||||||
* :bug:`235` Improve string type testing in a handful of spots (e.g. ``s/if
|
* :bug:`235` Improve string type testing in a handful of spots (e.g. ``s/if
|
||||||
|
|
|
@ -36,6 +36,7 @@ import StringIO
|
||||||
import paramiko
|
import paramiko
|
||||||
from stub_sftp import StubServer, StubSFTPServer
|
from stub_sftp import StubServer, StubSFTPServer
|
||||||
from loop import LoopSocket
|
from loop import LoopSocket
|
||||||
|
import paramiko.util
|
||||||
from paramiko.sftp_attr import SFTPAttributes
|
from paramiko.sftp_attr import SFTPAttributes
|
||||||
|
|
||||||
ARTICLE = '''
|
ARTICLE = '''
|
||||||
|
@ -738,3 +739,25 @@ class SFTPTest (unittest.TestCase):
|
||||||
self.assertNotEqual(attrs, None)
|
self.assertNotEqual(attrs, None)
|
||||||
finally:
|
finally:
|
||||||
sftp.remove(target)
|
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()
|
||||||
|
|
Loading…
Reference in New Issue