From a65ad0b9b66016dfed851bd5eca76c1928c4011b Mon Sep 17 00:00:00 2001 From: Sourcery AI Date: Sat, 13 Jun 2020 16:56:41 +0000 Subject: [PATCH] Refactored by Sourcery --- tornad_io/__init__.py | 12 ++++++------ tornad_io/socket_io.py | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tornad_io/__init__.py b/tornad_io/__init__.py index c8dba12..f9e63ac 100755 --- a/tornad_io/__init__.py +++ b/tornad_io/__init__.py @@ -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': - if extraRE[0] == '(': - extraRE = r'(?P%s)' % extraRE - else: - extraRE = r"(?P%s)" % extraRE + extraRE = r'(?P%s)' % extraRE if extraSep: extraRE = extraSep + extraRE else: extraRE = "(?P)" protoRE = "(%s)" % "|".join(PROTOCOLS.keys()) - route = (r"/(?P%s)%s/(?P%s)/?(?P[0-9a-zA-Z]*?)/?((?P\d*?)|(?P\w*?))/?(?P\d*?)" % (resource, extraRE, protoRE), cls) - return route + return ( + r"/(?P%s)%s/(?P%s)/?(?P[0-9a-zA-Z]*?)/?((?P\d*?)|(?P\w*?))/?(?P\d*?)" + % (resource, extraRE, protoRE), + cls, + ) class SocketIOServer(tornado.httpserver.HTTPServer): """HTTP Server which does some configuration and automatic setup diff --git a/tornad_io/socket_io.py b/tornad_io/socket_io.py index 30a9e11..720d10b 100644 --- a/tornad_io/socket_io.py +++ b/tornad_io/socket_io.py @@ -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, + ) + else: return True @@ -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 if isinstance(message, list): for m in message: out_fh.send(m) @@ -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 def async_callback(self, callback, *args, **kwargs):