8000 All users can now create downloads. · jsullivanlive/github3.py@89e6e02 · GitHub
[go: up one dir, main page]

Skip to content

Commit 89e6e02

Browse files
committed
All users can now create downloads.
Requests version does not matter. Soon though, I will force the requirement to be whatever version of requests ends up receiving that functionality. I'm not a fan of the recipe to create my own multipart/form-data encoded string.
1 parent 52805ba commit 89e6e02

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

HISTORY.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ History/Changelog
44
0.1: 2012-09-xx
55
---------------
66

7-
- Support for the complete GitHub API
7+
- Support for the complete GitHub API (accomplished)
88
- Partial coverage (unittests)

github3/repo.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from base64 import b64decode
1010
from json import dumps
11-
from requests import post
1211
from .event import Event
1312
from .issue import Issue, Label, Milestone, issue_params
1413
from .git import Blob, Commit, Reference, Tag, Tree
@@ -301,10 +300,6 @@ def create_download(self, name, path, description='',
301300
I do not require you provide the size in bytes because it can be
302301
determined by the operating system.
303302
304-
.. warning::
305-
This will not work until the release of requests after 0.13.5 or
306-
unless I vendorize requests as it is now (1 Aug 2012)
307-
308303
:param str name: (required), name of the file as it will appear
309304
:param path: (required), path to the file
310305
:type path: str
@@ -334,9 +329,33 @@ def create_download(self, name, path, description='',
334329
('Policy', json.get('policy')),
335330
('Signature', json.get('signature')),
336331
('Content-Type', json.get('mime_type'))]
337-
resp = post(json.get('s3_url'), data=form,
338 8000 -
files={'file': open(path, 'rb').read()})
339-
return resp
332+
# While requests doesn't have the ability to accept k/v lists leave
333+
# this commented.
334+
#file = [('file', open(path, 'rb').read())]
335+
#resp = self._post(json.get('s3_url', data=form, files=file,
336+
# auth=tuple())
337+
338+
# Recipe so we don't need to wait for requests to have this
339+
# functionality
340+
boundary = '--GitHubBoundary'
341+
content_disposition = 'Content-Disposition: form-data; name="{0}"'
342+
data = []
343+
for (k, v) in form:
344+
tmp = [boundary, content_disposition.format(k), '', v]
345+
data.extend(tmp)
346+
data.append(boundary)
347+
data.append(content_disposition.format('file') +
348+
'; filename="{0}"'.format(json.get('name')))
349+
data.extend(['', open(path, 'rb').read(), boundary + '--', ''])
350+
form = '\r\n'.join(data)
351+
headers = {'Content-Type': 'multipart 718D /form-data; boundary={0}'.format(
352+
boundary[2:]), 'Content-Length': str(len(form))}
353+
354+
# Need to disable auth so Amazon doesn't think we're trying to
355+
# authenticate that way
356+
resp = self._post(json.get('s3_url'), data=form, headers=headers,
357+
auth=tuple())
358+
return resp.status_code == 201
340359

341360
@GitHubCore.requires_auth
342361
def create_fork(self, organization=None):

0 commit comments

Comments
 (0)
0