Beispiel #1
0
 def mmapopen(fn, mode):
     mmapmode = 0
     filemode = 0
     import mmap
     if "r" in mode:
         mmapmode = mmap.ACCESS_READ
         filemode = os.O_RDONLY
     if "w" in mode:
         mmapmode |= mmap.ACCESS_WRITE
         filemode |= os.O_WRONLY
     fd = os.open(fn, filemode)
     return streamio.MMapFile(fd, mmapmode)
Beispiel #2
0
 def makeStream(self, tell=None, seek=None, bufsize=-1, mode="r"):
     mmapmode = 0
     filemode = 0
     import mmap
     if "r" in mode:
         mmapmode = mmap.ACCESS_READ
         filemode = os.O_RDONLY
     if "w" in mode:
         mmapmode |= mmap.ACCESS_WRITE
         filemode |= os.O_WRONLY
     self.teardown_method(None) # for tests calling makeStream() several time
     self.tfn = str(udir.join('streamio%03d' % TestMMapFile.Counter))
     TestMMapFile.Counter += 1
     f = open(self.tfn, "wb")
     f.writelines(self.packets)
     f.close()
     self.fd = os.open(self.tfn, filemode)
     return streamio.MMapFile(self.fd, mmapmode)