Given a string object, regardless of type, returns a representation of that string in the native string type, encoding and decoding where necessary. This assumes ASCII unless told otherwise.
(string: str | bytes, encoding: str = "ascii")
| 24 | |
| 25 | |
| 26 | def to_native_string(string: str | bytes, encoding: str = "ascii") -> str: |
| 27 | """Given a string object, regardless of type, returns a representation of |
| 28 | that string in the native string type, encoding and decoding where |
| 29 | necessary. This assumes ASCII unless told otherwise. |
| 30 | """ |
| 31 | if isinstance(string, builtin_str): |
| 32 | out = string |
| 33 | else: |
| 34 | out = string.decode(encoding) |
| 35 | |
| 36 | return out |
| 37 | |
| 38 | |
| 39 | def unicode_is_ascii(u_string: str) -> bool: |
no outgoing calls