|
8 | 8 |
|
9 | 9 | from base64 import b64decode
|
10 | 10 | from json import dumps
|
11 |
| -from requests import post |
12 | 11 | from .event import Event
|
13 | 12 | from .issue import Issue, Label, Milestone, issue_params
|
14 | 13 | from .git import Blob, Commit, Reference, Tag, Tree
|
@@ -301,10 +300,6 @@ def create_download(self, name, path, description='',
|
301 | 300 | I do not require you provide the size in bytes because it can be
|
302 | 301 | determined by the operating system.
|
303 | 302 |
|
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 |
| -
|
308 | 303 | :param str name: (required), name of the file as it will appear
|
309 | 304 | :param path: (required), path to the file
|
310 | 305 | :type path: str
|
@@ -334,9 +329,33 @@ def create_download(self, name, path, description='',
|
334 | 329 | ('Policy', json.get('policy')),
|
335 | 330 | ('Signature', json.get('signature')),
|
336 | 331 | ('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 |
340 | 359 |
|
341 | 360 | @GitHubCore.requires_auth
|
342 | 361 | def create_fork(self, organization=None):
|
|
0 commit comments