def _encode_auth(auth):
auth_s = unquote(auth)<EOL>auth_bytes = auth_s.encode()<EOL>encoded_bytes = base64.encodestring(auth_bytes)<EOL>encoded = encoded_bytes.decode()<EOL>return encoded.replace('<STR_LIT:\n>','<STR_LIT>')<EOL>
A function compatible with Python 2.3-3.3 that will encode
auth from a URL suitable for an HTTP header.
>>> str(_encode_auth('username%3Apassword'))
'dXNlcm5hbWU6cGFzc3dvcmQ='

Long auth strings should not cause a newline to be inserted.
>>> long_auth = 'username:' + 'password'*10
>>> chr(10) in str(_encode_auth(long_auth))
False