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
parent 56d8bf13
...@@ -32,7 +32,7 @@ depends.txt = setuptools.command.egg_info:warn_depends_obsolete ...@@ -32,7 +32,7 @@ depends.txt = setuptools.command.egg_info:warn_depends_obsolete
[console_scripts] [console_scripts]
easy_install = setuptools.command.easy_install:main easy_install = setuptools.command.easy_install:main
easy_install-2.6 = setuptools.command.easy_install:main easy_install-3.1 = setuptools.command.easy_install:main
[setuptools.file_finders] [setuptools.file_finders]
svn_cvs = setuptools.command.sdist:_default_revctrl svn_cvs = setuptools.command.sdist:_default_revctrl
......
...@@ -12,12 +12,25 @@ import httplib ...@@ -12,12 +12,25 @@ import httplib
import base64 import base64
import urlparse import urlparse
import tempfile import tempfile
import cStringIO as StringIO
from distutils import log from distutils import log
from distutils.errors import DistutilsOptionError from distutils.errors import DistutilsOptionError
from distutils.command.upload import upload 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): class upload_docs(upload):
description = 'Upload documentation to PyPI' description = 'Upload documentation to PyPI'
...@@ -85,31 +98,30 @@ class upload_docs(upload): ...@@ -85,31 +98,30 @@ class upload_docs(upload):
auth += encoded_creds.strip() auth += encoded_creds.strip()
# Build up the MIME payload for the POST data # Build up the MIME payload for the POST data
boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' boundary = b('--------------GHSKFJDLGDS7543FJKLFHRE75642756743254')
sep_boundary = '\n--' + boundary sep_boundary = b('\n--') + boundary
end_boundary = sep_boundary + '--' end_boundary = sep_boundary + b('--')
body = StringIO.StringIO() body = []
for key, values in data.items(): for key, values in data.items():
# handle multiple entries for the same name # handle multiple entries for the same name
if type(values) != type([]): if type(values) != type([]):
values = [values] values = [values]
for value in values: for value in values:
if type(value) is tuple: if type(value) is tuple:
fn = ';filename="%s"' % value[0] fn = b(';filename="%s"' % value[0])
value = value[1] value = value[1]
else: else:
fn = "" fn = b("")
value = str(value) body.append(sep_boundary)
body.write(sep_boundary) body.append(b('\nContent-Disposition: form-data; name="%s"'%key))
body.write('\nContent-Disposition: form-data; name="%s"'%key) body.append(fn)
body.write(fn) body.append(b("\n\n"))
body.write("\n\n") body.append(b(value))
body.write(value) if value and value[-1] == b('\r'):
if value and value[-1] == '\r': body.append(b('\n')) # write an extra newline (lurve Macs)
body.write('\n') # write an extra newline (lurve Macs) body.append(end_boundary)
body.write(end_boundary) body.append(b("\n"))
body.write("\n") body = b('').join(body)
body = body.getvalue()
self.announce("Submitting documentation to %s" % (self.repository), self.announce("Submitting documentation to %s" % (self.repository),
log.INFO) log.INFO)
......
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