Detect the encoding of the given byte string. :param byte_str: The byte sequence to examine. :type byte_str: ``bytes`` or ``bytearray``
(byte_str)
| 22 | |
| 23 | |
| 24 | def detect(byte_str): |
| 25 | """ |
| 26 | Detect the encoding of the given byte string. |
| 27 | |
| 28 | :param byte_str: The byte sequence to examine. |
| 29 | :type byte_str: ``bytes`` or ``bytearray`` |
| 30 | """ |
| 31 | if not isinstance(byte_str, bytearray): |
| 32 | if not isinstance(byte_str, bytes): |
| 33 | raise TypeError('Expected object of type bytes or bytearray, got: ' |
| 34 | '{0}'.format(type(byte_str))) |
| 35 | else: |
| 36 | byte_str = bytearray(byte_str) |
| 37 | detector = UniversalDetector() |
| 38 | detector.feed(byte_str) |
| 39 | return detector.close() |
no test coverage detected
searching dependent graphs…