Make usage of open safer by setting binary mode and closing fds

Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/git_config.py b/git_config.py
index 7aad80d..7e642a4 100644
--- a/git_config.py
+++ b/git_config.py
@@ -219,7 +219,11 @@
       return None
     try:
       Trace(': unpickle %s', self.file)
-      return cPickle.load(open(self._pickle, 'r'))
+      fd = open(self._pickle, 'rb')
+      try:
+        return cPickle.load(fd)
+      finally:
+        fd.close()
     except IOError:
       os.remove(self._pickle)
       return None
@@ -229,9 +233,11 @@
 
   def _SavePickle(self, cache):
     try:
-      cPickle.dump(cache,
-                   open(self._pickle, 'w'),
-                   cPickle.HIGHEST_PROTOCOL)
+      fd = open(self._pickle, 'wb')
+      try:
+        cPickle.dump(cache, fd, cPickle.HIGHEST_PROTOCOL)
+      finally:
+        fd.close()
     except IOError:
       os.remove(self._pickle)
     except cPickle.PickleError: