Source code for tools.SecureMmap

import mmap

[docs]class SecureMmap: """In a normal mmap, modifying the string modifies the file. This is a mmap with write protection""" def __init__(self, filename, enableWrite = False) : self.enableWrite = enableWrite self.filename = filename = filename f = open(filename, 'r+b') = mmap.mmap(f.fileno(), 0)
[docs] def forceSet(self, x1, v) : """Forces modification even if the mmap is write protected"""[x1] = v
def __getitem__(self, i): return[i] def __setitem__(self, i, v) : if self.enableWrite : raise IOError("Secure mmap is write protected") else :[i] = v def __str__(self) : return "secure mmap, file: %s, writing enabled : %s" % (self.filename, str(self.enableWrite)) def __len__(self) : return len(