@@ -755,7 +755,7 @@ def _read_frame(self):
755755 return fin , opcode , payload
756756
757757 def _is_control_frame (self , opcode : int ) -> bool :
758- return opcode in ( Websocket .CLOSE , Websocket .PING , Websocket .PONG )
758+ return opcode in { Websocket .CLOSE , Websocket .PING , Websocket .PONG }
759759
760760 def _handle_control_frame (self , fin : int , opcode : int , payload : bytes ):
761761 if 125 < len (payload ):
@@ -766,9 +766,7 @@ def _handle_control_frame(self, fin: int, opcode: int, payload: bytes):
766766
767767 if opcode == Websocket .CLOSE :
768768 if len (payload ) == 1 :
769- raise WebsocketError (
770- "Invalid close payload length" , self .PROTOCOL_ERROR
771- )
769+ raise WebsocketError ("Invalid close payload length" , self .PROTOCOL_ERROR )
772770 close_code = None
773771 close_reason = None
774772 if 2 <= len (payload ):
@@ -788,15 +786,12 @@ def _handle_control_frame(self, fin: int, opcode: int, payload: bytes):
788786 elif opcode == Websocket .PONG :
789787 return
790788
791- def _handle_frame (
792- self , fin : int , opcode : int , payload : bytes
793- ) -> Union [str , bytes , None ]:
794-
789+ def _handle_frame (self , fin : int , opcode : int , payload : bytes ) -> Union [str , bytes , None ]:
795790 if self ._is_control_frame (opcode ):
796791 return self ._handle_control_frame (fin , opcode , payload )
797792
798793 if not self ._fragmented_message_in_progress ():
799- if opcode not in ( Websocket .TEXT , Websocket .BINARY ) :
794+ if opcode not in { Websocket .TEXT , Websocket .BINARY } :
800795 raise WebsocketError (
801796 "Invalid frame received when no fragmented message in progress" ,
802797 self .PROTOCOL_ERROR ,
@@ -819,7 +814,7 @@ def _handle_frame(
819814 self ._start_fragmented_message (opcode , payload )
820815 return None
821816
822- if opcode not in ( Websocket .CONT ,) :
817+ if opcode != Websocket .CONT :
823818 raise WebsocketError (
824819 "New data frame received while fragmented message in progress" ,
825820 self .PROTOCOL_ERROR ,
@@ -862,13 +857,10 @@ def receive(self, fail_silently: bool = False) -> Union[str, bytes, None]:
862857 return None
863858 except OSError as error :
864859 if error .errno == EAGAIN : # No message/frame available
865-
866860 if not self ._fragmented_message_in_progress ():
867861 return None
868862
869- time_since_last_frame = (
870- monotonic_ns () - self ._message_last_frame_timestamp
871- )
863+ time_since_last_frame = monotonic_ns () - self ._message_last_frame_timestamp
872864
873865 if time_since_last_frame > self .MESSAGE_FRAGMENT_TIMEOUT_NS :
874866 self .close (code = self .POLICY_VIOLATION )
0 commit comments