faef56c3e7
* py3k: Remove reduce calls. * py3k: Remove compatibility sortList function. Sorting by key has existed since Python 2.4. * Remove unnecessary sys.path manipulation. This file doesn't have any __main__ code to run anyway. * Use context manager
26 lines
542 B
Python
26 lines
542 B
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Helper functions that smooth out the differences between python 2 and 3.
|
|
"""
|
|
import sys
|
|
|
|
def asUnicode(x):
|
|
if sys.version_info[0] == 2:
|
|
if isinstance(x, unicode):
|
|
return x
|
|
elif isinstance(x, str):
|
|
return x.decode('UTF-8')
|
|
else:
|
|
return unicode(x)
|
|
else:
|
|
return str(x)
|
|
|
|
|
|
if sys.version_info[0] == 3:
|
|
basestring = str
|
|
xrange = range
|
|
else:
|
|
import __builtin__
|
|
basestring = __builtin__.basestring
|
|
xrange = __builtin__.xrange
|