(self, filename, contents)
| 2329 | self._reuse_tokens = True |
| 2330 | |
| 2331 | def _write_if_changed(self, filename, contents): |
| 2332 | # Writes 'contents' into 'filename', but only if it differs from the |
| 2333 | # current contents of the file. |
| 2334 | # |
| 2335 | # Another variant would be write a temporary file on the same |
| 2336 | # filesystem, compare the files, and rename() the temporary file if it |
| 2337 | # differs, but it breaks stuff like write_config("/dev/null"), which is |
| 2338 | # used out there to force evaluation-related warnings to be generated. |
| 2339 | # This simple version is pretty failsafe and portable. |
| 2340 | # |
| 2341 | # Returns True if the file has changed and is updated, and False |
| 2342 | # otherwise. |
| 2343 | |
| 2344 | if self._contents_eq(filename, contents): |
| 2345 | return False |
| 2346 | with self._open(filename, "w") as f: |
| 2347 | f.write(contents) |
| 2348 | return True |
| 2349 | |
| 2350 | def _contents_eq(self, filename, contents): |
| 2351 | # Returns True if the contents of 'filename' is 'contents' (a string), |
no test coverage detected