From fd4b980c3e29e9677cd4f9a680b4de0e3f9bd6b4 Mon Sep 17 00:00:00 2001 From: Michiel Nauta Date: Tue, 17 May 2011 17:22:03 +0000 Subject: [PATCH] Allow setting mode on opening of file svn: r17519 --- src/gen/plug/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gen/plug/utils.py b/src/gen/plug/utils.py index f72986e82..c32e39f87 100644 --- a/src/gen/plug/utils.py +++ b/src/gen/plug/utils.py @@ -319,16 +319,16 @@ class OpenFileOrStdout: #------------------------------------------------------------------------- class OpenFileOrStdin: """Context manager to open a file or stdin for reading.""" - def __init__(self, filename): + def __init__(self, filename, add_mode=''): self.filename = filename + self.mode = 'r%s' % add_mode self.filehandle = None def __enter__(self): if self.filename == '-': - # TODO how to add U to mode? self.filehandle = sys.stdin else: - self.filehandle = open(self.filename, "rU") + self.filehandle = open(self.filename, self.mode) return self.filehandle def __exit__(self, exc_type, exc_value, traceback):