Esempio n. 1
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_READ)
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     m.write_byte("x")
     m.seek(0)
     assert m.read(6) == "xoobar"
     m.close()
Esempio n. 2
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_READ)
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     m.write_byte("x")
     m.seek(0)
     assert m.read(6) == "xoobar"
     m.close()
Esempio n. 3
0
        def func(no):

            try:
                mmap.mmap(no, 123)
            except RValueError:
                pass
            else:
                raise Exception("didn't raise")
Esempio n. 4
0
        def func(no):

            try:
                mmap.mmap(no, 123)
            except RValueError:
                pass
            else:
                raise Exception("didn't raise")
Esempio n. 5
0
 def func():
     m = mmap.mmap(-1, 1000, tagname="foo")
     # same tagname, but larger size
     try:
         m2 = mmap.mmap(-1, 5000, tagname="foo")
         m2.getitem(4500)
     except WindowsError:
         pass
     m.close()
Esempio n. 6
0
 def func():
     m = mmap.mmap(-1, 1000, tagname="foo")
     # same tagname, but larger size
     try:
         m2 = mmap.mmap(-1, 5000, tagname="foo")
         m2.getitem(4500)
     except WindowsError:
         pass
     m.close()
Esempio n. 7
0
 def func(no):
     m = mmap.mmap(no, 6)
     assert m.getitem(0) == 'f'
     assert m.getitem(-1) == 'r'
 # sl = slice(1, 2)
 # assert m.get_item(sl) == 'o'
     m.close()
Esempio n. 8
0
 def func(no):
     m = mmap.mmap(no, 6)
     assert m.getitem(0) == 'f'
     assert m.getitem(-1) == 'r'
     # sl = slice(1, 2)
     # assert m.get_item(sl) == 'o'
     m.close()
Esempio n. 9
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     f_size = os.fstat(no).st_size
     assert intmask(m.file_size()) == f_size == 6
     m.resize(10)
     f_size = os.fstat(no).st_size
     assert intmask(m.file_size()) == f_size == 10
     m.close()
Esempio n. 10
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     f_size = os.fstat(no).st_size
     assert intmask(m.file_size()) == f_size == 6
     m.resize(10)
     f_size = os.fstat(no).st_size
     assert intmask(m.file_size()) == f_size == 10
     m.close()
Esempio n. 11
0
 def func(no):
     m = mmap.mmap(no, 12)
     assert m.find("\0", 0, 13) == -1  # no searching past the stop
     assert m.find("\0", 0, 13, True) == -1
     m.close()
     #
     m = mmap.mmap(no, 13)
     assert m.find("b", 0, 7) == 3
     assert m.find("z", 0, 7) == -1
     assert m.find("o", 11, 13) == -1
     assert m.find("ob", 0, 7) == 2
     assert m.find("\0", 0, 13) == 12
     assert m.find("o", 1, 4) == 1
     assert m.find("o", 2, 4) == 2
     assert m.find("o", 2, -4) == 2
     assert m.find("o", 8, -5) == -1
     m.close()
Esempio n. 12
0
 def func(no):
     m = mmap.mmap(no, 12)
     assert m.find("\0", 0, 13) == -1    # no searching past the stop
     assert m.find("\0", 0, 13, True) == -1
     m.close()
     #
     m = mmap.mmap(no, 13)
     assert m.find("b", 0, 7) == 3
     assert m.find("z", 0, 7) == -1
     assert m.find("o", 11, 13) == -1
     assert m.find("ob", 0, 7) == 2
     assert m.find("\0", 0, 13) == 12
     assert m.find("o", 1, 4) == 1
     assert m.find("o", 2, 4) == 2
     assert m.find("o", 2, -4) == 2
     assert m.find("o", 8, -5) == -1
     m.close()
Esempio n. 13
0
def readline_mmap(f):
    handle = rmmap.mmap(f.fileno(), 0, access=rmmap.ACCESS_READ)
    for i in xrange(handle.size):
        line = handle.readline()
        if line != '':
            yield line
        else:
            break
Esempio n. 14
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     m.move(1, 3, 3)
     assert m.read(6) == "fbarar"
     m.seek(0)
     m.move(1, 3, 2)
     a = m.read(6)
     assert a == "frarar"
     m.close()
Esempio n. 15
0
 def func(no):
     m = mmap.mmap(no, 4)
     if os.name == "nt":
         # windows replaces \n with \r. it's time to change to \n only MS!
         assert m.readline() == "foo\r"
     elif os.name == "posix":
         assert m.readline() == "foo\n"
     assert m.readline() == ""
     m.close()
