def __len__(self):
"""
Returns the length of the content
"""
if not self.filepath:
# If there is no filepath, then we're probably dealing with a
# stream in memory like a StringIO or BytesIO stream.
if self.stream:
# Advance to the end of the file
ptr = self.stream.tell()
# Advance to the end of the file and get our length
length = self.stream.seek(0L, SEEK_END)
if length != ptr:
# Return our pointer
self.stream.seek(ptr, SEEK_SET)
else:
# No Stream or Filepath; nothing has been initialized
# yet at all so just return 0
length = 0
else:
if self.stream and self._dirty is True:
self.stream.flush()
self._dirty = False
# Get the size
length = getsize(self.filepath)
return length
评论列表
文章目录