Skip to content

Commit 49afa88

Browse files
committed
SVD: catch KeyError to show warning if builtin SVD was not in svd_data.zip.
1 parent 83238c5 commit 49afa88

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

pyocd/debug/svd/loader.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import zipfile
2121

2222
from .parser import SVDParser
23-
from ...utility.compatibility import FileNotFoundError
23+
from ...utility.compatibility import (
24+
FileNotFoundError,
25+
BadZipFile,
26+
)
2427

2528
LOG = logging.getLogger(__name__)
2629

@@ -34,7 +37,7 @@ def from_builtin(cls, svd_name):
3437
zip_stream = pkg_resources.resource_stream("pyocd", BUILTIN_SVD_DATA_PATH)
3538
zip = zipfile.ZipFile(zip_stream, 'r')
3639
return SVDFile(zip.open(svd_name))
37-
except (FileNotFoundError, BadZipFile) as err:
40+
except (KeyError, FileNotFoundError, BadZipFile) as err:
3841
from ...core.session import Session
3942
LOG.warning("unable to open builtin SVD file: %s", err, exc_info=Session.get_current().log_tracebacks)
4043
return None

pyocd/target/pack/cmsis_pack.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@
2525
import six
2626
import struct
2727

28-
# zipfile from Python 2 has a misspelled BadZipFile exception class.
29-
try:
30-
from zipfile import BadZipFile
31-
except ImportError:
32-
from zipfile import BadZipfile as BadZipFile
33-
3428
from .flash_algo import PackFlashAlgo
3529
from ... import core
3630
from ...core import exceptions
3731
from ...core.target import Target
3832
from ...core.memory_map import (MemoryMap, MemoryType, MEMORY_TYPE_CLASS_MAP, FlashRegion)
33+
from ...utility.compatibility import BadZipFile
3934

4035
LOG = logging.getLogger(__name__)
4136

pyocd/utility/compatibility.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def to_str_safe(v):
6666
except NameError:
6767
FileNotFoundError = OSError
6868

69+
# zipfile from Python 2 has a misspelled BadZipFile exception class.
70+
try:
71+
from zipfile import BadZipFile
72+
except ImportError:
73+
from zipfile import BadZipfile as BadZipFile
74+
6975
try:
7076
from shutil import get_terminal_size
7177
except ImportError:

0 commit comments

Comments
 (0)