summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2018-12-10 15:23:47 +0000
committerSimon McVittie <smcv@debian.org>2020-12-19 14:50:10 +0000
commit6ed6fc95c4676a5e69874ec580ce5d9ed989dca2 (patch)
treefb550cadf784195fbed176100459d53cba0381ee
parentcdf1588986293d9191828494c47bd77f30600063 (diff)
Filemap: catch StopIteration from next(iterator)
In Python >= 3.7, if code in a generator raises StopIteration, it is transformed into a RuntimeError instead of terminating the generator gracefully. Bug: https://github.com/intel/bmap-tools/issues/57 Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=915686 Forwarded: https://github.com/intel/bmap-tools/pull/58 Applied-upstream: 3.6, commit:2d3d0aeead0ac1b1f5e9fa5ef351aac8b14b5da9 Gbp-Pq: Name Filemap-catch-StopIteration-from-next-iterator.patch
-rw-r--r--bmaptools/Filemap.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/bmaptools/Filemap.py b/bmaptools/Filemap.py
index 3e56798..e06e654 100644
--- a/bmaptools/Filemap.py
+++ b/bmaptools/Filemap.py
@@ -476,7 +476,11 @@ class FilemapFiemap(_FilemapBase):
_log.debug("FilemapFiemap: get_mapped_ranges(%d, %d(%d))"
% (start, count, start + count - 1))
iterator = self._do_get_mapped_ranges(start, count)
- first_prev, last_prev = next(iterator)
+
+ try:
+ first_prev, last_prev = next(iterator)
+ except StopIteration:
+ return
for first, last in iterator:
if last_prev == first - 1: