Commits

"Bre...@python.org>"  committed 0999891

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.

  • Participants
  • Parent commits 7e13588
  • Branches 0.6-maintenance

Comments (0)

Files changed (2)

File distribute.egg-info/entry_points.txt

 
 [console_scripts]
 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]
 svn_cvs = setuptools.command.sdist:_default_revctrl

File setuptools/command/upload_docs.py

 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'
         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)