diff options
author | Martin Packman <gzlist@googlemail.com> | 2017-06-01 01:08:02 +0100 |
---|---|---|
committer | Martin Packman <gzlist@googlemail.com> | 2017-06-01 01:08:02 +0100 |
commit | e25e1aacf511be00ee32636737f5574b84f50e4e (patch) | |
tree | 1e7b17e14a1ecec2735138f74efb31dfb9794cb9 | |
parent | 102ed5d1bf3cae902953a3e784fb7d08c41817cc (diff) | |
download | paramiko-e25e1aacf511be00ee32636737f5574b84f50e4e.tar.gz |
Tweak comments as suggested in review
Thanks to bitprophet and ploxiln.
-rw-r--r-- | paramiko/common.py | 5 | ||||
-rw-r--r-- | paramiko/file.py | 3 | ||||
-rw-r--r-- | paramiko/sftp_client.py | 2 |
3 files changed, 6 insertions, 4 deletions
diff --git a/paramiko/common.py b/paramiko/common.py index f3ff75d6..8a5a24ef 100644 --- a/paramiko/common.py +++ b/paramiko/common.py @@ -160,15 +160,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 bdaa7ed8..e847308a 100644 --- a/paramiko/file.py +++ b/paramiko/file.py @@ -373,8 +373,7 @@ class BufferedFile (ClosingContextManager): :param str/bytes data: 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 06637ca2..160c33fe 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -743,6 +743,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 |