Ejemplo n.º 1
0
 def write(self, data):
     if self.closed:
         raise ValueError('I/O operation on closed file')
     if not self.allow_write:
         raise vfs.PermissionError('file not opened for writing')
     self._device.write_bytes(self._position, data)
     self._position += len(data)
Ejemplo n.º 2
0
 def read(self, size=None):
     if self.closed:
         raise ValueError('I/O operation on closed file')
     if not self.allow_read:
         raise vfs.PermissionError('file not opened for reading')
     if size is None:
         raise NotImplementError
     else:
         r = self._device.read_bytes(self._position, size)
     self._position += len(r)
     return r
Ejemplo n.º 3
0
 def write(self, data):
     self.check_closed()
     if not self.allow_write:
         raise vfs.PermissionError('file not opened for writing')
     self._node._data = \
         self._node._data[:self._position] \
         + chr(0) * (self._position - len(self._node._data)) \
         + data \
         + self._node._data[self._position+len(data):]
     self._position += len(data)
     return len(data)
Ejemplo n.º 4
0
 def read(self, size=None):
     self.check_closed()
     if not self.allow_read:
         raise vfs.PermissionError('file not opened for reading')
     if size is not None:
         r = self._node._data[self._position:self._position + size]
     elif self._position:
         r = self._node._data[self._position:]
     else:
         r = self._node._data
     self._position += len(r)
     return r
Ejemplo n.º 5
0
 def write_bytes(self, first, count):
     if not self.allow_write:
         raise vfs.PermissionError('file not opened for writing')
     return self._device.write_bytes(first, count)
Ejemplo n.º 6
0
 def read_bytes(self, first, count):
     if not self.allow_read:
         raise vfs.PermissionError('file not opened for reading')
     return self._device.read_bytes(first, count)