From 3a9119d78a8745e4e45bea0881bfae3deb2adab3 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 4 Mar 2013 08:17:22 -0500 Subject: [PATCH 1/5] Delint test_sftp (remove unused imports and unused variables, remove excess whitespace, move imports to top, remove semicolon terminator) --HG-- extra : source : 01df712a396de5fa7e1c0cc265411fdb2bbc5f41 --- tests/test_sftp.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tests/test_sftp.py b/tests/test_sftp.py index f95da69..dfd673a 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -26,13 +26,10 @@ do test file operations in (so no existing files will be harmed). from __future__ import with_statement from binascii import hexlify -import logging import os -import random -import struct +import warnings import sys import threading -import time import unittest import paramiko @@ -227,7 +224,7 @@ class SFTPTest (unittest.TestCase): """ f = sftp.open(FOLDER + '/first.txt', 'w') try: - f.write('content!\n'); + f.write('content!\n') f.close() sftp.rename(FOLDER + '/first.txt', FOLDER + '/second.txt') try: @@ -438,7 +435,7 @@ class SFTPTest (unittest.TestCase): self.assertEqual(sftp.readlink(FOLDER + '/link.txt'), 'original.txt') f = sftp.open(FOLDER + '/link.txt', 'r') - self.assertEqual(f.readlines(), [ 'original\n' ]) + self.assertEqual(f.readlines(), ['original\n']) f.close() cwd = sftp.normalize('.') @@ -566,7 +563,6 @@ class SFTPTest (unittest.TestCase): """ verify that get/put work. """ - import os, warnings warnings.filterwarnings('ignore', 'tempnam.*') localname = os.tempnam() @@ -631,7 +627,7 @@ class SFTPTest (unittest.TestCase): try: f = sftp.open(FOLDER + '/unusual.txt', 'wx') self.fail('expected exception') - except IOError, x: + except IOError: pass finally: sftp.unlink(FOLDER + '/unusual.txt') @@ -671,12 +667,12 @@ class SFTPTest (unittest.TestCase): f.close() try: f = sftp.open(FOLDER + '/zero', 'r') - data = f.readv([(0, 12)]) + f.readv([(0, 12)]) f.close() f = sftp.open(FOLDER + '/zero', 'r') f.prefetch() - data = f.read(100) + f.read(100) f.close() finally: sftp.unlink(FOLDER + '/zero') @@ -685,7 +681,6 @@ class SFTPTest (unittest.TestCase): """ verify that get/put work without confirmation. """ - import os, warnings warnings.filterwarnings('ignore', 'tempnam.*') localname = os.tempnam() @@ -697,7 +692,7 @@ class SFTPTest (unittest.TestCase): def progress_callback(x, y): saved_progress.append((x, y)) res = sftp.put(localname, FOLDER + '/bunny.txt', progress_callback, False) - + self.assertEquals(SFTPAttributes().attr, res.attr) f = sftp.open(FOLDER + '/bunny.txt', 'r') @@ -729,4 +724,3 @@ class SFTPTest (unittest.TestCase): f.close() finally: sftp.remove(FOLDER + '/append.txt') - From a3fe422198b1faf75afaf8e2ccfc752dcba64c82 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 4 Mar 2013 08:45:00 -0500 Subject: [PATCH 2/5] Adding test capturing desired behavior and demonstrating issue #142. --- tests/test_sftp.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_sftp.py b/tests/test_sftp.py index dfd673a..b1697ea 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -31,6 +31,7 @@ import warnings import sys import threading import unittest +import StringIO import paramiko from stub_sftp import StubServer, StubSFTPServer @@ -724,3 +725,16 @@ class SFTPTest (unittest.TestCase): f.close() finally: sftp.remove(FOLDER + '/append.txt') + + def test_putfo_empty_file(self): + """ + Send an empty file and confirm it is sent. + """ + target = FOLDER + '/empty file.txt' + stream = StringIO.StringIO() + try: + attrs = sftp.putfo(stream, target) + # the returned attributes should not be null + self.assertNotEqual(attrs, None) + finally: + sftp.remove(target) From 3cd7f585d01afe7eb97374e26a9f72197fc77a42 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 4 Mar 2013 08:46:39 -0500 Subject: [PATCH 3/5] Remove 'file_size' check from tests. The docstring indicates this parameter is to be passed to the callback, and there's no reason to think this parameter is relevant in affecting whether a useful stat object has been passed (especially when the 'confirm' parameter is explicitly supplied for that decision. This fixes #142. --- paramiko/sftp_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index 7df643f..17ea493 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -575,7 +575,7 @@ class SFTPClient (BaseSFTP): break finally: fr.close() - if confirm and file_size: + if confirm: s = self.stat(remotepath) if s.st_size != size: raise IOError('size mismatch in put! %d != %d' % (s.st_size, size)) From abe009b14980d8547b111f07ca9ca782c0bb47a6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 4 Mar 2013 08:49:47 -0500 Subject: [PATCH 4/5] Update NEWS per #142 --- NEWS | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index f34a876..363b838 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,12 @@ Issues noted as "Fabric #NN" can be found at https://github.com/fabric/fabric/. Releases ======== +v1.10.1 (...) +------------- + +* #142: (Fabric #811) SFTP put of empty file will still return the attributes + of the put file. Thanks to Jason R. Coombs for the patch. + v1.10.0 (1st Mar 2013) -------------------- @@ -325,7 +331,7 @@ v1.5 (paras) 02oct05 separation * demo scripts fixed to have a better chance of loading the host keys correctly on windows/cygwin - + v1.4 (oddish) 17jul05 --------------------- * added SSH-agent support (for posix) from john rochester From 17ba0d5b61fe0c87b6b7b657d1b74176931f890f Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Fri, 5 Apr 2013 11:51:19 -0700 Subject: [PATCH 5/5] Dumb format tweak to NEWS --- NEWS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 363b838..f135005 100644 --- a/NEWS +++ b/NEWS @@ -12,8 +12,8 @@ Issues noted as "Fabric #NN" can be found at https://github.com/fabric/fabric/. Releases ======== -v1.10.1 (...) -------------- +v1.10.1 (DD MM YYYY) +-------------------- * #142: (Fabric #811) SFTP put of empty file will still return the attributes of the put file. Thanks to Jason R. Coombs for the patch.