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

[python 3] Use bytes literals where appropriate #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FAHControl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def set_proc_name(name):
libc.prctl(15, byref(buff), 0, 0, 0)


if sys.platform.startswith('linux'): set_proc_name('FAHControl')
if sys.platform.startswith('linux'): set_proc_name(b'FAHControl')

# If present, remove the Launch Services -psn_xxx_xxx argument
if len(sys.argv) > 1 and sys.argv[1][:4] == '-psn':
Expand Down
38 changes: 19 additions & 19 deletions fah/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ def __init__(self, app, name, address, port, password):

# Init commands
self.inactive_cmds = [
'updates clear',
'updates add 0 4 $heartbeat',
'updates add 1 5 $ppd',
b'updates clear',
b'updates add 0 4 $heartbeat',
b'updates add 1 5 $ppd',
]

self.active_cmds = self.inactive_cmds + [
'updates add 2 1 $(options %s *)' % ' '.join(self.option_names),
'updates add 3 4 $queue-info',
'updates add 4 1 $slot-info',
'info',
'log-updates start',
'configured',
('updates add 2 1 $(options %s *)' % ' '.join(self.option_names)).encode('ascii'),
b'updates add 3 4 $queue-info',
b'updates add 4 1 $slot-info',
b'info',
b'log-updates start',
b'configured',
]

# Objects
Expand Down Expand Up @@ -327,19 +327,19 @@ def process_message(self, app, type, data):
if debug:
print ('message: %s %s' % (type, data))

if type == 'heartbeat': return
if type == 'ppd': self.process_ppd(app, data)
if type == b'heartbeat': return
if type == b'ppd': self.process_ppd(app, data)

if not self.selected: return

if type == 'options': self.process_options(app, data)
elif type == 'info': self.process_info(app, data)
elif type == 'slots': self.process_slots(app, data)
elif type == 'units': self.process_units(app, data)
elif type == 'log-restart': self.process_log_restart(app, data)
elif type == 'log-update': self.process_log_update(app, data)
elif type == 'error': self.process_error(app, data)
elif type == 'configured': self.process_configured(app, data)
if type == b'options': self.process_options(app, data)
elif type == b'info': self.process_info(app, data)
elif type == b'slots': self.process_slots(app, data)
elif type == b'units': self.process_units(app, data)
elif type == b'log-restart': self.process_log_restart(app, data)
elif type == b'log-update': self.process_log_update(app, data)
elif type == b'error': self.process_error(app, data)
elif type == b'configured': self.process_configured(app, data)
# Ignore other message types


Expand Down
3 changes: 2 additions & 1 deletion fah/ClientConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ def log_add_lines(self, app, lines):

if len(filtered):
text = '\n'.join(filtered)
text = text.decode('utf-8', 'ignore')
if isinstance(text, bytes):
text = text.decode('utf-8', 'ignore')
app.log.insert(app.log.get_end_iter(), text + '\n')
self.scroll_log_to_end(app)

Expand Down
14 changes: 8 additions & 6 deletions fah/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def can_read(self):
def reset(self):
self.close()
self.messages = []
self.readBuf = ''
self.writeBuf = ''
self.readBuf = b''
self.writeBuf = b''
self.fail_reason = None
self.last_message = 0
self.last_connect = 0
Expand Down Expand Up @@ -189,8 +189,10 @@ def write_some(self):


def queue_command(self, command):
if not isinstance(command, bytes):
command = command.encode()
if debug: print ('command: ' + command)
self.writeBuf += command + '\n'
self.writeBuf += command + b'\n'


def parse_message(self, version, type, data):
Expand All @@ -205,9 +207,9 @@ def parse_message(self, version, type, data):


def parse(self):
start = self.readBuf.find('\nPyON ')
start = self.readBuf.find(b'\nPyON ')
if start != -1:
eol = self.readBuf.find('\n', start + 1)
eol = self.readBuf.find(b'\n', start + 1)
if eol != -1:
line = self.readBuf[start + 1: eol]
tokens = line.split(None, 2)
Expand All @@ -219,7 +221,7 @@ def parse(self):
version = int(tokens[1])
type = tokens[2]

end = self.readBuf.find('\n---\n', start)
end = self.readBuf.find(b'\n---\n', start)
if end != -1:
data = self.readBuf[eol + 1: end]
self.parse_message(version, type, data)
Expand Down
Loading