######################## BEGIN LICENSE BLOCK ########################1# This library is free software; you can redistribute it and/or2# modify it under the terms of the GNU Lesser General Public3# License as published by the Free Software Foundation; either4# version 2.1 of the License, or (at your option) any later version.5#6# This library is distributed in the hope that it will be useful,7# but WITHOUT ANY WARRANTY; without even the implied warranty of8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU9# Lesser General Public License for more details.10#11# You should have received a copy of the GNU Lesser General Public12# License along with this library; if not, write to the Free Software13# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA14# 02110-1301 USA15######################### END LICENSE BLOCK #########################161718from .compat import PY2, PY319from .universaldetector import UniversalDetector20from .version import __version__, VERSION212223def detect(byte_str):24"""25Detect the encoding of the given byte string.2627:param byte_str: The byte sequence to examine.28:type byte_str: ``bytes`` or ``bytearray``29"""30if not isinstance(byte_str, bytearray):31if not isinstance(byte_str, bytes):32raise TypeError('Expected object of type bytes or bytearray, got: '33'{0}'.format(type(byte_str)))34else:35byte_str = bytearray(byte_str)36detector = UniversalDetector()37detector.feed(byte_str)38return detector.close()394041