Commit 1021869d authored by JackV's avatar JackV

Python3 corrections

parent d7a9922d
#! /usr/bin/env python2
#! /usr/bin/env python3
from bitsd.main import main
......
......@@ -26,7 +26,7 @@ def send(string):
LOG.error("No Fonera connected! Not sending %r", string)
return
try:
RemoteListener.STREAM.write(string)
RemoteListener.STREAM.write(string.encode('utf-8'))
except StreamClosedError as error:
LOG.error('Could not push message to Fonera! %s', error)
......@@ -107,7 +107,7 @@ class RemoteListener(tornado.tcpserver.TCPServer):
# Meanwhile, go on with commands...
RemoteListener.STREAM.read_until(b'\n', self.handle_command)
command = command.strip('\n')
command = command.strip(b'\n')
if command:
args = command.split(b' ')
......
......@@ -93,6 +93,8 @@ def query_by_attribute(session, model, attribute, value, first=True):
"""Query all instances of `model` having `attribute == value`.
If first is True, only first result will be returned (useful
if attribute is a primary/candidate key)."""
if isinstance(value, bytes):
value = value.decode('utf-8')
query = session.query(model).filter_by(**{attribute: value})
result = query.first() if first else query
return result
......
......@@ -338,6 +338,7 @@ class MessagePageHandler(BaseHandler):
with session_scope() as session:
user = query.get_user(session, username)
print(user)
message = query.log_message(session, user, text)
LOG.info("Broadcasting to clients")
broadcast(message.jsondict())
......
#! /usr/bin/env python2
#! /usr/bin/env python3
#
# Copyright (C) 2013 Stefano Sanfilippo
# Copyright (C) 2013 BITS development team
......@@ -29,6 +29,6 @@ if __name__ == '__main__':
start()
with open('INFO.md', 'r') as info:
infopage = Page('Info', info.read().decode('utf-8'))
infopage = Page('Info', info.read())
with session_scope() as session:
persist(session, infopage)
#! /usr/bin/env python2
#! /usr/bin/env python3
#
# Copyright (C) 2013 Stefano Sanfilippo
# Copyright (C) 2013 BITS development team
......@@ -23,8 +23,7 @@ setup(
'markdown',
'futures',
'pycares',
'passlib',
'recaptcha'
'passlib'
],
packages=[
'bitsd',
......
#! /usr/bin/env python2
#! /usr/bin/env python3
#
# Copyright (C) 2013 Stefano Sanfilippo
# Copyright (C) 2013 BITS development team
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment