def py_native_string(source):
 if PY2:
  if isinstance(source, str):
   return source.encode('ascii')
  elif callable(source):
   @functools.wraps(source)
   def new_func(*args, **kwargs):
    rv = source(*args, **kwargs)
    if isinstance(rv, str):
     rv = rv.encode('unicode-escape')
    return rv
   return new_func
 return source

def py_native_string ( source ) : if PY2 : if isinstance ( source , str ) : return source . encode ( 'ascii' ) elif callable ( source ) : @ functools . wraps ( source ) def new_func ( * args , ** kwargs ) : rv = source ( * args , ** kwargs ) if isinstance ( rv , str ) : rv = rv . encode ( 'unicode-escape' ) return rv return new_func return source
converts unicode strings to bytestrings on python 2 .