commit:     b1d97b175f8dd5224e8c7d8ea6275daeda0e134c
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Wed May 14 21:33:55 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Wed May 14 21:33:55 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=b1d97b17

layman/output.py: Adds file output compatibility

In order to allow users to set the output for error and normal
output we need to check to see if users have set the output to be
of type file. In py2 this is specified by the variable "file",
however in py3 this is specified by io.IOBase which encompasses
all file types such as Raw, Text, and Buffered files.

---
 layman/output.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/layman/output.py b/layman/output.py
index ea98894..ef348f5 100644
--- a/layman/output.py
+++ b/layman/output.py
@@ -6,6 +6,7 @@
  Distributed under the terms of the GNU General Public License v2
 """
 
+from __future__ import print_function
 
 __version__ = "0.1"
 
@@ -15,6 +16,11 @@ import sys
 from layman.constants import codes, INFO_LEVEL, WARN_LEVEL, NOTE_LEVEL, 
DEBUG_LEVEL, OFF
 from layman.compatibility import encode
 
+# py3.2
+if sys.hexversion >= 0x30200f0:
+    from io import IOBase as BUILTIN_FILE_TYPE
+else:
+    BUILTIN_FILE_TYPE=file
 
 class MessageBase(object):
     """Base Message class helper functions and variables
@@ -30,13 +36,13 @@ class MessageBase(object):
                  error_callback=None
                  ):
         # Where should the error output go? This can also be a file
-        if isinstance(err, file):
+        if isinstance(err, BUILTIN_FILE_TYPE):
             self.error_out = err
         else:
             raise Exception("MessageBase: input parameter 'err' must be of 
type: file")
 
         # Where should the normal output go? This can also be a file
-        if isinstance(out, file):
+        if isinstance(out, BUILTIN_FILE_TYPE):
             self.std_out = out
         else:
             raise Exception("MessageBase: input parameter 'out' must be of 
type: file")

Reply via email to