|
24 | 24 |
|
25 | 25 | # Libraries. |
26 | 26 | import os |
| 27 | +import re |
27 | 28 | from datetime import datetime |
28 | 29 | import re |
29 | 30 | from bs4 import BeautifulSoup |
30 | 31 | from collections import OrderedDict |
31 | 32 | from .. import SEPRTR |
32 | 33 | from .eda import eda_class |
33 | | -from .log__ import debug_overview |
| 34 | +from .log__ import debug_overview, debug_obsessive |
34 | 35 |
|
35 | 36 |
|
36 | 37 | __all__ = ['eda_kicad'] |
@@ -70,11 +71,17 @@ def get_part_groups(in_file): |
70 | 71 | @return `dict()` of the parts designed. The keys are the componentes references. |
71 | 72 | ''' |
72 | 73 | # Read-in the schematic XML file to get a tree and get its root. |
73 | | - debug_overview('# Getting from XML \'{}\' KiCad BoM...'.format( |
74 | | - os.path.basename(in_file))) |
75 | | - file_h = open(in_file) |
76 | | - root = BeautifulSoup(file_h, 'xml') |
77 | | - file_h.close() |
| 74 | + debug_overview('# Getting from XML \'{}\' KiCad BoM...'.format(os.path.basename(in_file))) |
| 75 | + # KiCad uses UTF-8 encoding, some broken Python setups uses CP1252 (see #581) |
| 76 | + with open(in_file, 'rb') as f: |
| 77 | + xml = f.read() |
| 78 | + res = re.search(rb'encoding\s*=\s*"(.*)"', xml) |
| 79 | + assert res, "Broken XML, no encoding declared" |
| 80 | + encoding = res.group(1).decode() |
| 81 | + debug_obsessive('XML encoding: {}'.format(encoding)) |
| 82 | + xml_s = xml.decode(encoding) |
| 83 | + |
| 84 | + root = BeautifulSoup(xml_s, 'xml') |
78 | 85 |
|
79 | 86 | # Get the general information of the project BoM XML file. |
80 | 87 | debug_overview('Getting authorship data...') |
|
0 commit comments