267 data = self._read_raw_data(file_obj) |
268 data = self._read_raw_data(file_obj) |
268 |
269 |
269 self._lines = self._arcs = None |
270 self._lines = self._arcs = None |
270 |
271 |
271 if 'lines' in data: |
272 if 'lines' in data: |
272 self._lines = data['lines'] |
273 self._lines = dict( |
|
274 (fname.encode(sys.getfilesystemencoding()), linenos) |
|
275 for fname, linenos in iitems(data['lines']) |
|
276 ) |
|
277 |
273 if 'arcs' in data: |
278 if 'arcs' in data: |
274 self._arcs = dict( |
279 self._arcs = dict( |
275 (fname, [tuple(pair) for pair in arcs]) |
280 (fname.encode(sys.getfilesystemencoding()), |
|
281 [tuple(pair) for pair in arcs]) |
276 for fname, arcs in iitems(data['arcs']) |
282 for fname, arcs in iitems(data['arcs']) |
277 ) |
283 ) |
278 self._file_tracers = data.get('file_tracers', {}) |
284 self._file_tracers = data.get('file_tracers', {}) |
279 self._runs = data.get('runs', []) |
285 self._runs = data.get('runs', []) |
280 |
286 |
282 |
288 |
283 def read_file(self, filename): |
289 def read_file(self, filename): |
284 """Read the coverage data from `filename` into this object.""" |
290 """Read the coverage data from `filename` into this object.""" |
285 if self._debug and self._debug.should('dataio'): |
291 if self._debug and self._debug.should('dataio'): |
286 self._debug.write("Reading data from %r" % (filename,)) |
292 self._debug.write("Reading data from %r" % (filename,)) |
287 try: |
293 with self._open_for_reading(filename) as f: |
288 with self._open_for_reading(filename) as f: |
294 self.read_fileobj(f) |
289 self.read_fileobj(f) |
|
290 except Exception as exc: |
|
291 raise CoverageException( |
|
292 "Couldn't read data from '%s': %s: %s" % ( |
|
293 filename, exc.__class__.__name__, exc, |
|
294 ) |
|
295 ) |
|
296 |
295 |
297 _GO_AWAY = "!coverage.py: This is a private format, don't read it directly!" |
296 _GO_AWAY = "!coverage.py: This is a private format, don't read it directly!" |
298 |
297 |
299 @classmethod |
298 @classmethod |
300 def _open_for_reading(cls, filename): |
299 def _open_for_reading(cls, filename): |
432 |
431 |
433 # Create the file data. |
432 # Create the file data. |
434 file_data = {} |
433 file_data = {} |
435 |
434 |
436 if self._has_arcs(): |
435 if self._has_arcs(): |
437 file_data['arcs'] = self._arcs |
436 file_data['arcs'] = dict( |
|
437 (fname.decode(sys.getfilesystemencoding()), |
|
438 [tuple(pair) for pair in self._arcs]) |
|
439 for fname, arcs in iitems(data['arcs']) |
|
440 ) |
438 |
441 |
439 if self._has_lines(): |
442 if self._has_lines(): |
440 file_data['lines'] = self._lines |
443 file_data['lines'] = dict( |
|
444 (fname.decode(sys.getfilesystemencoding()), linenos) |
|
445 for fname, linenos in iitems(self._lines) |
|
446 ) |
441 |
447 |
442 if self._file_tracers: |
448 if self._file_tracers: |
443 file_data['file_tracers'] = self._file_tracers |
449 file_data['file_tracers'] = self._file_tracers |
444 |
450 |
445 if self._runs: |
451 if self._runs: |