Add dunder syntax to check if resource is valid

Added both __nonzero__ and __bool__ for portability.