@property
    def checksum(self):
        """The checksum of the file or directory."""
        rv = self._checksum
        if rv is not None:
            return rv

        try:
            h = hashlib.sha1()
            if os.path.isdir(self.filename):
                h.update(b'DIR\x00')
                for filename in sorted(os.listdir(self.filename)):
                    if self.env.is_uninteresting_source_name(filename):
                        continue
                    if isinstance(filename, unicode):
                        filename = filename.encode('utf-8')
                    h.update(filename)
                    h.update(_describe_fs_path_for_checksum(
                        os.path.join(self.filename, filename)))
                    h.update(b'\x00')
            else:
                with open(self.filename, 'rb') as f:
                    while 1:
                        chunk = f.read(16 * 1024)
                        if not chunk:
                            break
                        h.update(chunk)
            checksum = h.hexdigest()
        except (OSError, __HOLE__):
            checksum = '0' * 40
        self._checksum = checksum
        return checksum
dataset/ETHPy150Open lektor/lektor/lektor/builder.py/FileInfo.checksum