Skip to content

Commit

Permalink
fix for #104 large file support
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tal committed Apr 29, 2015
1 parent 36c1f2c commit 1b14328
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions twine/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ def upload(dists, repository, sign, identity, username, password, comment,

}

md5_hash = hashlib.md5()
with open(filename, "rb") as fp:
content = fp.read()
filedata = {
"content": (os.path.basename(filename), content),
}
data["md5_digest"] = hashlib.md5(content).hexdigest()
content = fp.read(4096)
while content:
md5_hash.update(content)
content = fp.read(4096)

data["md5_digest"] = md5_hash.hexdigest()

signed_name = os.path.basename(filename) + ".asc"
if signed_name in signatures:
Expand All @@ -206,13 +208,14 @@ def upload(dists, repository, sign, identity, username, password, comment,

print("Uploading {0}".format(os.path.basename(filename)))

resp = session.post(
config["repository"],
data=dict((k, v) for k, v in data.items() if v),
files=filedata,
auth=(username, password),
allow_redirects=False,
)
with open(filename, "rb") as fp:
resp = session.post(
config["repository"],
data=dict((k, v) for k, v in data.items() if v),
files={"content": (os.path.basename(filename), fp)},
auth=(username, password),
allow_redirects=False,
)
# Bug 28. Try to silence a ResourceWarning by releasing the socket and
# clearing the connection pool.
resp.close()
Expand All @@ -222,7 +225,7 @@ def upload(dists, repository, sign, identity, username, password, comment,
# funky. The behaviour is not well defined and redirects being issued
# by PyPI should never happen in reality. This should catch malicious
# redirects as well.
if resp.is_redirect():
if resp.is_redirect:
raise exc.RedirectDetected(
('"{0}" attempted to redirect to "{1}" during upload.'
' Aborting...').format(config["respository"],
Expand Down

0 comments on commit 1b14328

Please sign in to comment.