From d89deb47d3dfe4158232441fa335f295ab62c7bd Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 16 Jan 2023 13:05:53 +0200 Subject: [PATCH] - fixed an encoding 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 f308e16d..65f3eff2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ CHANGELOG for FlatCAM Evo beta ================================================= +16.01.2023 + +- fixed an encoding error in the Excellon parser + 20.05.2022 - small fix for a bug that interfere with running the 2D graphic mode 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)