Make this unicode in Python 3, otherwise leave it as bytes. Args: byte_str: The byte string to decode. allow_none: If true, then we will allow byte_str to be None in which case we will return an empty string. TODO(rkn): Remove this flag. This is only here
(byte_str: str, allow_none: bool = False, encode_type: str = "utf-8")
| 459 | |
| 460 | |
| 461 | def decode(byte_str: str, allow_none: bool = False, encode_type: str = "utf-8"): |
| 462 | """Make this unicode in Python 3, otherwise leave it as bytes. |
| 463 | |
| 464 | Args: |
| 465 | byte_str: The byte string to decode. |
| 466 | allow_none: If true, then we will allow byte_str to be None in which |
| 467 | case we will return an empty string. TODO(rkn): Remove this flag. |
| 468 | This is only here to simplify upgrading to flatbuffers 1.10.0. |
| 469 | encode_type: The encoding type to use for decoding. Defaults to "utf-8". |
| 470 | |
| 471 | Returns: |
| 472 | A byte string in Python 2 and a unicode string in Python 3. |
| 473 | """ |
| 474 | if byte_str is None and allow_none: |
| 475 | return "" |
| 476 | |
| 477 | if not isinstance(byte_str, bytes): |
| 478 | raise ValueError(f"The argument {byte_str} must be a bytes object.") |
| 479 | return byte_str.decode(encode_type) |
| 480 | |
| 481 | |
| 482 | class TimerBase(ABC): |
searching dependent graphs…