commit: 708276267e3d68acdaaf81a57b0f43aa132b9cc1
Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Tue Mar 24 16:09:01 2015 +0000
Commit: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Tue Mar 24 16:09:01 2015 +0000
URL: https://gitweb.gentoo.org/proj/layman.git/commit/?id=70827626
compatibility.py: Adds binary mode aware compatibility to fileopen()
layman/compatibility.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/layman/compatibility.py b/layman/compatibility.py
index 2ef4d8c..67ca3e6 100644
--- a/layman/compatibility.py
+++ b/layman/compatibility.py
@@ -21,7 +21,10 @@ def encode(text, enc="UTF-8"):
def fileopen(path, mode='r', enc="UTF-8"):
"""py2, py3 compatibility function"""
try:
- f = open(path, mode, encoding=enc)
+ if 'b' in mode:
+ f = open(path, mode)
+ else:
+ f = open(path, mode, encoding=enc)
except TypeError:
f = open(path, mode)
return f