Change upload_docs so that its use of base64 does not fail under

Python 3.

While base64 accepts a string in Python 2, the module in Python 3 only
works with bytes. Changed the code so that base64.encodebytes() is
used, else catch the AttributeError and use base64.encodestring(). Not
fully tested yet as there is another failure farther down under under
Python 3.

--HG--
branch : distribute
extra : rebase_source : 37078c416d98ee7f6dff1715731ab3f0c186b6cf
parent 3b04385b
......@@ -75,8 +75,14 @@ class upload_docs(upload):
'content': (os.path.basename(filename), content),
}
# set up the authentication
auth = "Basic " + base64.encodestring(
self.username + ":" + self.password).strip()
credentials = self.username + ':' + self.password
try: # base64 only works with bytes in Python 3.
encoded_creds = base64.encodebytes(credentials.encode('utf8'))
auth = b"Basic"
except AttributeError:
encoded_creds = base64.encodestring(credentials)
auth = "Basic"
auth += encoded_creds.strip()
# Build up the MIME payload for the POST data
boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment