Merge branch 'main' into avm99963-monorail

Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266

GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/framework/filecontent.py b/framework/filecontent.py
index 15d2940..7e79643 100644
--- a/framework/filecontent.py
+++ b/framework/filecontent.py
@@ -1,7 +1,6 @@
-# Copyright 2016 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file or at
-# https://developers.google.com/open-source/licenses/bsd
+# Copyright 2016 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
 
 """Utility routines for dealing with MIME types and decoding text files."""
 
@@ -11,6 +10,7 @@
 
 import itertools
 import logging
+import six
 
 from framework import framework_constants
 
@@ -160,7 +160,7 @@
 
   # If the string can be decoded as utf-8, we treat it as textual.
   try:
-    u_str = file_contents.decode('utf-8', 'strict')
+    u_str = six.ensure_text(file_contents)
     is_long = len(u_str.split('\n')) > SOURCE_FILE_MAX_LINES
     return u_str, False, is_long
   except UnicodeDecodeError:
@@ -168,7 +168,7 @@
 
   # Fall back on latin-1. This will always succeed, since every byte maps to
   # something in latin-1, even if that something is gibberish.
-  u_str = file_contents.decode('latin-1', 'strict')
+  u_str = six.ensure_text(file_contents, encoding='latin-1')
 
   lines = u_str.split('\n')
   is_long = len(lines) > SOURCE_FILE_MAX_LINES