code: def is_valid(packet):
      
      packet = packet.strip(END)
      return not (END in packet or
                  packet.endswith(ESC) or
                  re.search(ESC + b'[^' + ESC_END + ESC_ESC + b']', packet))
docs: is_valid(packet) -> indicates if the packet's contents conform to the SLIP specification.
      
      A packet is valid if:
  
      * It contains no :const:`END` bytes other than leading and/or trailing :const:`END` bytes, and
      * Each :const:`ESC` byte is followed by either an :const:`ESC_END` or an :const:`ESC_ESC` byte.
  
      :param bytes packet: The packet to inspect.
      :return: :const:`True` if the packet is valid, :const:`False` otherwise
      :rtype: bool