code: def _readline(sock, buf):
      
      chunks = []
      last_char = b''
  
      while True:
          # We're reading in chunks, so "\r\n" could appear in one chunk,
          # or across the boundary of two chunks, so we check for both
          # cases.
  
          # This case must appear first, since the buffer could have
          # later \r\n characters in it and we want to get the first \r\n.
          if last_char == b'\r' and buf[0:1] == b'\n':
              # Strip the last character from the last chunk.
              chunks[-1] = chunks[-1][:-1]
              return buf[1:], b''.join(chunks)
          elif buf.find(b'\r\n') != -1:
              before, sep, after = buf.partition(b"\r\n")
              chunks.append(before)
              return after, b''.join(chunks)
  
          if buf:
              chunks.append(buf)
              last_char = buf[-1:]
  
          buf = _recv(sock, RECV_SIZE)
          if not buf:
              raise MemcacheUnexpectedCloseError()
docs: Read line of text from the socket.
  
      Read a line of text (delimited by "\r\n") from the socket, and
      return that line along with any trailing characters read from the
      socket.
  
      Args:
          sock: Socket object, should be connected.
          buf: String, zero or more characters, returned from an earlier
              call to _readline or _readvalue (pass an empty string on the
              first call).
  
      Returns:
        A tuple of (buf, line) where line is the full line read from the
        socket (minus the "\r\n" characters) and buf is any trailing
        characters read after the "\r\n" was found (which may be an empty
        string).