changeset 3862:2526b5b8411f

caching: always use binary file mode for file-like api
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 16 Jul 2008 17:53:40 +0200
parents be61d38685f5
children 6d2f6f954c08
files MoinMoin/caching.py
diffstat 1 files changed, 5 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/caching.py	Wed Jul 16 17:46:49 2008 +0200
+++ b/MoinMoin/caching.py	Wed Jul 16 17:53:40 2008 +0200
@@ -154,6 +154,8 @@
 
         @param filename: should be None (default - means to use self._filename())
         @param mode: 'r' (read, default), 'w' (write), 'a' (append)
+                     Note: if mode does not include 'b' (binary), it will be
+                           automatically changed to include 'b'.
         @param bufsize: size of read/write buffer (default: -1 meaning automatic)
         @return: None (the opened file object is kept in self._fileobj and used
                  implicitely by read/write/close functions of CacheEntry object.
@@ -171,6 +173,9 @@
 
         self._lock = self._determine_locktype(mode)
 
+        if 'b' not in mode:
+            mode += 'b'  # we want to use binary mode, ever!
+
         if not self.locking or self.locking and self._lock.acquire(1.0):
             try:
                 self._fileobj = open(filename, mode, bufsize)