Commit 96fc3908 authored by Baptiste Mispelon's avatar Baptiste Mispelon
Browse files

Fixed a failing test introduced in 918a16bc.

Refs #22307.
parent c94bff2b
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -36,19 +36,26 @@ class File(FileProxyMixin):
    def __len__(self):
        return self.size

    def _get_size(self):
        if not hasattr(self, '_size'):
    def _get_size_from_underlying_file(self):
        if hasattr(self.file, 'size'):
                self._size = self.file.size
            elif hasattr(self.file, 'name') and self.file.name is not None and os.path.exists(self.file.name):
                self._size = os.path.getsize(self.file.name)
            elif hasattr(self.file, 'tell') and hasattr(self.file, 'seek'):
            return self.file.size
        if hasattr(self.file, 'name'):
            try:
                return os.path.getsize(self.file.name)
            except (OSError, TypeError):
                pass
        if hasattr(self.file, 'tell') and hasattr(self.file, 'seek'):
            pos = self.file.tell()
            self.file.seek(0, os.SEEK_END)
                self._size = self.file.tell()
            size = self.file.tell()
            self.file.seek(pos)
            else:
            return size
        raise AttributeError("Unable to determine the file's size.")

    def _get_size(self):
        if hasattr(self, '_size'):
            return self._size
        self._size = self._get_size_from_underlying_file()
        return self._size

    def _set_size(self, size):