Return a Message representation or raise a KeyError.
(self, key)
| 1343 | self._labels[key] = message.get_labels() |
| 1344 | |
| 1345 | def get_message(self, key): |
| 1346 | """Return a Message representation or raise a KeyError.""" |
| 1347 | start, stop = self._lookup(key) |
| 1348 | self._file.seek(start) |
| 1349 | self._file.readline() # Skip b'1,' line specifying labels. |
| 1350 | original_headers = io.BytesIO() |
| 1351 | while True: |
| 1352 | line = self._file.readline() |
| 1353 | if line == b'*** EOOH ***' + linesep or not line: |
| 1354 | break |
| 1355 | original_headers.write(line.replace(linesep, b'\n')) |
| 1356 | visible_headers = io.BytesIO() |
| 1357 | while True: |
| 1358 | line = self._file.readline() |
| 1359 | if line == linesep or not line: |
| 1360 | break |
| 1361 | visible_headers.write(line.replace(linesep, b'\n')) |
| 1362 | # Read up to the stop, or to the end |
| 1363 | n = stop - self._file.tell() |
| 1364 | assert n >= 0 |
| 1365 | body = self._file.read(n) |
| 1366 | body = body.replace(linesep, b'\n') |
| 1367 | msg = BabylMessage(original_headers.getvalue() + body) |
| 1368 | msg.set_visible(visible_headers.getvalue()) |
| 1369 | if key in self._labels: |
| 1370 | msg.set_labels(self._labels[key]) |
| 1371 | return msg |
| 1372 | |
| 1373 | def get_bytes(self, key): |
| 1374 | """Return a string representation or raise a KeyError.""" |
nothing calls this directly
no test coverage detected