Matt Chaput  committed 47066c5

Make sure a file has a fileno() method before trying to call it.

  • Participants
  • Parent commits eb487af
  • Branches default

Comments (0)

Files changed (1)

File src/whoosh/filedb/

             if hasattr(fileobj, attr):
                 setattr(self, attr, getattr(fileobj, attr))
+        self.is_real = not gzip and hasattr(fileobj, "fileno")
         # If mapped is True, set the 'map' attribute to a memory-mapped
         # representation of the file. Otherwise, the fake 'map' that set up by
         # the base class will be used.
-        if not gzip and mapped and hasattr(fileobj, "mode") and "r" in fileobj.mode:
+        if (mapped and self.is_real
+            and hasattr(fileobj, "mode") and "r" in fileobj.mode):
             fd = fileobj.fileno()
             self.size = os.fstat(fd).st_size
             if self.size > 0:
-        self.is_real = not gzip and hasattr(fileobj, "fileno")
     def __repr__(self):
         return "%s(%r)" % (self.__class__.__name__, self._name)