diff options
author | Devan Franchini <twitch153@gentoo.org> | 2014-05-14 17:33:55 -0400 |
---|---|---|
committer | Devan Franchini <twitch153@gentoo.org> | 2014-06-12 00:12:40 -0400 |
commit | 17220d550f58a3ede3d4dfb95e6c2ccf1108519f (patch) | |
tree | 54881c58897b45bbb7944a12be4d7fc858bada6a /layman | |
parent | api.py: Corrects output of repos (diff) | |
download | layman-17220d550f58a3ede3d4dfb95e6c2ccf1108519f.tar.gz layman-17220d550f58a3ede3d4dfb95e6c2ccf1108519f.tar.bz2 layman-17220d550f58a3ede3d4dfb95e6c2ccf1108519f.zip |
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.
Diffstat (limited to 'layman')
-rw-r--r-- | layman/output.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/layman/output.py b/layman/output.py index d4ee148..10250d8 100644 --- a/layman/output.py +++ b/layman/output.py @@ -17,6 +17,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 @@ -32,13 +37,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") |