Check if we are dealing with a Unicode string that needs encoding for both Python 2 & 3.
Also, do the encoding the same way for Python 2 & 3 and avoid using negation to make the code simpler. v1 -> v2: Rewrite the check for Unicode string to avoid flake8 warnings. Signed-off-by: Jakub Sitnicki <[email protected]> --- Ben, Thanks for pointing out the flake8 warnings. It was poorly done. This version should read much better, and be free of warnings. -Jakub python/ovs/stream.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/python/ovs/stream.py b/python/ovs/stream.py index 7b15bcd7d..d6c447a97 100644 --- a/python/ovs/stream.py +++ b/python/ovs/stream.py @@ -383,11 +383,8 @@ class Stream(object): elif len(buf) == 0: return 0 - # Python 3 has separate types for strings and bytes. We must have - # bytes here. - if six.PY3 and not isinstance(buf, bytes): - buf = bytes(buf, 'utf-8') - elif six.PY2: + # We must have bytes for sending. + if isinstance(buf, six.text_type): buf = buf.encode('utf-8') if sys.platform == 'win32' and self.socket is None: -- 2.14.3 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
