objectquery: simplify closing of file objects

This takes advantage of the file context manager (`with`) to simplify
closure of files. This patch removes several explicit `fp.close()`
statements.
Merge pull request #132 from larsbutler/simplify-fp-handling

objectquery: simplify closing of file objects