Convert C{bytes} or C{str} to C{str} type, using ASCII encoding if conversion is necessary. @raise UnicodeError: The input string is not ASCII encodable/decodable. @raise TypeError: The input is neither C{bytes} nor C{str}.
(s: AnyStr)
| 327 | |
| 328 | |
| 329 | def nativeString(s: AnyStr) -> str: |
| 330 | """ |
| 331 | Convert C{bytes} or C{str} to C{str} type, using ASCII encoding if |
| 332 | conversion is necessary. |
| 333 | |
| 334 | @raise UnicodeError: The input string is not ASCII encodable/decodable. |
| 335 | @raise TypeError: The input is neither C{bytes} nor C{str}. |
| 336 | """ |
| 337 | if not isinstance(s, (bytes, str)): |
| 338 | raise TypeError("%r is neither bytes nor str" % s) |
| 339 | if isinstance(s, bytes): |
| 340 | return s.decode("ascii") |
| 341 | else: |
| 342 | # Ensure we're limited to ASCII subset: |
| 343 | s.encode("ascii") |
| 344 | return s |
| 345 | |
| 346 | |
| 347 | def _matchingString(constantString, inputString): |