Esempio n. 16
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     m.move(1, 3, 3)
     assert m.read(6) == "fbarar"
     m.seek(0)
     m.move(1, 3, 2)
     a = m.read(6)
     assert a == "frarar"
     m.close()
Esempio n. 17
0
 def func(no):
     m = mmap.mmap(no, 1)
     m.close()
     try:
         m.check_valid()
     except RValueError:
         pass
     else:
         raise Exception("Did not raise")
Esempio n. 18
0
 def mmap(space, w_subtype, fileno, length, tagname="",
          access=rmmap._ACCESS_DEFAULT, offset=0):
     self = space.allocate_instance(W_MMap, w_subtype)
     try:
         W_MMap.__init__(self, space,
                         rmmap.mmap(fileno, length, tagname, access,
                                    offset))
     except OSError, e:
         raise mmap_error(space, e)
Esempio n. 19
0
 def func(no):
     m = mmap.mmap(no, 1)
     m.close()
     try:
         m.check_valid()
     except RValueError:
         pass
     else:
         raise Exception("Did not raise")
Esempio n. 20
0
 def func(no):
     m = mmap.mmap(no, 4)
     if os.name == "nt":
         # windows replaces \n with \r. it's time to change to \n only MS!
         assert m.readline() == "foo\r"
     elif os.name == "posix":
         assert m.readline() == "foo\n"
     assert m.readline() == ""
     m.close()
Esempio n. 21
0
 def mmap(space, w_subtype, fileno, length, flags=rmmap.MAP_SHARED,
          prot=rmmap.PROT_WRITE | rmmap.PROT_READ,
          access=rmmap._ACCESS_DEFAULT, offset=0):
     self = space.allocate_instance(W_MMap, w_subtype)
     try:
         W_MMap.__init__(self, space,
                         rmmap.mmap(fileno, length, flags, prot, access,
                                    offset))
     except OSError, e:
         raise mmap_error(space, e)
Esempio n. 22
0
 def func(no):
     m = mmap.mmap(no, 1)
     assert m.read_byte() == "c"
     try:
         m.read_byte()
     except RValueError:
         pass
     else:
         raise Exception("Did not raise")
     m.close()
Esempio n. 23
0
 def test_write_readonly(self):
     if os.name == "nt":
         py.test.skip("Needs PROT_READ")
     f = open(self.tmpname + "l", "w+")
     f.write("foobar")
     f.flush()
     m = mmap.mmap(f.fileno(), 6, prot=mmap.PROT_READ)
     py.test.raises(RTypeError, m.check_writeable)
     m.close()
     f.close()
Esempio n. 24
0
 def test_write_readonly(self):
     if os.name == "nt":
         py.test.skip("Needs PROT_READ")
     f = open(self.tmpname + "l", "w+")
     f.write("foobar")
     f.flush()
     m = mmap.mmap(f.fileno(), 6, prot=mmap.PROT_READ)
     py.test.raises(RTypeError, m.check_writeable)
     m.close()
     f.close()
Esempio n. 25
0
 def func(no):
     m = mmap.mmap(no, 1)
     assert m.read_byte() == "c"
     try:
         m.read_byte()
     except RValueError:
         pass
     else:
         raise Exception("Did not raise")
     m.close()
Esempio n. 26
0
 def func(no):
     m = mmap.mmap(no, 6)
     m.seek(0)
     assert m.tell() == 0
     m.read(1)
     m.seek(1, 1)
     assert m.tell() == 2
     m.seek(0)
     m.seek(-1, 2)
     assert m.tell() == 5
     m.close()
Esempio n. 27
0
 def func(no):
     m = mmap.mmap(no, 6)
     m.seek(0)
     assert m.tell() == 0
     m.read(1)
     m.seek(1, 1)
     assert m.tell() == 2
     m.seek(0)
     m.seek(-1, 2)
     assert m.tell() == 5
     m.close()
Esempio n. 28
0
 def test_write_without_protwrite(self):
     if os.name == "nt":
         py.test.skip("Needs PROT_WRITE")
     f = open(self.tmpname + "l2", "w+")
     f.write("foobar")
     f.flush()
     m = mmap.mmap(f.fileno(), 6, prot=mmap.PROT_READ|mmap.PROT_EXEC)
     py.test.raises(RTypeError, m.check_writeable)
     py.test.raises(RTypeError, m.check_writeable)
     m.close()
     f.close()
