code: def _mcon(self):
          
          with self.lock:
              sdata = ' '
              while sdata[-1] != self._crlf[-1]:
                  if sdata == ' ':
                      sdata = ''
                  try:
                      sdata = sdata + \
                      self._socket.recv(4096).decode(self.encoding)
                  except UnicodeDecodeError:
                      sdata = sdata + \
                      self._socket.recv(4096).decode(self.fallback_encoding)
  
              lines = sdata.split(self._crlf)
              for line in lines:
                  if line.find('PING :') == 0:
                      self.send(line.replace('PING', 'PONG'))
                  if line != '':
                      self._buffer.append(line)
docs: Buffer IRC data and handle PING/PONG.