Skip to content

Commit

Permalink
DSL: detect utf-16-le and utf-16-be encodings, #555
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Apr 14, 2024
1 parent 44e7705 commit 1967533
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pyglossary/plugins/dsl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@ def open(
self.processHeaderLine(line)

def detectEncoding(self) -> str:
for testEncoding in ("utf-8", "utf-16"):
for testEncoding in (
"utf-8",
"utf-16",
"utf-16-le",
"utf-16-be",
):
with compressionOpen(
self._filename,
dz=True,
Expand All @@ -240,7 +245,7 @@ def detectEncoding(self) -> str:
try:
for _ in range(10):
fileObj.readline()
except UnicodeDecodeError:
except (UnicodeDecodeError, UnicodeError):
log.info(f"Encoding of DSL file is not {testEncoding}")
continue
else:
Expand Down

0 comments on commit 1967533

Please sign in to comment.