Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/epy/googleapiclient.http-pysrc.html
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ <h1 class="epydoc">Source Code for <a href="googleapiclient.http-module.html">Mo
<a name="L655"></a><tt class="py-lineno"> 655</tt> <tt class="py-line"><tt class="py-docstring"> Returns:</tt> </tt>
<a name="L656"></a><tt class="py-lineno"> 656</tt> <tt class="py-line"><tt class="py-docstring"> (status, done): (MediaDownloadStatus, boolean)</tt> </tt>
<a name="L657"></a><tt class="py-lineno"> 657</tt> <tt class="py-line"><tt class="py-docstring"> The value of 'done' will be True when the media has been fully</tt> </tt>
<a name="L658"></a><tt class="py-lineno"> 658</tt> <tt class="py-line"><tt class="py-docstring"> downloaded.</tt> </tt>
<a name="L658"></a><tt class="py-lineno"> 658</tt> <tt class="py-line"><tt class="py-docstring"> downloaded or the total size of the media is unknown.</tt> </tt>
<a name="L659"></a><tt class="py-lineno"> 659</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L660"></a><tt class="py-lineno"> 660</tt> <tt class="py-line"><tt class="py-docstring"> Raises:</tt> </tt>
<a name="L661"></a><tt class="py-lineno"> 661</tt> <tt class="py-line"><tt class="py-docstring"> googleapiclient.errors.HttpError if the response was not a 2xx.</tt> </tt>
Expand Down Expand Up @@ -873,7 +873,7 @@ <h1 class="epydoc">Source Code for <a href="googleapiclient.http-module.html">Mo
<a name="L684"></a><tt class="py-lineno"> 684</tt> <tt class="py-line"> <tt class="py-keyword">elif</tt> <tt class="py-string">'content-length'</tt> <tt class="py-keyword">in</tt> <tt class="py-name">resp</tt><tt class="py-op">:</tt> </tt>
<a name="L685"></a><tt class="py-lineno"> 685</tt> <tt class="py-line"> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_total_size</tt> <tt class="py-op">=</tt> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">resp</tt><tt class="py-op">[</tt><tt class="py-string">'content-length'</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L686"></a><tt class="py-lineno"> 686</tt> <tt class="py-line"> </tt>
<a name="L687"></a><tt class="py-lineno"> 687</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_progress</tt> <tt class="py-op">==</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_total_size</tt><tt class="py-op">:</tt> </tt>
<a name="L687"></a><tt class="py-lineno"> 687</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_total_size</tt> <tt class="py-keyword">is</tt> <tt class="py-name">None</tt> <tt class="py-keyword">or</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_progress</tt> <tt class="py-op">==</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_total_size</tt><tt class="py-op">:</tt> </tt>
<a name="L688"></a><tt class="py-lineno"> 688</tt> <tt class="py-line"> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_done</tt> <tt class="py-op">=</tt> <tt class="py-name">True</tt> </tt>
<a name="L689"></a><tt class="py-lineno"> 689</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt id="link-86" class="py-name" targets="Class googleapiclient.http.MediaDownloadProgress=googleapiclient.http.MediaDownloadProgress-class.html"><a title="googleapiclient.http.MediaDownloadProgress" class="py-name" href="#" onclick="return doclink('link-86', 'MediaDownloadProgress', 'link-86');">MediaDownloadProgress</a></tt><tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_progress</tt><tt class="py-op">,</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_total_size</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_done</tt> </tt>
<a name="L690"></a><tt class="py-lineno"> 690</tt> <tt class="py-line"> <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
Expand Down Expand Up @@ -2189,7 +2189,7 @@ <h1 class="epydoc">Source Code for <a href="googleapiclient.http-module.html">Mo
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Mon Jun 5 13:38:40 2017
Generated by Epydoc 3.0.1 on Wed Jun 14 20:18:21 2017
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
Expand Down
4 changes: 2 additions & 2 deletions docs/epy/googleapiclient.http.MediaIoBaseDownload-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ <h3 class="epydoc"><span class="sig"><span class="sig-name">next_chunk</span>(<s
Returns:
(status, done): (MediaDownloadStatus, boolean)
The value of 'done' will be True when the media has been fully
downloaded.
downloaded or the total size of the media is unknown.

Raises:
googleapiclient.errors.HttpError if the response was not a 2xx.
Expand Down Expand Up @@ -308,7 +308,7 @@ <h3 class="epydoc"><span class="sig"><span class="sig-name">next_chunk</span>(<s
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Mon Jun 5 13:38:40 2017
Generated by Epydoc 3.0.1 on Wed Jun 14 20:18:20 2017
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
Expand Down
4 changes: 2 additions & 2 deletions googleapiclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def next_chunk(self, num_retries=0):
Returns:
(status, done): (MediaDownloadStatus, boolean)
The value of 'done' will be True when the media has been fully
downloaded.
downloaded or the total size of the media is unknown.

Raises:
googleapiclient.errors.HttpError if the response was not a 2xx.
Expand Down Expand Up @@ -684,7 +684,7 @@ def next_chunk(self, num_retries=0):
elif 'content-length' in resp:
self._total_size = int(resp['content-length'])

if self._progress == self._total_size:
if self._total_size is None or self._progress == self._total_size:
self._done = True
return MediaDownloadProgress(self._progress, self._total_size), self._done
else:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,29 @@ def test_media_io_base_download_empty_file(self):
self.assertEqual(0, download._total_size)
self.assertEqual(0, status.progress())

def test_media_io_base_download_unknown_media_size(self):
self.request.http = HttpMockSequence([
({'status': '200'}, b'123')
])

download = MediaIoBaseDownload(
fd=self.fd, request=self.request, chunksize=3)

self.assertEqual(self.fd, download._fd)
self.assertEqual(0, download._progress)
self.assertEqual(None, download._total_size)
self.assertEqual(False, download._done)
self.assertEqual(self.request.uri, download._uri)

status, done = download.next_chunk()

self.assertEqual(self.fd.getvalue(), b'123')
self.assertEqual(True, done)
self.assertEqual(3, download._progress)
self.assertEqual(None, download._total_size)
self.assertEqual(0, status.progress())


EXPECTED = """POST /someapi/v1/collection/?foo=bar HTTP/1.1
Content-Type: application/json
MIME-Version: 1.0
Expand Down