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