Skip to content

Commit

Permalink
update to new canmatrix API and fix using BytesIO object when calling…
Browse files Browse the repository at this point in the history
… _load_
  • Loading branch information
danielhrisca committed May 17, 2019
1 parent d0d1855 commit 0370483
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions asammdf/blocks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import xml.etree.ElementTree as ET
import re
import subprocess
from io import BytesIO

from collections import namedtuple
from functools import partial
Expand Down Expand Up @@ -1525,12 +1526,13 @@ def load_can_database(file, contents=None):
loads = dbc_load if import_type == 'dbc' else arxml_load
if contents is None:
contents = file.read_bytes()
contents = BytesIO(contents)
try:
dbc = loads(
contents,
import_type=import_type,
key="db",
)["db"]
)
except UnicodeDecodeError:
encoding = detect(contents)["encoding"]
contents = contents.decode(
Expand All @@ -1542,6 +1544,6 @@ def load_can_database(file, contents=None):
import_type=import_type,
key="db",
encoding=encoding,
)["db"]
)

return dbc

0 comments on commit 0370483

Please sign in to comment.