def _encode_auth(auth):
 auth_s = unquote(auth)
 auth_bytes = auth_s.encode()
 encoded_bytes = base64.encodestring(auth_bytes)
 encoded = encoded_bytes.decode()
 return encoded.replace('\n', '')

def _encode_auth ( auth ) : auth_s = unquote ( auth ) auth_bytes = auth_s . encode ( ) encoded_bytes = base64 . encodestring ( auth_bytes ) encoded = encoded_bytes . decode ( ) return encoded . replace ( '\n' , '' )
a function compatible with python 2 .