Instead of checking the raw version, use the six.PY2 and six.PY3 helpers
to determine if Python 2 or Python 3 are in use.
In one case, the check was to determine if the Python version was >=
2.6. We now only support >= 2.7, so this check would always be true.
Signed-off-by: Russell Bryant <russell@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
Acked-by: Miguel Angel Ajo <majopela@redhat.com>
import os.path
import random
import socket
-import sys
import six
from six.moves import range
sock.bind(bind_path)
try:
- if sys.hexversion >= 0x02060000:
- os.fchmod(sock.fileno(), 0o700)
- else:
- os.chmod("/dev/fd/%d" % sock.fileno(), 0o700)
+ os.fchmod(sock.fileno(), 0o700)
except OSError as e:
pass
if connect_path is not None:
bytes_written = 0
if len(buf) == 0:
return 0, 0
- if sys.version_info[0] >= 3 and not isinstance(buf, six.binary_type):
+ if six.PY3 and not isinstance(buf, six.binary_type):
buf = six.binary_type(buf, 'utf-8')
while True:
try:
import errno
import os
import socket
-import sys
import six
try:
# Python 3 has separate types for strings and bytes. We must have
# bytes here.
- if (sys.version_info[0] >= 3
- and not isinstance(buf, six.binary_type)):
+ if six.PY3 and not isinstance(buf, six.binary_type):
buf = six.binary_type(buf, 'utf-8')
return self.socket.send(buf)
except socket.error as e:
argv0 = argv[0]
# When this is used with Python 3, the program produces no output.
- if sys.version_info[0] == 2:
+ if six.PY2:
# Make stdout and stderr UTF-8, even if they are redirected to a file.
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
sys.stderr = codecs.getwriter("utf-8")(sys.stderr)