#NEWLINE# def read_packet( self , stream ) : #NEWLINE# #INDENT# ready_to_read = select . select ( [ self . connection . socket ] , [ ] , [ ] , self . TIME_OUT ) [ 0 ] #NEWLINE# if ( self . connection . socket in ready_to_read ) : #NEWLINE# #INDENT# length = VarInt . read_socket ( self . connection . socket ) #NEWLINE# packet_data = packets . PacketBuffer ( ) #NEWLINE# packet_data . send ( stream . read ( length ) ) #NEWLINE# while ( len ( packet_data . get_writable ( ) ) < length ) : #NEWLINE# #INDENT# packet_data . send ( stream . read ( ( length - len ( packet_data . get_writable ( ) ) ) ) ) #NEWLINE# #UNINDENT# packet_data . reset_cursor ( ) #NEWLINE# if self . connection . options . compression_enabled : #NEWLINE# #INDENT# compressed_size = VarInt . read ( packet_data ) #NEWLINE# if ( compressed_size > 0 ) : #NEWLINE# #INDENT# decompressed_packet = decompress ( packet_data . read ( compressed_size ) ) #NEWLINE# packet_data . reset ( ) #NEWLINE# packet_data . send ( decompressed_packet ) #NEWLINE# packet_data . reset_cursor ( ) #NEWLINE# #UNINDENT# #UNINDENT# packet_id = VarInt . read ( packet_data ) #NEWLINE# if ( packet_id in self . clientbound_packets ) : #NEWLINE# #INDENT# packet = self . clientbound_packets [ packet_id ] ( ) #NEWLINE# packet . read ( packet_data ) #NEWLINE# return packet #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return packets . Packet ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return None