← Back to team overview

dulwich-users team mailing list archive

[PATCH 7/9] file: Don't error when creating GitFiles with the default mode.

 

From: Dave Borowitz <dborowitz@xxxxxxxxxx>

Change-Id: I43708186fe73ae20aca8dce95887c4bdd114c3bc
---
 NEWS                       |    2 ++
 dulwich/file.py            |    2 +-
 dulwich/tests/test_file.py |    5 +++++
 3 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/NEWS b/NEWS
index 379d3bd..d0e9042 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@
 
   * HTTP server correctly handles empty CONTENT_LENGTH. (Dave Borowitz)
 
+  * Don't error when creating GitFiles with the default mode. (Dave Borowitz)
+
  FEATURES
 
   * Use slots for core objects to save up on memory. (Jelmer Vernooij)
diff --git a/dulwich/file.py b/dulwich/file.py
index dd0fbb0..7228fc2 100644
--- a/dulwich/file.py
+++ b/dulwich/file.py
@@ -60,7 +60,7 @@ def fancy_rename(oldname, newname):
     os.remove(tmpfile)
 
 
-def GitFile(filename, mode='r', bufsize=-1):
+def GitFile(filename, mode='rb', bufsize=-1):
     """Create a file object that obeys the git file locking protocol.
 
     :return: a builtin file object or a _GitFile object
diff --git a/dulwich/tests/test_file.py b/dulwich/tests/test_file.py
index 8deb987..f154a57 100644
--- a/dulwich/tests/test_file.py
+++ b/dulwich/tests/test_file.py
@@ -119,6 +119,11 @@ class GitFileTests(TestCase):
         self.assertEquals('contents', f.read())
         f.close()
 
+    def test_default_mode(self):
+        f = GitFile(self.path('foo'))
+        self.assertEquals('foo contents', f.read())
+        f.close()
+
     def test_write(self):
         foo = self.path('foo')
         foo_lock = '%s.lock' % foo
-- 
1.7.1




References