def read_packet(data, local_sock, remote_addr):
 (opcode,) = unpack('!H', data[0:2])
 if ((opcode < 1) or (opcode > 6)):
  logging.warn(('Unknown request id %d from %s' % (opcode, remote_addr)))
  local_sock.sendto(ERRORPacket(0, 'Unknown request').marshall(), remote_addr)
  return None
 if (REQUESTS[opcode][REQ_CLASS] is None):
  if (opcode != TFTP_OPCODE_ERROR):
   logging.warn(('Unsupported request %d(%s) from %s' % (opcode, REQUESTS[opcode][REQ_NAME], remote_addr)))
  local_sock.sendto(ERRORPacket(2, 'Unsupported request').marshall(), remote_addr)
  return None
 try:
  return REQUESTS[opcode][REQ_CLASS](data, local_sock, remote_addr)
 except:
  return None

def read_packet ( data , local_sock , remote_addr ) : ( opcode , ) = unpack ( '!H' , data [ 0 : 2 ] ) if ( ( opcode < 1 ) or ( opcode > 6 ) ) : logging . warn ( ( 'Unknown request id %d from %s' % ( opcode , remote_addr ) ) ) local_sock . sendto ( ERRORPacket ( 0 , 'Unknown request' ) . marshall ( ) , remote_addr ) return None if ( REQUESTS [ opcode ] [ REQ_CLASS ] is None ) : if ( opcode != TFTP_OPCODE_ERROR ) : logging . warn ( ( 'Unsupported request %d(%s) from %s' % ( opcode , REQUESTS [ opcode ] [ REQ_NAME ] , remote_addr ) ) ) local_sock . sendto ( ERRORPacket ( 2 , 'Unsupported request' ) . marshall ( ) , remote_addr ) return None try : return REQUESTS [ opcode ] [ REQ_CLASS ] ( data , local_sock , remote_addr ) except : return None
read data from socket *sock* returns none if something went wrong .