Write file contents (synchronous) :param str path: File path to write :param str data: Data to write :param str encoding: File encoding (default: 'utf-8') :returns bool: True if successful, False otherwise
(self, path: str, data: str, encoding: str = 'utf-8')
| 509 | return None |
| 510 | |
| 511 | def write_file(self, path: str, data: str, encoding: str = 'utf-8'): |
| 512 | """ |
| 513 | Write file contents (synchronous) |
| 514 | :param str path: File path to write |
| 515 | :param str data: Data to write |
| 516 | :param str encoding: File encoding (default: 'utf-8') |
| 517 | :returns bool: True if successful, False otherwise |
| 518 | """ |
| 519 | self._ensure_whitelisted_file(path) |
| 520 | try: |
| 521 | with open(path, 'w', encoding=encoding) as file: |
| 522 | file.write(data) |
| 523 | return True |
| 524 | except Exception: |
| 525 | return False |
| 526 | |
| 527 | def exists_file(self, path: str): |
| 528 | """ |