Extract locations from context appropriately. All tests pass.
Chris Pressey
4 years ago
292 | 292 | self.set_written(dest.ref) |
293 | 293 | |
294 | 294 | def extract(self, location): |
295 | """Used in `save`.""" | |
295 | """Sets the given location as writeable in the context, and returns a 'baton' representing | |
296 | the previous state of context for that location. This 'baton' can be used to later restore | |
297 | this state of context.""" | |
298 | # Used in `save`. | |
296 | 299 | baton = ( |
297 | 300 | location, |
298 | 301 | location in self._touched, |
299 | 302 | self._range.get(location, None), |
300 | 303 | location in self._writeable, |
301 | 304 | ) |
302 | ||
303 | if location in self._touched: | |
304 | self._touched.remove(location) | |
305 | self.set_unmeaningful(location) | |
306 | 305 | self.set_writeable(location) |
307 | ||
308 | 306 | return baton |
309 | 307 | |
310 | 308 | def re_introduce(self, baton): |
311 | """Used in `save`.""" | |
309 | """Given a 'baton' produced by `extract()`, restores the context for that saved location | |
310 | to what it was before `extract()` was called.""" | |
311 | # Used in `save`. | |
312 | 312 | location, was_touched, was_range, was_writeable = baton |
313 | 313 | |
314 | 314 | if was_touched: |