'Context manager to create a file. We create a temporary file first, and
then return a DiskFileWriter object to encapsulate the state.
.. note::
An implementation is not required to perform on-disk
preallocations even if the parameter is specified. But if it does
and it fails, it must raise a `DiskFileNoSpace` exception.
:param size: optional initial size of file to explicitly allocate on
disk
:raises DiskFileNoSpace: if a size is specified and allocation fails'

@contextmanager
def create(self, size=None):

    try:
        (fd, tmppath) = self._get_tempfile()
    except OSError as err:
        if (err.errno in (errno.ENOSPC, errno.EDQUOT)):
            raise DiskFileNoSpace()
        raise
    dfw = None
    try:
        if ((size is not None) and (size > 0)):
            try:
                fallocate(fd, size)
            except OSError as err:
                if (err.errno in (errno.ENOSPC, errno.EDQUOT)):
                    raise DiskFileNoSpace()
                raise
        dfw = self.writer_cls(self._name, self._datadir, fd, tmppath, bytes_per_sync=self._bytes_per_sync, diskfile=self, next_part_power=self.next_part_power)
        (yield dfw)
    finally:
        try:
            os.close(fd)
        except OSError:
            pass
        if ((dfw is None) or (not dfw.put_succeeded)):
            try:
                if tmppath:
                    os.unlink(tmppath)
            except OSError:
                self._logger.exception(('Error    removing    tempfile:    %s' % tmppath))
