(file)
| 1339 | return None |
| 1340 | |
| 1341 | def write_stream(file): |
| 1342 | current_bytes = 0 |
| 1343 | while True: |
| 1344 | data = file.read(chunk_size) |
| 1345 | if not data: |
| 1346 | break |
| 1347 | transfer_bytes = len(data) |
| 1348 | headers = { |
| 1349 | 'Content-type': 'application/octet-stream', |
| 1350 | 'Content-Length': str(len(data)), |
| 1351 | 'Content-Range': 'bytes {}-{}/{}' |
| 1352 | ''.format(current_bytes, |
| 1353 | current_bytes + |
| 1354 | transfer_bytes - 1, |
| 1355 | file_size) |
| 1356 | } |
| 1357 | current_bytes += transfer_bytes |
| 1358 | |
| 1359 | # this request mut NOT send the authorization header. |
| 1360 | # so we use a naive simple request. |
| 1361 | response = self.con.naive_request(upload_url, 'PUT', |
| 1362 | data=data, |
| 1363 | headers=headers) |
| 1364 | if not response: |
| 1365 | return None |
| 1366 | |
| 1367 | if response.status_code != 202: |
| 1368 | # file is completed |
| 1369 | data = response.json() |
| 1370 | return self._classifier(data)(parent=self, **{ |
| 1371 | self._cloud_data_key: data}) |
| 1372 | |
| 1373 | if stream: |
| 1374 | return write_stream(stream) |
nothing calls this directly
no test coverage detected