diff --git a/cup/platforms.py b/cup/platforms.py index 345f7b9..ed2e6c4 100644 --- a/cup/platforms.py +++ b/cup/platforms.py @@ -7,13 +7,16 @@ cross-platform functions related module """ +import sys import select import platform __all__ = [ 'is_linux', 'is_windows', - 'is_mac' + 'is_mac', + 'is_py2', + 'is_py3' ] @@ -54,4 +57,22 @@ def is_mac(): return False +def is_py2(): + """ + is python 2.x + """ + if sys.version_info >= (3, 0): + return False + if sys.version_info < (3, 0): + return True + raise ValueError('cannot determine if it\'s python2') + + +def is_py3(): + """is python 3.x""" + if (3, 0) <= sys.version_info <= (4, 0): + return True + else: + return False + # vi:set tw=0 ts=4 sw=4 nowrap fdm=indent diff --git a/cup/shell/oper.py b/cup/shell/oper.py index 044ddf1..a960265 100644 --- a/cup/shell/oper.py +++ b/cup/shell/oper.py @@ -24,9 +24,10 @@ import subprocess import cup -from cup import decorators from cup import err from cup import log +from cup import platforms +from cup import decorators # linux only import @@ -518,6 +519,9 @@ def _signal_handle(): signal.signal(signal.SIGPIPE, signal.SIG_DFL) def _trans_bytes(data): + """trans bytes into unicode for python3""" + if platforms.is_py2(): + return data if isinstance(data, bytes): try: data = bytes.decode(data) diff --git a/cup/version.py b/cup/version.py index 81eddca..00cc021 100644 --- a/cup/version.py +++ b/cup/version.py @@ -13,7 +13,7 @@ ] -VERSION = '3.2.12' +VERSION = '3.2.13' AUTHOR = 'CUP-DEV Team' # vi:set tw=0 ts=4 sw=4 nowrap fdm=indent