flutter_flutter/engine/src/flutter/ci/compatibility_helper.py
Ricardo Amador 2e9905afab Update infrastructure python code to be compatible with python 2 and python 3 (flutter/engine#39133)
* Compatibility with python2 and python3

* Formatting

* Updated to use a function instead of decoding bytes in multiple places.

* Formatting and whitespace cleanup.

* Fix import statement.

* Linter change for docstring.

* Formatting.

* Remove function from run_tests.py since it is a pain to import.

* Add todo message for python 2 deprecation.

* Updated copyright year.
2023-01-26 16:04:31 +00:00

26 lines
808 B
Python

#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# This script contains helper function(s) for supporting both
# python 2 and python 3 infrastructure code.
ENCODING = 'UTF-8'
def byte_str_decode(str_or_bytes):
"""Returns a string if given either a string or bytes.
TODO: This function should be removed when the supported python
version is only python 3.
Args:
str_or_bytes (string or bytes) we want to convert or return as
the possible value changes depending on the version of python
used.
"""
return str_or_bytes if isinstance(str_or_bytes,
str) else str_or_bytes.decode(ENCODING)