Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Unified Diff: Lib/packaging/command/upload_docs.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/packaging/command/register.py ('k') | Lib/packaging/command/upload.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/packaging/command/upload_docs.py Tue Jul 26 09:37:46 2011 +0300
+++ b/Lib/packaging/command/upload_docs.py Mon Jul 25 09:47:18 2011 -0400
@@ -10,8 +10,7 @@
from io import BytesIO
from packaging import logger
-from packaging.util import (read_pypirc, DEFAULT_REPOSITORY, DEFAULT_REALM,
- encode_multipart)
+from packaging.util import read_pypirc, DEFAULT_REPOSITORY, DEFAULT_REALM
from packaging.errors import PackagingFileError
from packaging.command.cmd import Command
@@ -29,6 +28,49 @@
return destination
+# grabbed from
+# http://code.activestate.com/recipes/
+# 146306-http-client-to-post-using-multipartform-data/
+# TODO factor this out for use by install and command/upload
+
+def encode_multipart(fields, files, boundary=None):
+ """
+ *fields* is a sequence of (name: str, value: str) elements for regular
+ form fields, *files* is a sequence of (name: str, filename: str, value:
+ bytes) elements for data to be uploaded as files.
+
+ Returns (content_type: bytes, body: bytes) ready for http.client.HTTP.
+ """
+ if boundary is None:
+ boundary = b'--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
+ elif not isinstance(boundary, bytes):
+ raise TypeError('boundary is not bytes but %r' % type(boundary))
+
+ l = []
+ for key, value in fields:
+ l.extend((
+ b'--' + boundary,
+ ('Content-Disposition: form-data; name="%s"' %
+ key).encode('utf-8'),
+ b'',
+ value.encode('utf-8')))
+
+ for key, filename, value in files:
+ l.extend((
+ b'--' + boundary,
+ ('Content-Disposition: form-data; name="%s"; filename="%s"' %
+ (key, filename)).encode('utf-8'),
+ b'',
+ value))
+ l.append(b'--' + boundary + b'--')
+ l.append(b'')
+
+ body = b'\r\n'.join(l)
+
+ content_type = b'multipart/form-data; boundary=' + boundary
+ return content_type, body
+
+
class upload_docs(Command):
description = "upload HTML documentation to PyPI"
« no previous file with comments | « Lib/packaging/command/register.py ('k') | Lib/packaging/command/upload.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+