class_docstr: File stream policy for removing carriage-return erased characters.
  
  This is what a terminal does. We use it for console output to reduce the amount of
  data we need to send over the network (eg. for progress bars), while preserving the
  output's appearance in the web app.
  
  CR stands for "carriage return", for the character \r. It tells the terminal to move
  the cursor back to the start of the current line. Progress bars (like tqdm) use \r
  repeatedly to overwrite a line with newer updates. This gives the illusion of the
  progress bar filling up in real-time.
docstr: Process chunks.
  
  Args:
      chunks: List of Chunk objects. See description of chunk above in `split_chunk(...)`.
  
  Returns:
      List[Dict]. Each dict in the list contains two keys: an `offset` which holds the line number
      and `content` which maps to a list of consecutive lines starting from that offset.
      `offset` here means global line number in our console on the UI.
  
  Example:
      >>> chunks = [
          Chunk("output.log", "ERROR 2020-08-25T20:38 this is my line of text\nboom\n"),
          Chunk("output.log", "2020-08-25T20:38 this is test\n"),
      ]
      >>> process_chunks(chunks)
      [
          {"offset": 0, "content": [
              "ERROR 2020-08-25T20:38 this is my line of text\n",
              "ERROR 2020-08-25T20:38 boom\n",
              "2020-08-25T20:38 this is test\n"
              ]
          }
      ]
docstr_tok: ["Process","chunks",".","Args",":","chunks",":","List","of","Chunk","objects",".","See","description","of","chunk","above","in","`","split_chunk","(","...",")","`",".","Returns",":","List","[","Dict","]",".","Each","dict","in","the","list","contains","two","keys",":","an","`","offset","`","which","holds","the","line","number","and","`","content","`","which","maps","to","a","list","of","consecutive","lines","starting","from","that","offset",".","`","offset","`","here","means","global","line","number","in","our","console","on","the","UI",".","Example",":",">",">",">","chunks","=","[","Chunk","(","``","output.log","''",",","``","ERROR","2020-08-25T20:38","this","is","my","line","of","text\\nboom\\n","''",")",",","Chunk","(","``","output.log","''",",","``","2020-08-25T20:38","this","is","test\\n","''",")",",","]",">",">",">","process_chunks","(","chunks",")","[","{","``","offset","''",":","0",",","``","content","''",":","[","``","ERROR","2020-08-25T20:38","this","is","my","line","of","text\\n","''",",","``","ERROR","2020-08-25T20:38","boom\\n","''",",","``","2020-08-25T20:38","this","is","test\\n","''","]","}","]"]
code: def process_chunks(self, chunks: List) -> List["ProcessedChunk"]:
      r"""Process chunks.
  
      Args:
          chunks: List of Chunk objects. See description of chunk above in `split_chunk(...)`.
  
      Returns:
          List[Dict]. Each dict in the list contains two keys: an `offset` which holds the line number
          and `content` which maps to a list of consecutive lines starting from that offset.
          `offset` here means global line number in our console on the UI.
  
      Example:
          >>> chunks = [
              Chunk("output.log", "ERROR 2020-08-25T20:38 this is my line of text\nboom\n"),
              Chunk("output.log", "2020-08-25T20:38 this is test\n"),
          ]
          >>> process_chunks(chunks)
          [
              {"offset": 0, "content": [
                  "ERROR 2020-08-25T20:38 this is my line of text\n",
                  "ERROR 2020-08-25T20:38 boom\n",
                  "2020-08-25T20:38 this is test\n"
                  ]
              }
          ]
      """
      # Dict[int->str], each offset (line number) mapped to a line.
      # Represents a mini-version of our console pane on the UI.
      console = {}
      sep = os.linesep
  
      for c in chunks:
          prefix, logs_str = self.split_chunk(c)
          logs = logs_str.split(sep)
  
          for line in logs:
              stream = (
                  self.stderr
                  if prefix.startswith("ERROR ")
                  else self.stdout
              )
              if line.startswith("\r"):
                  # line starting with \r will always overwrite a previous offset.
                  offset: int = (
                      stream.cr
                      if (stream.found_cr and stream.cr is not None)
                      else (stream.last_normal or 0)
                  )
                  stream.cr = offset
                  stream.found_cr = True
                  console[offset] = prefix + line[1:] + "\n"
  
                  # Usually logs_str = "\r progress bar\n" for progress bar updates.
                  # If instead logs_str = "\r progress bar\n text\n text\n",
                  # treat this as the end of a progress bar and reset accordingly.
                  if (
                      logs_str.count(sep) > 1
                      and logs_str.replace(sep, "").count("\r") == 1
                  ):
                      stream.found_cr = False
  
              elif line:
                  console[self.global_offset] = prefix + line + "\n"
                  stream.last_normal = self.global_offset
                  self.global_offset += 1
  
      intervals = self.get_consecutive_offsets(console)
      ret = []
      for a, b in intervals:
          processed_chunk: ProcessedChunk = {
              "offset": a,
              "content": [console[i] for i in range(a, b + 1)],
          }
          ret.append(processed_chunk)
      return ret
  
imports: import base64
  import functools
  import itertools
  import logging
  import os
  import queue
  import random
  import sys
  import threading
  import time
  from types import TracebackType
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, NamedTuple, Optional, Set, Tuple, Type, Union
  import requests
  import wandb
  from wandb import util
  from wandb.sdk.internal import internal_api
  from ..lib import file_stream_utils
label_desc: Use image node_id 4 for calling the CRDedupeFilePolicy obj's underlying member method code with example usage: obj.process_chunks(chunks) and returns: ret