Skip to content
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
16 changes: 8 additions & 8 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
master_doc = 'index'

# General information about the project.
project = u'TornadIO2'
copyright = u'2011, Serge S. Koval'
project = 'TornadIO2'
copyright = '2011, Serge S. Koval'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -183,8 +183,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'TornadIO2.tex', u'TornadIO2 Documentation',
u'Serge S. Koval', 'manual'),
('index', 'TornadIO2.tex', 'TornadIO2 Documentation',
'Serge S. Koval', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -213,8 +213,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'tornadio2', u'TornadIO2 Documentation',
[u'Serge S. Koval'], 1)
('index', 'tornadio2', 'TornadIO2 Documentation',
['Serge S. Koval'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -227,8 +227,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'TornadIO2', u'TornadIO2 Documentation',
u'Serge S. Koval', 'TornadIO2', 'One line description of project.',
('index', 'TornadIO2', 'TornadIO2 Documentation',
'Serge S. Koval', 'TornadIO2', 'One line description of project.',
'Miscellaneous'),
]

Expand Down
6 changes: 3 additions & 3 deletions examples/multiplexed/multiplexed.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_username(cls):
return 'User%d' % cls.unique_id

def on_open(self, info):
print 'Chat', repr(info)
print(('Chat', repr(info)))

# Give user unique ID
self.user_name = self.get_username()
Expand All @@ -54,7 +54,7 @@ def broadcast(self, msg):

class PingConnection(SocketConnection):
def on_open(self, info):
print 'Ping', repr(info)
print(('Ping', repr(info)))

def on_message(self, message):
now = datetime.datetime.now()
Expand All @@ -68,7 +68,7 @@ class RouterConnection(SocketConnection):
'/ping': PingConnection}

def on_open(self, info):
print 'Router', repr(info)
print(('Router', repr(info)))

# Create tornadio server
MyRouter = TornadioRouter(RouterConnection)
Expand Down
2 changes: 1 addition & 1 deletion examples/rpcping/rpcping.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get(self):
class PingConnection(SocketConnection):
@event
def ping(self, client, text):
print 'Got %s from client' % text
print(('Got %s from client' % text))

now = datetime.datetime.now()

Expand Down
2 changes: 1 addition & 1 deletion tests/gen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, queue_type):

@gen.sync_engine
def test(self, value):
for n in xrange(2):
for n in range(2):
self.v += (yield gen.Task(self.queue_type, value))

def test():
Expand Down
18 changes: 9 additions & 9 deletions tests/proto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ def test_encode_frames():

# Test multiple strings encode
eq_(proto.encode_frames(['abc', 'def']),
u'\ufffd3\ufffdabc\ufffd3\ufffddef'.encode('utf-8'))
'\\ufffd3\\ufffdabc\\ufffd3\\ufffddef'.encode('utf-8'))


def test_decode_frames():
# Single string
eq_(proto.decode_frames(u'abc'), [u'abc'])
eq_(proto.decode_frames('abc'), ['abc'])

# Multiplie strings
eq_(proto.decode_frames(u'\ufffd3\ufffdabc\ufffd3\ufffddef'),
[u'abc', u'def'])
eq_(proto.decode_frames('\\ufffd3\\ufffdabc\\ufffd3\\ufffddef'),
['abc', 'def'])


def test_message():
# Test string message
eq_(proto.message(None, 'abc'), u'3:::abc')
eq_(proto.message(None, 'abc'), '3:::abc')

eq_(proto.message('abc', 'def'), u'3::abc:def')
eq_(proto.message('abc', 'def'), '3::abc:def')

eq_(proto.message(None, u'\u0403\u0404\u0405'),
u'3:::\u0403\u0404\u0405')
eq_(proto.message(None, '\\u0403\\u0404\\u0405'),
'3:::\\u0403\\u0404\\u0405')

# TODO: Multibyte encoding fix

# TODO: Fix me
eq_(proto.message(None, dict(a=1, b=2)),
u'4:::%s' % proto.json_dumps(dict(a=1, b=2)))
'4:::%s' % proto.json_dumps(dict(a=1, b=2)))


