From 6c5a4684189dd953fd4b6c5afc513b7646ccdf1d Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 16 Jan 2023 13:02:47 +0200 Subject: [PATCH] - fixed a decoding error in the Excellon parser --- CHANGELOG.md | 4 ++++ appParsers/ParseExcellon.py | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14e1ab81..916efc7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ CHANGELOG for FlatCAM Evo beta ================================================= +16.01.2023 + +- fixed a decoding error in the Excellon parser + 15.01.2023 - PEP8 changes diff --git a/appParsers/ParseExcellon.py b/appParsers/ParseExcellon.py index 06061556..5d1a60a6 100644 --- a/appParsers/ParseExcellon.py +++ b/appParsers/ParseExcellon.py @@ -230,9 +230,20 @@ class Excellon(Geometry): else: if filename is None: return "fail" - efile = open(filename, 'r') - estr = efile.readlines() - efile.close() + + estr = "" + decoded = False + encodings_types = ('cp1252', 'cp850', 'utf-8', 'utf8') + for enc in encodings_types: + try: + with open(filename, 'r', encoding=enc) as efile: + estr = efile.readlines() + decoded = True + break + except UnicodeDecodeError: + pass + if decoded is False: + return 'fail' try: self.parse_lines(estr)