Esempio n. 29
0
 def test_write_without_protwrite(self):
     if os.name == "nt":
         py.test.skip("Needs PROT_WRITE")
     f = open(self.tmpname + "l2", "w+")
     f.write("foobar")
     f.flush()
     m = mmap.mmap(f.fileno(), 6, prot=mmap.PROT_READ | mmap.PROT_EXEC)
     py.test.raises(RTypeError, m.check_writeable)
     py.test.raises(RTypeError, m.check_writeable)
     m.close()
     f.close()
Esempio n. 30
0
 def mmap(space, w_subtype, fileno, length, tagname="",
          access=rmmap._ACCESS_DEFAULT, offset=0):
     self = space.allocate_instance(W_MMap, w_subtype)
     try:
         W_MMap.__init__(self, space,
                         rmmap.mmap(fileno, length, tagname, access,
                                    offset))
     except OSError as e:
         raise mmap_error(space, e)
     except RMMapError as e:
         raise mmap_error(space, e)
     return self
Esempio n. 31
0
 def mmap(space, w_subtype, fileno, length, flags=rmmap.MAP_SHARED,
          prot=rmmap.PROT_WRITE | rmmap.PROT_READ,
          access=rmmap._ACCESS_DEFAULT, offset=0):
     self = space.allocate_instance(W_MMap, w_subtype)
     try:
         W_MMap.__init__(self, space,
                         rmmap.mmap(fileno, length, flags, prot, access,
                                    offset))
     except OSError as e:
         raise mmap_error(space, e)
     except RMMapError as e:
         raise mmap_error(space, e)
     return self
Esempio n. 32
0
        def func(no):
            m = mmap.mmap(no, size*4096)
            m.unmap_range(left*4096, (right-left)*4096)
            m.read(1)
            m.seek(right*4096)
            m.read(1)

            def in_map(m, offset):
                return rffi.ptradd(m.data, offset)
            def as_num(ptr):
                return rffi.cast(lltype.Unsigned, ptr)
            res = mmap.alloc_hinted(in_map(m, (left+right)/2 * 4096), 4096)
            assert as_num(in_map(m, left*4096)) <= as_num(res) < as_num(in_map(m, right*4096))
Esempio n. 33
0
        def func(no):
            m = mmap.mmap(no, size*4096)
            m.unmap_range(left*4096, (right-left)*4096)
            m.read(1)
            m.seek(right*4096)
            m.read(1)

            def in_map(m, offset):
                return rffi.ptradd(m.data, offset)
            def as_num(ptr):
                return rffi.cast(lltype.Unsigned, ptr)
            res = mmap.alloc_hinted(in_map(m, (left+right)/2 * 4096), 4096)
            assert as_num(in_map(m, left*4096)) <= as_num(res) < as_num(in_map(m, right*4096))
Esempio n. 34
0
    def test_windows_crasher_2(self):
        if sys.platform != "win32":
            py.test.skip("Windows-only test")

        f = open(self.tmpname + "t", "w+")
        f.write("foobar")
        f.flush()

        f = open(self.tmpname + "t", "r+b")
        m = mmap.mmap(f.fileno(), 0)
        f.close()
        py.test.raises(WindowsError, m.resize, 0)
        py.test.raises(RValueError, m.getitem, 0)
        m.close()
Esempio n. 35
0
    def test_windows_crasher_2(self):
        if sys.platform != "win32":
            py.test.skip("Windows-only test")

        f = open(self.tmpname + "t", "w+")
        f.write("foobar")
        f.flush()

        f = open(self.tmpname + "t", "r+b")
        m = mmap.mmap(f.fileno(), 0)
        f.close()
        py.test.raises(WindowsError, m.resize, 0)
        py.test.raises(RValueError, m.getitem, 0)
        m.close()
Esempio n. 36
0
    def test_find_rfind(self):
        f = open(self.tmpname + "g", "w+")
        f.write("foobarfoobar\0")
        f.flush()
        m = mmap.mmap(f.fileno(), 13)

        for s1 in range(-20, 20):
            for e1 in range(-20, 20):
                expected = "foobarfoobar\0".find("ob", s1, e1)
                assert m.find("ob", s1, e1, False) == expected
                expected = "foobarfoobar\0".rfind("ob", s1, e1)
                assert m.find("ob", s1, e1, True) == expected

        m.close()
        f.close()
Esempio n. 37
0
    def test_find_rfind(self):
        f = open(self.tmpname + "g", "w+")
        f.write("foobarfoobar\0")
        f.flush()
        m = mmap.mmap(f.fileno(), 13)

        for s1 in range(-20, 20):
            for e1 in range(-20, 20):
                expected = "foobarfoobar\0".find("ob", s1, e1)
                assert m.find("ob", s1, e1, False) == expected
                expected = "foobarfoobar\0".rfind("ob", s1, e1)
                assert m.find("ob", s1, e1, True) == expected

        m.close()
        f.close()