# TODO: Add event unit tests
3 changes: 1 addition & 2 deletions tornadio2/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(cls, name, bases, attrs):
super(EventMagicMeta, cls).__init__(name, bases, attrs)


class SocketConnection(object):
class SocketConnection(object, metaclass=EventMagicMeta):
"""Subclass this class and define at least `on_message()` method to make a Socket.IO
connection handler.

Expand All @@ -96,7 +96,6 @@ def test(self, msg):
sock.emit('test', {msg:'Hello World'});

"""
__metaclass__ = EventMagicMeta

__endpoints__ = dict()

Expand Down
4 changes: 2 additions & 2 deletions tornadio2/flashserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Flash Socket policy server implementation. Merged with minor modifications
from the SocketTornad.IO project.
"""
from __future__ import with_statement


import socket
import errno
Expand Down Expand Up @@ -64,7 +64,7 @@ def connection_ready(self, sock, _fd, _events):
while True:
try:
connection, address = sock.accept()
except socket.error, ex:
except socket.error as ex:
if ex[0] not in (errno.EWOULDBLOCK, errno.EAGAIN):
raise
return
Expand Down
2 changes: 1 addition & 1 deletion tornadio2/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def on_message(self, message):

try:
self.session.raw_message(message)
except Exception, ex:
except Exception as ex:
logger.error('Failed to handle message: ' + traceback.format_exc(ex))

# Close session on exception
Expand Down
8 changes: 4 additions & 4 deletions tornadio2/polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""
import time
import logging
import urllib
import urllib.request, urllib.parse, urllib.error

from tornado.web import HTTPError, asynchronous

Expand Down Expand Up @@ -88,7 +88,7 @@ def post(self, session_id):
data = self.request.body.decode('utf-8')

# IE XDomainRequest support
if data.startswith(u'data='):
if data.startswith('data='):
data = data[5:]

# Process packets one by one
Expand Down Expand Up @@ -295,10 +295,10 @@ def post(self, session_id):
raise HTTPError(403)

# Grab data
data = urllib.unquote_plus(data[2:]).decode('utf-8')
data = urllib.parse.unquote_plus(data[2:]).decode('utf-8')

# If starts with double quote, it is json encoded (socket.io workaround)
if data.startswith(u'"'):
if data.startswith('"'):
data = proto.json_load(data)

# Process packets one by one
Expand Down
34 changes: 17 additions & 17 deletions tornadio2/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def default(self, o):
NOOP = '8'

# socket.io frame separator
FRAME_SEPARATOR = u'\ufffd'
FRAME_SEPARATOR = '\\ufffd'


def disconnect(endpoint=None):
Expand All @@ -61,7 +61,7 @@ def disconnect(endpoint=None):
`endpoint`
Optional endpoint name
"""
return u'0::%s' % (
return '0::%s' % (
endpoint or ''
)

Expand All @@ -72,15 +72,15 @@ def connect(endpoint=None):
`endpoint`
Optional endpoint name
"""
return u'1::%s' % (
return '1::%s' % (
endpoint or ''
)


def heartbeat():
"""Generate heartbeat message.
"""
return u'2::'
return '2::'


def message(endpoint, msg, message_id=None, force_json=False):
Expand All @@ -99,22 +99,22 @@ def message(endpoint, msg, message_id=None, force_json=False):
"""
if msg is None:
# TODO: Log something ?
return u''
return ''

packed_message_tpl = u"%(kind)s:%(message_id)s:%(endpoint)s:%(msg)s"
packed_data = {'endpoint': endpoint or u'',
'message_id': message_id or u''}
packed_message_tpl = "%(kind)s:%(message_id)s:%(endpoint)s:%(msg)s"
packed_data = {'endpoint': endpoint or '',
'message_id': message_id or ''}

# Trying to send a dict over the wire ?
if not isinstance(msg, (unicode, str)) and isinstance(msg, (dict, object)):
if not isinstance(msg, str) and isinstance(msg, (dict, object)):
packed_data.update({'kind': JSON,
'msg': json.dumps(msg, **json_decimal_args)})

# for all other classes, including objects. Call str(obj)
# and respect forced JSON if requested
else:
packed_data.update({'kind': MESSAGE if not force_json else JSON,
'msg': msg if isinstance(msg, unicode) else str(msg).decode('utf-8')})
'msg': msg if isinstance(msg, str) else str(msg).decode('utf-8')})

