[Python-checkins] distutils2: make sure distutils2 talks with PyPI correctly -- once again this part misses

tarek.ziade python-checkins at python.org
Tue Apr 13 02:24:57 CEST 2010


tarek.ziade pushed 42bcaed8a5d5 to distutils2:

http://hg.python.org/distutils2/rev/42bcaed8a5d5
changeset:   116:42bcaed8a5d5
user:        Tarek Ziade <tarek at ziade.org>
date:        Tue Apr 13 02:21:57 2010 +0200
summary:     make sure distutils2 talks with PyPI correctly -- once again this part misses tests
files:       src/distutils2/command/register.py, src/distutils2/command/upload.py, src/distutils2/config.py

diff --git a/src/distutils2/command/register.py b/src/distutils2/command/register.py
--- a/src/distutils2/command/register.py
+++ b/src/distutils2/command/register.py
@@ -228,6 +228,7 @@
         data[':action'] = action
         return data
 
+    # XXX to be refactored with upload.upload_file
     def post_to_server(self, data, auth=None):
         ''' Post a query to the server, and return a string response.
         '''
diff --git a/src/distutils2/command/upload.py b/src/distutils2/command/upload.py
--- a/src/distutils2/command/upload.py
+++ b/src/distutils2/command/upload.py
@@ -7,7 +7,7 @@
 from urllib2 import urlopen, Request, HTTPError
 from base64 import standard_b64encode
 import urlparse
-import cStringIO as StringIO
+import StringIO as StringIO
 try:
     from hashlib import md5
 except ImportError:
@@ -62,6 +62,7 @@
         for command, pyversion, filename in self.distribution.dist_files:
             self.upload_file(command, pyversion, filename)
 
+    # XXX to be refactored with register.post_to_server
     def upload_file(self, command, pyversion, filename):
         # Makes sure the repository URL is compliant
         schema, netloc, url, params, query, fragments = \
@@ -83,14 +84,13 @@
         # Fill in the data - send all the meta-data in case we need to
         # register a new release
         content = open(filename,'rb').read()
-        meta = self.distribution.metadata
 
         data = self._metadata_to_pypy_dict()
 
         # extra upload infos
         data[':action'] = 'file_upload'
         data['protcol_version'] = '1'
-        data['content'] = os.path.basename(filename), content
+        data['content'] = [os.path.basename(filename), content]
         data['filetype'] = command
         data['pyversion'] = pyversion
         data['md5_digest'] = md5(content).hexdigest()
@@ -105,8 +105,8 @@
         data['comment'] = comment
 
         if self.sign:
-            data['gpg_signature'] = (os.path.basename(filename) + ".asc",
-                                     open(filename+".asc").read())
+            data['gpg_signature'] = [(os.path.basename(filename) + ".asc",
+                                      open(filename+".asc").read())]
 
         # set up the authentication
         auth = "Basic " + standard_b64encode(self.username + ":" +
@@ -117,29 +117,41 @@
         sep_boundary = '\n--' + boundary
         end_boundary = sep_boundary + '--'
         body = StringIO.StringIO()
-        for key, value in data.items():
+        file_fields = ('content', 'gpg_signature')
+
+        for key, values in data.items():
             # handle multiple entries for the same name
-            if not isinstance(value, list):
-                value = [value]
-            for value in value:
-                if isinstance(value, tuple):
-                    fn = ';filename="%s"' % value[0]
-                    value = value[1]
-                else:
-                    fn = ""
+            if not isinstance(values, (tuple, list)):
+                values = [values]
 
+            content_dispo = 'Content-Disposition: form-data; name="%s"' % key
+
+            if key in file_fields:
+                filename, content = values
+                filename = ';filename="%s"' % filename
                 body.write(sep_boundary)
-                body.write('\nContent-Disposition: form-data; name="%s"'%key)
-                body.write(fn)
+                body.write("\n")
+                body.write(content_dispo)
+                body.write(filename)
                 body.write("\n\n")
-                body.write(value)
-                if value and value[-1] == '\r':
-                    body.write('\n')  # write an extra newline (lurve Macs)
+                body.write(content)
+            else:
+                for value in values:
+                    body.write(sep_boundary)
+                    body.write("\n")
+                    body.write(content_dispo)
+                    body.write("\n\n")
+                    body.write(value)
+                    if value and value[-1] == '\r':
+                        # write an extra newline (lurve Macs)
+                        body.write('\n')
+
         body.write(end_boundary)
         body.write("\n")
         body = body.getvalue()
 
-        self.announce("Submitting %s to %s" % (filename, self.repository), log.INFO)
+        self.announce("Submitting %s to %s" % (filename, self.repository),
+                      log.INFO)
 
         # build the Request
         headers = {'Content-type':
diff --git a/src/distutils2/config.py b/src/distutils2/config.py
--- a/src/distutils2/config.py
+++ b/src/distutils2/config.py
@@ -131,7 +131,8 @@
             data['requires_external'] = meta['Requires-External']
             data['provides_dist'] = meta['Provides-Dist']
             data['obsoletes_dist'] = meta['Obsoletes-Dist']
-            data['project_url'] = meta['Project-URL']
+            data['project_url'] = [','.join(url) for url in
+                                   meta['Project-URL']]
 
         elif meta.version == '1.1':
             data['provides'] = meta['Provides']

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list