Skip to content

Commit

Permalink
Only use single startswith calls for detecting different BOMs
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-blanchard committed Apr 11, 2017
1 parent 7c8239b commit 663c57a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions chardet/universaldetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def feed(self, byte_str):
self.result = {'encoding': "UTF-8-SIG",
'confidence': 1.0,
'language': ''}
elif byte_str.startswith(codecs.BOM_UTF32_LE) or byte_str.startswith(codecs.BOM_UTF32_BE):
elif byte_str.startswith((codecs.BOM_UTF32_LE,
codecs.BOM_UTF32_BE)):
# FF FE 00 00 UTF-32, little-endian BOM
# 00 00 FE FF UTF-32, big-endian BOM
self.result = {'encoding': "UTF-32",
Expand All @@ -154,7 +155,7 @@ def feed(self, byte_str):
self.result = {'encoding': "X-ISO-10646-UCS-4-2143",
'confidence': 1.0,
'language': ''}
elif byte_str.startswith(codecs.BOM_LE) or byte_str.startswith(codecs.BOM_BE):
elif byte_str.startswith((codecs.BOM_LE, codecs.BOM_BE)):
# FF FE UTF-16, little endian BOM
# FE FF UTF-16, big endian BOM
self.result = {'encoding': "UTF-16",
Expand Down

0 comments on commit 663c57a

Please sign in to comment.