'Check this object for internal consistency.
:raise ObjectFormatException: if the object is malformed in some way
:raise ChecksumMismatch: if the object was created with a SHA that does
not match its contents'

def check(self):

    old_sha = self.id
    try:
        self._deserialize(self.as_raw_chunks())
        self._sha = None
        new_sha = self.id
    except Exception as e:
        raise ObjectFormatException(e)
    if (old_sha != new_sha):
        raise ChecksumMismatch(new_sha, old_sha)
