code: def fix_file(input_file,
               encoding=None,
               *,
               fix_entities='auto',
               remove_terminal_escapes=True,
               fix_encoding=True,
               fix_latin_ligatures=True,
               fix_character_width=True,
               uncurl_quotes=True,
               fix_line_breaks=True,
               fix_surrogates=True,
               remove_control_chars=True,
               remove_bom=True,
               normalization='NFC'):
      
      entities = fix_entities
      for line in input_file:
          if isinstance(line, bytes):
              if encoding is None:
                  line, encoding = guess_bytes(line)
              else:
                  line = line.decode(encoding)
          if fix_entities == 'auto' and '<' in line and '>' in line:
              entities = False
          yield fix_text_segment(
              line,
              fix_entities=entities,
              remove_terminal_escapes=remove_terminal_escapes,
              fix_encoding=fix_encoding,
              fix_latin_ligatures=fix_latin_ligatures,
              fix_character_width=fix_character_width,
              uncurl_quotes=uncurl_quotes,
              fix_line_breaks=fix_line_breaks,
              fix_surrogates=fix_surrogates,
              remove_control_chars=remove_control_chars,
              remove_bom=remove_bom,
              normalization=normalization
          )
docs: Fix text that is found in a file.
  
      If the file is being read as Unicode text, use that. If it's being read as
      bytes, then we hope an encoding was supplied. If not, unfortunately, we
      have to guess what encoding it is. We'll try a few common encodings, but we
      make no promises. See the `guess_bytes` function for how this is done.
  
      The output is a stream of fixed lines of text.