def open(name, mode='r', *args, **kwargs): # if name is a mocked file name, lookup corresponding mocked file if name in FILENAMES: if mode == 'w' or name not in FILES: FILES[name] = File(name) return FILES[name] # else call builtin open() else: return builtins.oldopen(name, mode, *args, **kwargs)
def open(name, mode='r', *args, **kwargs): # if name is a mocked file name, lookup corresponding mocked file if name in FILENAMES: if mode == 'w' or name not in FILES: FILES[name] = File(name) return FILES[name] # else call builtin open() else: return builtins.oldopen(name, mode, *args, **kwargs)