summaryrefslogtreecommitdiff
path: root/src/distutils2/command/upload_docs.py
diff options
context:
space:
mode:
authorKonrad Delong <konryd@gmail.com>2010-05-13 23:20:53 +0200
committerKonrad Delong <konryd@gmail.com>2010-05-13 23:20:53 +0200
commitb2e9e5f4ba2268f1b01dbbb8e1f16d07d6ee9ae6 (patch)
treecb73e75d8309b7dc17eb2b69fa9c15adce872bf2 /src/distutils2/command/upload_docs.py
parente00e9fa0faac915b1b12675d1788bcb37b8fc769 (diff)
downloaddisutils2-b2e9e5f4ba2268f1b01dbbb8e1f16d07d6ee9ae6.tar.gz
added encode_multipart
Diffstat (limited to 'src/distutils2/command/upload_docs.py')
-rw-r--r--src/distutils2/command/upload_docs.py32
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 = [