mirror of
https://github.com/SickGear/SickGear.git
synced 2024-11-15 17:35:04 +00:00
54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
|
# Copyright: 2013 Paul Traylor
|
||
|
# These sources are released under the terms of the MIT license: see LICENSE
|
||
|
|
||
|
"""
|
||
|
Python2.5 and Python3.3 compatibility shim
|
||
|
|
||
|
Heavily inspirted by the "six" library.
|
||
|
https://pypi.python.org/pypi/six
|
||
|
"""
|
||
|
|
||
|
import sys
|
||
|
|
||
|
PY2 = sys.version_info[0] == 2
|
||
|
PY3 = sys.version_info[0] == 3
|
||
|
|
||
|
if PY3:
|
||
|
def b(s):
|
||
|
if isinstance(s, bytes):
|
||
|
return s
|
||
|
return s.encode('utf8', 'replace')
|
||
|
|
||
|
def u(s):
|
||
|
if isinstance(s, bytes):
|
||
|
return s.decode('utf8', 'replace')
|
||
|
return s
|
||
|
|
||
|
from io import BytesIO as StringIO
|
||
|
# noinspection PyUnresolvedReferences
|
||
|
from configparser import RawConfigParser
|
||
|
else:
|
||
|
def b(s):
|
||
|
# noinspection PyUnresolvedReferences
|
||
|
if isinstance(s, unicode):
|
||
|
return s.encode('utf8', 'replace')
|
||
|
return s
|
||
|
|
||
|
def u(s):
|
||
|
# noinspection PyUnresolvedReferences
|
||
|
if isinstance(s, unicode):
|
||
|
return s
|
||
|
if isinstance(s, int):
|
||
|
s = str(s)
|
||
|
# noinspection PyUnresolvedReferences
|
||
|
return unicode(s, "utf8", "replace")
|
||
|
|
||
|
|
||
|
# noinspection PyUnresolvedReferences
|
||
|
from StringIO import StringIO
|
||
|
# noinspection PyUnresolvedReferences
|
||
|
from ConfigParser import RawConfigParser
|
||
|
|
||
|
b.__doc__ = "Ensure we have a byte string"
|
||
|
u.__doc__ = "Ensure we have a unicode string"
|