Overridable: return a readable & writable file. The file will be used as follows: - data is written to it - seek(0) - data is read from it The file is opened in binary mode for files, in text mode for other fields This version open
(self)
| 817 | last_line_lfend = line.endswith(b'\n') |
| 818 | |
| 819 | def make_file(self): |
| 820 | """Overridable: return a readable & writable file. |
| 821 | |
| 822 | The file will be used as follows: |
| 823 | - data is written to it |
| 824 | - seek(0) |
| 825 | - data is read from it |
| 826 | |
| 827 | The file is opened in binary mode for files, in text mode |
| 828 | for other fields |
| 829 | |
| 830 | This version opens a temporary file for reading and writing, |
| 831 | and immediately deletes (unlinks) it. The trick (on Unix!) is |
| 832 | that the file can still be used, but it can't be opened by |
| 833 | another process, and it will automatically be deleted when it |
| 834 | is closed or when the current process terminates. |
| 835 | |
| 836 | If you want a more permanent file, you derive a class which |
| 837 | overrides this method. If you want a visible temporary file |
| 838 | that is nevertheless automatically deleted when the script |
| 839 | terminates, try defining a __del__ method in a derived class |
| 840 | which unlinks the temporary files you have created. |
| 841 | |
| 842 | """ |
| 843 | if self._binary_file: |
| 844 | return tempfile.TemporaryFile("wb+") |
| 845 | else: |
| 846 | return tempfile.TemporaryFile("w+", |
| 847 | encoding=self.encoding, newline = '\n') |
| 848 | |
| 849 | |
| 850 | # Test/debug code |
no outgoing calls
no test coverage detected