From 992a2d17939eb5679d9154cfcd25d99ed69f4a94 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 8 Jun 2025 22:47:17 +0900 Subject: [PATCH] Use 'is' in comparison to None ... instead of == or != . --- websockify/websocketproxy.py | 8 ++++---- websockify/websockifyserver.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/websockify/websocketproxy.py b/websockify/websocketproxy.py index 6e19e72..ca90781 100644 --- a/websockify/websocketproxy.py +++ b/websockify/websocketproxy.py @@ -367,7 +367,7 @@ class WebSocketProxy(websockifyserver.WebSockifyServer): else: dst_string = "%s:%s" % (self.target_host, self.target_port) - if self.listen_fd != None: + if self.listen_fd is not None: src_string = "inetd" else: src_string = "%s:%s" % (self.listen_host, self.listen_port) @@ -392,11 +392,11 @@ class WebSocketProxy(websockifyserver.WebSockifyServer): if self.wrap_cmd and self.cmd: ret = self.cmd.poll() - if ret != None: + if ret is not None: self.vmsg("Wrapped command exited (or daemon). Returned %s" % ret) self.cmd = None - if self.wrap_cmd and self.cmd == None: + if self.wrap_cmd and self.cmd is None: # Response to wrapped command being gone if self.wrap_mode == "ignore": pass @@ -708,7 +708,7 @@ def websockify_init(): except ValueError: parser.error("Error parsing target port") - if len(args) > 0 and opts.wrap_cmd == None: + if len(args) > 0 and opts.wrap_cmd is None: parser.error("Too many arguments") if opts.token_plugin is not None: diff --git a/websockify/websockifyserver.py b/websockify/websockifyserver.py index 7342b6e..df180a3 100644 --- a/websockify/websockifyserver.py +++ b/websockify/websockifyserver.py @@ -22,7 +22,7 @@ for mod, msg in [('ssl', 'TLS/SSL/wss is disabled'), try: globals()[mod] = __import__(mod) except ImportError: - globals()[mod] = None + globals()[mod] is None print("WARNING: no '%s' module, %s" % (mod, msg)) if sys.platform == 'win32': @@ -405,9 +405,9 @@ class WebSockifyServer(): # Show configuration self.msg("WebSocket server settings:") - if self.listen_fd != None: + if self.listen_fd is not None: self.msg(" - Listen for inetd connections") - elif self.unix_listen != None: + elif self.unix_listen is not None: self.msg(" - Listen on unix socket %s", self.unix_listen) else: self.msg(" - Listen on %s:%s", @@ -741,9 +741,9 @@ class WebSockifyServer(): """ try: - if self.listen_fd != None: + if self.listen_fd is not None: lsock = socket.fromfd(self.listen_fd, socket.AF_INET, socket.SOCK_STREAM) - elif self.unix_listen != None: + elif self.unix_listen is not None: lsock = self.socket(host=None, unix_socket=self.unix_listen, unix_socket_mode=self.unix_listen_mode, @@ -819,7 +819,7 @@ class WebSockifyServer(): if lsock in ready: startsock, address = lsock.accept() # Unix Socket will not report address (empty string), but address[0] is logged a bunch - if self.unix_listen != None: + if self.unix_listen is not None: address = [self.unix_listen] else: continue