diff options
author | "Brett Cannon ext:(%22) <brett@python.org> | 2010-01-17 14:32:16 -0800 |
---|---|---|
committer | "Brett Cannon ext:(%22) <brett@python.org> | 2010-01-17 14:32:16 -0800 |
commit | 72d79d0466d0bfb566939075d651a9f111189137 (patch) | |
tree | 126f3ad8b84ecfd8f299ef557bfdbaf2423c60b6 /setuptools/command/upload_docs.py | |
parent | 56d8bf130caec9061d304dbedf0a1b7e8f5ff396 (diff) | |
download | external_python_setuptools-72d79d0466d0bfb566939075d651a9f111189137.tar.gz external_python_setuptools-72d79d0466d0bfb566939075d651a9f111189137.tar.bz2 external_python_setuptools-72d79d0466d0bfb566939075d651a9f111189137.zip |
Add some compatibility code for upload_docs so it will work in both
Python 2 and Python 3.
At this point in manual testing, Python 2.6 still works fine, but
Python 3 is getting a 200 from the upload which is not what is wanted;
a 301 is what is expected for a successful upload. But at least Python
3 is not throwing any more exceptions.
--HG--
branch : distribute
extra : rebase_source : 00020ec37fec743077e9614f8b0141aab41cc932
Diffstat (limited to 'setuptools/command/upload_docs.py')
-rw-r--r-- | setuptools/command/upload_docs.py | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/setuptools/command/upload_docs.py b/setuptools/command/upload_docs.py index d8c864e4..e961a0df 100644 --- a/setuptools/command/upload_docs.py +++ b/setuptools/command/upload_docs.py @@ -12,12 +12,25 @@ import httplib import base64 import urlparse import tempfile -import cStringIO as StringIO from distutils import log from distutils.errors import DistutilsOptionError from distutils.command.upload import upload +try: + bytes +except NameError: + bytes = str + +def b(str_or_bytes): + """Return bytes by either encoding the argument as ASCII or simply return + the argument as-is.""" + if not isinstance(str_or_bytes, bytes): + return str_or_bytes.encode('ascii') + else: + return str_or_bytes + + class upload_docs(upload): description = 'Upload documentation to PyPI' @@ -85,31 +98,30 @@ class upload_docs(upload): auth += encoded_creds.strip() # Build up the MIME payload for the POST data - boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' - sep_boundary = '\n--' + boundary - end_boundary = sep_boundary + '--' - body = StringIO.StringIO() + boundary = b('--------------GHSKFJDLGDS7543FJKLFHRE75642756743254') + sep_boundary = b('\n--') + boundary + end_boundary = sep_boundary + b('--') + body = [] for key, values in data.items(): # handle multiple entries for the same name if type(values) != type([]): values = [values] for value in values: if type(value) is tuple: - fn = ';filename="%s"' % value[0] + fn = b(';filename="%s"' % value[0]) value = value[1] else: - fn = "" - value = str(value) - body.write(sep_boundary) - body.write('\nContent-Disposition: form-data; name="%s"'%key) - body.write(fn) - body.write("\n\n") - body.write(value) - if value and value[-1] == '\r': - body.write('\n') # write an extra newline (lurve Macs) - body.write(end_boundary) - body.write("\n") - body = body.getvalue() + fn = b("") + body.append(sep_boundary) + body.append(b('\nContent-Disposition: form-data; name="%s"'%key)) + body.append(fn) + body.append(b("\n\n")) + body.append(b(value)) + if value and value[-1] == b('\r'): + body.append(b('\n')) # write an extra newline (lurve Macs) + body.append(end_boundary) + body.append(b("\n")) + body = b('').join(body) self.announce("Submitting documentation to %s" % (self.repository), log.INFO) |