code: def _clean(self, data: str):
      last_newline = None
      remove = []
      for i in range(len(data)):
          if data[i] == "\r":
              if i + 1 < len(data) and data[i + 1] == "\n":
                  remove.append((i, i))
              elif last_newline is not None:
                  remove.append((last_newline + 1, i))
              last_newline = i
          elif data[i] == "\n":
              last_newline = i
  
      res = []
      offset = 0
      for r in remove:
          if offset < r[0]:
              res.append(data[offset : r[0]])
          offset = r[1] + 1
  
      res.append(data[offset:])
      return "".join(res)
  
imports: import sys
  import threading
  import time
  from io import StringIO
  from typing import Optional
  from labml.internal.app import AppTracker, AppTrackDataSource, Packet
label_desc: Use image node_id 4 for calling the AppConsoleLogs obj's underlying member method code with example usage: obj._clean(data) and returns: str