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
12 changes: 6 additions & 6 deletions tornad_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,18 @@ def routes(cls, resource, extraRE=None, extraSep=None):
#return (r"/%s/((xhr-polling|xhr-multipart|jsonp-polling|htmlfile)/)?/?/(\d*)/(%s)" % (resource, extraRE), cls)
if extraRE:
if extraRE[0] != '(?P<extra>':
if extraRE[0] == '(':
extraRE = r'(?P<extra>%s)' % extraRE
else:
extraRE = r"(?P<extra>%s)" % extraRE
extraRE = r'(?P<extra>%s)' % extraRE
if extraSep:
extraRE = extraSep + extraRE
else:
extraRE = "(?P<extra>)"

protoRE = "(%s)" % "|".join(PROTOCOLS.keys())
route = (r"/(?P<resource>%s)%s/(?P<protocol>%s)/?(?P<session_id>[0-9a-zA-Z]*?)/?((?P<protocol_init>\d*?)|(?P<xhr_path>\w*?))/?(?P<jsonp_index>\d*?)" % (resource, extraRE, protoRE), cls)
return route
return (
r"/(?P<resource>%s)%s/(?P<protocol>%s)/?(?P<session_id>[0-9a-zA-Z]*?)/?((?P<protocol_init>\d*?)|(?P<xhr_path>\w*?))/?(?P<jsonp_index>\d*?)"
% (resource, extraRE, protoRE),
cls,
)
Comment on lines -131 to +142
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SocketIOHandler.routes refactored with the following changes:

  • Hoist repeated code outside conditional statement
  • Inline variable that is only used once


class SocketIOServer(tornado.httpserver.HTTPServer):
"""HTTP Server which does some configuration and automatic setup
Expand Down
14 changes: 7 additions & 7 deletions tornad_io/socket_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,12 @@ def verify_origin(self):
url = urlparse.urlparse(origin)
host = url.hostname
port = url.port
return filter(lambda t: (t[0] == '*' or t[0].lower() == host.lower()) and (t[1] == '*' or t[1] == int(port)), origins)
return filter(
lambda t: ((t[0] == '*' or t[0].lower() == host.lower()))
and t[1] in ['*', int(port)],
origins,
)

Comment on lines -211 to +216
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SocketIOProtocol.verify_origin refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator

else:
return True

Expand All @@ -218,11 +223,7 @@ def send(self, message, skip_queue=False):
ensures it doesn't send if session
isn't fully open yet."""

if self.asynchronous:
out_fh = self.output_handle
else:
out_fh = self

out_fh = self.output_handle if self.asynchronous else self
Comment on lines -221 to +226
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SocketIOProtocol.send refactored with the following changes:

  • Replace if statement with if expression

if isinstance(message, list):
for m in message:
out_fh.send(m)
Expand Down Expand Up @@ -288,7 +289,6 @@ def _write(self, message):
"""Write method which all protocols must define to
indicate how to push to their wire"""
self.warning("[socketio protocol] Default call to _write. NOOP. [%s]" % message)
pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SocketIOProtocol._write refactored with the following changes:

  • Remove redundant pass statement



def async_callback(self, callback, *args, **kwargs):
Expand Down