Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #44 from Borda/fix-prints
Browse files Browse the repository at this point in the history
fix prints for py3
  • Loading branch information
jcoffland committed Mar 12, 2020
2 parents 98d6ba2 + 346c2cb commit eafc041
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 81 deletions.
9 changes: 5 additions & 4 deletions FAHControl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ if options.exit:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(single_app_addr)
sock.send('EXIT')
if sock.recv(1024).strip() == 'OK': print 'Ok'
except Exception, e: pass
if sock.recv(1024).strip() == 'OK': print ('Ok')
except Exception as e:
pass

sys.exit(0)

Expand All @@ -77,5 +78,5 @@ else:

try:
app.run()
except Exception, e:
print e
except Exception as e:
print (e)
30 changes: 17 additions & 13 deletions ez_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
This file can also be run as a script to install or upgrade setuptools.
"""
from __future__ import print_function

import sys
DEFAULT_VERSION = "0.6c11"
DEFAULT_URL = "http:https://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3]
Expand Down Expand Up @@ -63,8 +65,10 @@
}

import sys, os
try: from hashlib import md5
except ImportError: from md5 import md5
try:
from hashlib import md5
except ImportError:
from md5 import md5

def _validate_md5(egg_name, data):
if egg_name in md5_data:
Expand Down Expand Up @@ -103,14 +107,14 @@ def do_download():
return do_download()
try:
pkg_resources.require("setuptools>="+version); return
except pkg_resources.VersionConflict, e:
except pkg_resources.VersionConflict as e:
if was_imported:
print >>sys.stderr, (
print (
"The required version of setuptools (>=%s) is not available, and\n"
"can't be installed while this script is running. Please install\n"
" can't be installed while this script is running. Please install\n"
" a more recent version first, using 'easy_install -U setuptools'."
"\n\n(Currently using %r)"
) % (version, e.args[0])
% (version, e.args[0]), file=sys.stderr)
sys.exit(2)
else:
del pkg_resources, sys.modules['pkg_resources'] # reload ok
Expand Down Expand Up @@ -216,10 +220,10 @@ def main(argv, version=DEFAULT_VERSION):
os.unlink(egg)
else:
if setuptools.__version__ == '0.0.1':
print >>sys.stderr, (
"You have an obsolete version of setuptools installed. Please\n"
"remove it from your system entirely before rerunning this script."
)
print (
"You have an obsolete version of setuptools installed. Please\n"
" remove it from your system entirely before rerunning this script.",
file=sys.stderr)
sys.exit(2)

req = "setuptools>="+version
Expand All @@ -238,8 +242,8 @@ def main(argv, version=DEFAULT_VERSION):
from setuptools.command.easy_install import main
main(argv)
else:
print "Setuptools version",version,"or greater has been installed."
print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
print ("Setuptools version %s or greater has been installed." % version)
print ('(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)')

def update_md5(filenames):
"""Update our built-in md5 registry"""
Expand All @@ -262,7 +266,7 @@ def update_md5(filenames):

match = re.search("\nmd5_data = {\n([^}]+)}", src)
if not match:
print >>sys.stderr, "Internal error!"
print ("Internal error!", file=sys.stderr)
sys.exit(2)

src = src[:match.start(1)] + repl + src[match.end(1):]
Expand Down
16 changes: 9 additions & 7 deletions fah/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ def process_error(self, app, data):
self.error_messages.add(msg)
app.error(msg)

else: print 'ERROR:', msg
else:
print ('ERROR: %s' % msg)

app.set_status(msg)

Expand All @@ -323,7 +324,8 @@ def process_configured(self, app, configured):


def process_message(self, app, type, data):
if debug: print 'message:', type, data
if debug:
print ('message: %s %s' % (type, data))

if type == 'heartbeat': return
if type == 'ppd': self.process_ppd(app, data)
Expand All @@ -350,13 +352,13 @@ def update(self, app):
for version, type, data in self.conn.messages:
try:
self.process_message(app, type, data)
except Exception, e:
except Exception as e:
traceback.print_exc()

self.conn.messages = []

except Exception, e:
print e
except Exception as e:
print (e)

# If client status has changed update UI
newStatus = self.get_status()
Expand Down Expand Up @@ -395,7 +397,7 @@ def close(self):
self.conn.queue_command('quit')
self.conn.write_some()

except Exception, e:
print e
except Exception as e:
print (e)

self.conn.close()
6 changes: 3 additions & 3 deletions fah/ClientConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def update_options(self, app):
set_widget_str_value(widget, self.options[name])

except: # Don't let one bad widget kill everything
print 'WARNING: failed to set widget "%s"' % name
print ('WARNING: failed to set widget "%s"' % name)

# Setup passkey and password entries
app.passkey_validator.set_good()
Expand Down Expand Up @@ -614,8 +614,8 @@ def check_option(model, path, iter, data):
if value is None: options[name + '!'] = None
else: options[name] = value

except Exception, e: # Don't let one bad widget kill everything
print 'WARNING: failed to save widget "%s": %s' % (name, e)
except Exception as e: # Don't let one bad widget kill everything
print ('WARNING: failed to save widget "%s": %s' % (name, e))

# Removed options
for name in self.options:
Expand Down
34 changes: 16 additions & 18 deletions fah/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def open(self):
if err != 0 and not err in [
errno.EINPROGRESS, errno.EWOULDBLOCK, WSAEWOULDBLOCK]:
self.fail_reason = 'connect'
raise Exception, 'Connection failed: ' + errno.errorcode[err]
raise Exception('Connection failed: ' + errno.errorcode[err])

if self.password: self.queue_command('auth "%s"' % self.password)
map(self.queue_command, self.init_commands)
Expand All @@ -124,14 +124,14 @@ def close(self):


def connection_lost(self):
print 'Connection lost'
print ('Connection lost')
self.close()
self.fail_reason = 'closed'
raise Exception, 'Lost connection'
raise Exception('Lost connection')


def connection_error(self, err, msg):
print 'Connection Error: %d: %s' % (err, msg)
print ('Connection Error: %d: %s' % (err, msg))
self.close()
if err == errno.ECONNREFUSED: self.fail_reason = 'refused'
elif err in [errno.ETIMEDOUT, errno.ENETDOWN, errno.ENETUNREACH]:
Expand All @@ -153,7 +153,7 @@ def read_some(self):
self.connection_lost()
return 0

except socket.error, (err, msg):
except socket.error as (err, msg):
# Error codes for nothing to read
if err not in [errno.EAGAIN, errno.EWOULDBLOCK, WSAEWOULDBLOCK]:
if bytesRead: return bytesRead
Expand All @@ -178,7 +178,7 @@ def write_some(self):
self.connection_lost()
return 0

except socket.error, (err, msg):
except socket.error as (err, msg):
# Error codes for write buffer full
if err not in [errno.EAGAIN, errno.EWOULDBLOCK, WSAEWOULDBLOCK]:
if bytesWritten: return bytesWritten
Expand All @@ -189,7 +189,7 @@ def write_some(self):


def queue_command(self, command):
if debug: print 'command: ' + command
if debug: print ('command: ' + command)
self.writeBuf += command + '\n'


Expand All @@ -199,9 +199,9 @@ def parse_message(self, version, type, data):
#if debug: print 'MSG:', type, msg
self.messages.append((version, type, msg))
self.last_message = time.time()
except Exception, e:
print 'ERROR parsing PyON message: %s: %s' % (
str(e), data.encode('string_escape'))
except Exception as e:
print ('ERROR parsing PyON message: %s: %s'
% (str(e), data.encode('string_escape')))


def parse(self):
Expand All @@ -214,8 +214,7 @@ def parse(self):

if len(tokens) < 3:
self.readBuf = self.readBuf[eol:]
raise Exception, 'Invalid PyON line: ' + \
line.encode('string_escape')
raise Exception('Invalid PyON line: ' + line.encode('string_escape'))

version = int(tokens[1])
type = tokens[2]
Expand Down Expand Up @@ -248,21 +247,20 @@ def update(self):
while self.parse(): continue

# Handle special case for OSX disconnect
except socket.error, e:
except socket.error as e:
if sys.platform == 'darwin' and e.errno == errno.EPIPE:
self.fail_reason = 'refused'
self.close()

else: raise

except Exception, e:
print 'ERROR on connection to %s:%d: %s' % (
self.address, self.port, e)
except Exception as e:
print ('ERROR on connection to %s:%d: %s' % (self.address, self.port, e))

# Timeout connection
if self.connected and self.last_message and \
self.last_message + 10 < time.time():
print 'Connection timed out'
print ('Connection timed out')
self.close()


Expand All @@ -277,7 +275,7 @@ def update(self):
conn.update()

for version, type, data in conn.messages:
print 'PyON %d %s:\n' % (version, type), data
print ('PyON %d %s:\n' % (version, type), data)
conn.messages = []

time.sleep(0.1)
Loading

0 comments on commit eafc041

Please sign in to comment.