General file validation in python