diff options
Diffstat (limited to 'src/distutils2/command/upload_docs.py')
| -rw-r--r-- | src/distutils2/command/upload_docs.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/distutils2/command/upload_docs.py b/src/distutils2/command/upload_docs.py index 8400b3d..0904a6b 100644 --- a/src/distutils2/command/upload_docs.py +++ b/src/distutils2/command/upload_docs.py @@ -14,6 +14,38 @@ def zip_dir_into(directory, destination): zip_file.write(full, dest) zip_file.close() +# grabbed from +# http://code.activestate.com/recipes/146306-http-client-to-post-using-multipartform-data/ +def encode_multipart(fields, files, boundary=None): + """ + fields is a sequence of (name, value) elements for regular form fields. + files is a sequence of (name, filename, content_type, value) + elements for data to be uploaded as files + Return (content_type, body) ready for httplib.HTTP instance + """ + if boundary is None: + boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' + CRLF = '\r\n' + l = [] + for (key, value) in fields: + l.extend([ + '--' + boundary, + 'Content-Disposition: form-data; name="%s"' % key, + '', + value]) + for (key, filename, content_type, value) in files: + l.extend([ + '--' + boundary, + 'Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename), + 'Content-Type: %s' % content_type, + '', + value]) + l.append('--' + boundary + '--') + l.append('') + body = CRLF.join(l) + content_type = 'multipart/form-data; boundary=%s' % boundary + return content_type, body + class upload_docs(Command): user_options = [ |
