Python 2.4+ compat

Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
Properly close pack files on exceptions.

Cherry-picked from max0d41 @ GitHub.

Signed-off-by: Jelmer Vernooij <jelmer@samba.org>