return packed_message_tpl % packed_data

Expand Down Expand Up @@ -147,7 +147,7 @@ def event(endpoint, name, message_id, *args, **kwargs):
args=[kwargs]
)

return u'5:%s:%s:%s' % (
return '5:%s:%s:%s' % (
message_id or '',
endpoint or '',
json.dumps(evt)
Expand All @@ -170,11 +170,11 @@ def ack(endpoint, message_id, ack_response=None):

data = json_dumps(ack_response)

return u'6::%s:%s+%s' % (endpoint or '',
return '6::%s:%s+%s' % (endpoint or '',
message_id,
data)
else:
return u'6::%s:%s' % (endpoint or '',
return '6::%s:%s' % (endpoint or '',
message_id)


Expand All @@ -188,14 +188,14 @@ def error(endpoint, reason, advice=None):
`advice`
Error advice
"""
return u'7::%s:%s+%s' % (endpoint or '',
return '7::%s:%s+%s' % (endpoint or '',
(reason or ''),
(advice or ''))


def noop():
"""Generate noop packet."""
return u'8::'
return '8::'


def json_dumps(msg):
Expand Down Expand Up @@ -224,7 +224,7 @@ def decode_frames(data):

"""
# Single message - nothing to decode here
assert isinstance(data, unicode), 'frame is not unicode'
assert isinstance(data, str), 'frame is not unicode'

if not data.startswith(FRAME_SEPARATOR):
return [data]
Expand Down Expand Up @@ -267,7 +267,7 @@ def encode_frames(packets):
return packets[0].encode('utf-8')

# Multiple packets
frames = u''.join(u'%s%d%s%s' % (FRAME_SEPARATOR, len(p),
frames = ''.join('%s%d%s%s' % (FRAME_SEPARATOR, len(p),
FRAME_SEPARATOR, p)
for p in packets)

Expand Down
2 changes: 1 addition & 1 deletion tornadio2/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self, application,
io_loop=io_loop,
port=flash_policy_port,
policy_file=flash_policy_file)
except Exception, ex:
except Exception as ex:
logger.error('Failed to start Flash policy server: %s', ex)

if auto_start:
Expand Down
10 changes: 5 additions & 5 deletions tornadio2/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Active TornadIO2 connection session.
"""

import urlparse
import urllib.parse
import logging


Expand Down Expand Up @@ -221,7 +221,7 @@ def close(self, endpoint=None):
if endpoint is None:
if not self.conn.is_closed:
# Close child connections
for k in self.endpoints.keys():
for k in list(self.endpoints.keys()):
self.disconnect_endpoint(k)

# Close parent connections
Expand Down Expand Up @@ -289,7 +289,7 @@ def connect_endpoint(self, url):
`url`
socket.io endpoint URL.
"""
urldata = urlparse.urlparse(url)
urldata = urllib.parse.urlparse(url)

endpoint = urldata.path

Expand Down Expand Up @@ -404,7 +404,7 @@ def raw_message(self, msg):
# in args
if len(args) == 1 and isinstance(args[0], dict):
# Fix for the http://bugs.python.org/issue4978 for older Python versions
str_args = dict((str(x), y) for x, y in args[0].iteritems())
str_args = dict((str(x), y) for x, y in list(args[0].items()))

ack_response = conn.on_event(event['name'], kwargs=str_args)
else:
Expand All @@ -429,7 +429,7 @@ def raw_message(self, msg):
logger.error('Incoming error: %s' % msg_data)
elif msg_type == proto.NOOP:
pass
except Exception, ex:
except Exception as ex:
logger.exception(ex)

# TODO: Add global exception callback?
Expand Down