Modernize Python 2 code to get ready for Python 3

This commit is contained in:
cclauss
2018-02-08 16:39:06 +01:00
parent e982f6ed06
commit e18838a4b7
16 changed files with 28 additions and 29 deletions

View File

@@ -89,7 +89,7 @@ options = vars(options)
if options['preset']:
print ' Using preset data numbers set ' + str(options['preset'])
print(' Using preset data numbers set ' + str(options['preset']))
# Read the numbers of resources from presets file, if provided
presets_filename = os.path.abspath(os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'presets.tsv'))

View File

@@ -183,7 +183,7 @@ def listen():
def _consume(queue):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('0.0.0.0', 6899))
print 'listening for rdb notifications on :6899...'
print('listening for rdb notifications on :6899...')
while True:
r, w, x = select.select([sock], [], [])
for i in r:
@@ -201,13 +201,13 @@ def listen():
if port == 'q':
break
port = int(port)
print 'opening telnet session at localhost:%d...' % port
print('opening telnet session at localhost:%d...' % port)
telnet(port)
print 'listening for rdb notifications on :6899...'
print('listening for rdb notifications on :6899...')
except Empty:
pass
except KeyboardInterrupt:
print 'got Ctrl-C'
print('got Ctrl-C')
queue.put('q')
@@ -218,18 +218,18 @@ def telnet(port):
try:
s.connect(('0.0.0.0', port))
except Exception:
print 'unable to connect'
print('unable to connect')
return
print 'connected to 0.0.0.0:%d' % port
print('connected to 0.0.0.0:%d' % port)
while True:
socket_list = [sys.stdin, s]
r, w, e = select.select(socket_list , [], [])
r, w, e = select.select(socket_list, [], [])
for sock in r:
if sock == s:
data = sock.recv(4096)
if not data:
print 'connection closed'
print('connection closed')
return
else:
sys.stdout.write(data)