1234567891011121314151617181920212223242526 |
- import tempfile
- class AttackContext:
- def __init__(self):
-
-
-
- self.allocated_files = {}
- def allocate_file(self, suffix):
- if suffix in self.allocated_files:
- raise ValueError("File with suffix %s is already allocated" % suffix)
- file = tempfile.NamedTemporaryFile(mode = "w", suffix = suffix, delete = False)
- self.allocated_files[suffix] = file.name
- return file
- def reset(self):
- self.allocated_files.clear()
- def get_allocated_files(self):
- return_ = list(self.allocated_files.items())
- self.allocated_files.clear()
- return return_
|