summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Packman <gzlist@googlemail.com>2017-06-01 01:08:02 +0100
committerJeff Forcier <jeff@bitprophet.org>2017-06-09 13:46:15 -0700
commit8c9df8ba637e222a3e9da6d365d225f9cad81f18 (patch)
tree6d191c77b561f78fb06aae9f909a50b5c67fe2ef
parent17231b9a7c56bf06f1a848fc52554541a09a2eba (diff)
Tweak comments as suggested in review
Thanks to bitprophet and ploxiln.
-rw-r--r--paramiko/common.py5
-rw-r--r--paramiko/file.py3
-rw-r--r--paramiko/sftp_client.py2
3 files changed, 6 insertions, 4 deletions
diff --git a/paramiko/common.py b/paramiko/common.py
index 3b18858b..8ce735d7 100644
--- a/paramiko/common.py
+++ b/paramiko/common.py
@@ -163,15 +163,16 @@ else:
def asbytes(s):
+ """Coerce to bytes if possible or return unchanged."""
if isinstance(s, bytes_types):
return s
if isinstance(s, text_type):
- # GZ 2017-05-25: Accept text and encode as utf-8 for compatibilty only.
+ # Accept text and encode as utf-8 for compatibility only.
return s.encode("utf-8")
asbytes = getattr(s, "asbytes", None)
if asbytes is not None:
return asbytes()
- # May be an object that implements the buffer api, let callers decide
+ # May be an object that implements the buffer api, let callers handle.
return s
diff --git a/paramiko/file.py b/paramiko/file.py
index 35637b8e..a1bdafbe 100644
--- a/paramiko/file.py
+++ b/paramiko/file.py
@@ -392,8 +392,7 @@ class BufferedFile (ClosingContextManager):
:param data: ``str``/``bytes`` data to write
"""
if isinstance(data, text_type):
- # GZ 2017-05-25: Accepting text on a binary stream unconditionally
- # cooercing to utf-8 seems questionable, but compatibility reasons?
+ # Accept text and encode as utf-8 for compatibility only.
data = data.encode('utf-8')
if self._closed:
raise IOError('File is closed')
diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py
index ef04f37a..a1ee6723 100644
--- a/paramiko/sftp_client.py
+++ b/paramiko/sftp_client.py
@@ -761,6 +761,8 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
elif isinstance(item, SFTPAttributes):
item._pack(msg)
else:
+ # For all other types, rely on as_string() to either coerce
+ # to bytes before writing or raise a suitable exception.
msg.add_string(item)
num = self.request_number
self._expecting[num] = fileobj