Esempio n. 38
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_READ)
     try:
         m.check_writeable()
     except RTypeError:
         pass
     else:
         assert False
     try:
         m.check_resizeable()
     except RTypeError:
         pass
     else:
         assert False
     m.close()
Esempio n. 39
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_READ)
     try:
         m.check_writeable()
     except RTypeError:
         pass
     else:
         assert False
     try:
         m.check_resizeable()
     except RTypeError:
         pass
     else:
         assert False
     m.close()
Esempio n. 40
0
        def func(no):
            m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)

            # def f(m): m[1:3] = u'xx'
            # py.test.raises(IndexError, f, m)
            # def f(m): m[1:4] = "zz"
            # py.test.raises(IndexError, f, m)
            # def f(m): m[1:6] = "z" * 6
            # py.test.raises(IndexError, f, m)
            # def f(m): m[:2] = "z" * 5
            # m[1:3] = 'xx'
            # assert m.read(6) == "fxxbar"
            # m.seek(0)
            m.setitem(0, 'x')
            assert m.getitem(0) == 'x'
            m.setitem(-6, 'y')
            data = m.read(6)
            assert data == "yoobar" # yxxbar with slice's stuff
            m.close()
Esempio n. 41
0
        def func(no):
            m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)

            # def f(m): m[1:3] = u'xx'
            # py.test.raises(IndexError, f, m)
            # def f(m): m[1:4] = "zz"
            # py.test.raises(IndexError, f, m)
            # def f(m): m[1:6] = "z" * 6
            # py.test.raises(IndexError, f, m)
            # def f(m): m[:2] = "z" * 5
            # m[1:3] = 'xx'
            # assert m.read(6) == "fxxbar"
            # m.seek(0)
            m.setitem(0, 'x')
            assert m.getitem(0) == 'x'
            m.setitem(-6, 'y')
            data = m.read(6)
            assert data == "yoobar"  # yxxbar with slice's stuff
            m.close()
Esempio n. 42
0
 def func(no):
     m = mmap.mmap(no, 6)
     assert m.len() == 6
     m.close()
Esempio n. 43
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     m.write("ciao\n")
     m.seek(0)
     assert m.read(6) == "ciao\nr"
     m.close()
Esempio n. 44
0
 def func(no):
     m = mmap.mmap(no, 5)
     assert m.file_size() == 6 # size of the underline file, not the mmap
     m.close()
Esempio n. 45
0
 def func(no):
     m = mmap.mmap(no, 1)
     assert m.tell() >= 0
     m.close()
Esempio n. 46
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     m.close()
     m.close()  # didn't explode
Esempio n. 47
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     m.close()
     m.close() # didn't explode
Esempio n. 48
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     assert m.write("ciao\n") == 5
     m.seek(0)
     assert m.read(6) == "ciao\nr"
     m.close()
Esempio n. 49
0
 def func(no):
     m = mmap.mmap(no, 1)
     r = m.read_byte()
     m.close()
     return r
Esempio n. 50
0
 def test_madvise(self):
     m = mmap.mmap(-1, 8096)
     m.madvise(mmap.MADV_NORMAL, 0, 8096)
     m.close()
Esempio n. 51
0
 def func(no):
     m = mmap.mmap(no, 6)
     assert m.read(1) == "f"
     assert m.read(6) == "oobar"
     assert m.read(1) == ""
     m.close()
Esempio n. 52
0
 def func(no):
     m = mmap.mmap(no, 1)
     r = m.read_byte()
     m.close()
     return r
Esempio n. 53
0
 def func(no):
     m = mmap.mmap(no, 1)
     assert m.read(99) == "c"
Esempio n. 54
0
 def func(no):
     m = mmap.mmap(no, 6)
     assert m.len() == 6
     m.close()
Esempio n. 55
0
 def func(no):
     m = mmap.mmap(no, 6)
     assert m.read(1) == "f"
     assert m.read(6) == "oobar"
     assert m.read(1) == ""
     m.close()
Esempio n. 56
0
 def func(no):
     m = mmap.mmap(no, 1)
     assert m.read(99) == "c"
Esempio n. 57
0
 def func(no):
     m = mmap.mmap(no, 5)
     assert m.file_size(
     ) == 6  # size of the underline file, not the mmap
     m.close()
Esempio n. 58
0
 def func(no):
     m = mmap.mmap(no, 1)
     assert m.tell() >= 0
     m.close()
Esempio n. 59
0
 def entry_point(argv):
     try:
         res = mmap(0, 1024)
     except OSError:
         return 0
     return 1