Return a Message representation or raise a KeyError.
(self, key)
| 1269 | self._labels[key] = message.get_labels() |
| 1270 | |
| 1271 | def get_message(self, key): |
| 1272 | """Return a Message representation or raise a KeyError.""" |
| 1273 | start, stop = self._lookup(key) |
| 1274 | self._file.seek(start) |
| 1275 | self._file.readline() # Skip b'1,' line specifying labels. |
| 1276 | original_headers = io.BytesIO() |
| 1277 | while True: |
| 1278 | line = self._file.readline() |
| 1279 | if line == b'*** EOOH ***' + linesep or not line: |
| 1280 | break |
| 1281 | original_headers.write(line.replace(linesep, b'\n')) |
| 1282 | visible_headers = io.BytesIO() |
| 1283 | while True: |
| 1284 | line = self._file.readline() |
| 1285 | if line == linesep or not line: |
| 1286 | break |
| 1287 | visible_headers.write(line.replace(linesep, b'\n')) |
| 1288 | # Read up to the stop, or to the end |
| 1289 | n = stop - self._file.tell() |
| 1290 | assert n >= 0 |
| 1291 | body = self._file.read(n) |
| 1292 | body = body.replace(linesep, b'\n') |
| 1293 | msg = BabylMessage(original_headers.getvalue() + body) |
| 1294 | msg.set_visible(visible_headers.getvalue()) |
| 1295 | if key in self._labels: |
| 1296 | msg.set_labels(self._labels[key]) |
| 1297 | return msg |
| 1298 | |
| 1299 | def get_bytes(self, key): |
| 1300 | """Return a string representation or raise a KeyError.""" |
nothing calls this directly
no test coverage detected