def encode_if_py2(func):
 if (not PY2):
  return func
 def wrapped(*args, **kwargs):
  ret = func(*args, **kwargs)
  if (not isinstance(ret, unicode)):
   raise TypeError('Wrapped function must return `unicode`')
  return ret.encode('utf-8', 'ignore')
 return wrapped

def encode_if_py2 ( func ) : if ( not PY2 ) : return func def wrapped ( * args , ** kwargs ) : ret = func ( * args , ** kwargs ) if ( not isinstance ( ret , unicode ) ) : raise TypeError ( 'Wrapped function must return `unicode`' ) return ret . encode ( 'utf-8' , 'ignore' ) return wrapped
if python 2 .