getbinpkg: fix base64 usage for python3
authorZac Medico <zmedico@gentoo.org>
Mon, 14 May 2012 03:29:07 +0000 (20:29 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 14 May 2012 03:29:07 +0000 (20:29 -0700)
pym/portage/getbinpkg.py

index 579a46f9b7eb9a5a6c316aa47012d31cfa185280..7dec20a4418a46ea0b7cf25c6996fd0f5044d4fc 100644 (file)
@@ -158,11 +158,16 @@ def create_conn(baseurl,conn=None):
        http_headers = {}
        http_params = {}
        if username and password:
+               try:
+                       encodebytes = base64.encodebytes
+               except AttributeError:
+                       # Python 2
+                       encodebytes = base64.encodestring
                http_headers = {
-                       "Authorization": "Basic %s" %
-                         base64.encodestring("%s:%s" % (username, password)).replace(
-                           "\012",
-                           ""
+                       b"Authorization": "Basic %s" % \
+                       encodebytes(_unicode_encode("%s:%s" % (username, password))).replace(
+                           b"\012",
+                           b""
                          ),
                }