parameters: (self, callback=None, finish_callback=None,
                        additional_headers=None, use_chunks=True)
return_statement: return response
docstring: Helper function for StreamMedia / StreamInChunks.
docstring_summary: Helper function for StreamMedia / StreamInChunks.
docstring_tokens: Helper function for StreamMedia / StreamInChunks .
function: def __StreamMedia(self, callback=None, finish_callback=None,
                        additional_headers=None, use_chunks=True):
          """Helper function for StreamMedia / StreamInChunks."""
          if self.strategy != RESUMABLE_UPLOAD:
              raise exceptions.InvalidUserInputError(
                  'Cannot stream non-resumable upload')
          callback = callback or self.progress_callback
          finish_callback = finish_callback or self.finish_callback
          # final_response is set if we resumed an already-completed upload.
          response = self.__final_response
          send_func = self.__SendChunk if use_chunks else self.__SendMediaBody
          if use_chunks:
              self.__ValidateChunksize(self.chunksize)
          self.EnsureInitialized()
          while not self.complete:
              response = send_func(self.stream.tell(),
                                   additional_headers=additional_headers)
              if response.status_code in (http_client.OK, http_client.CREATED):
                  self.__complete = True
                  break
              self.__progress = self.__GetLastByte(response.info['range'])
              if self.progress + 1 != self.stream.tell():
                  # TODO(craigcitro): Add a better way to recover here.
                  raise exceptions.CommunicationError(
                      'Failed to transfer all bytes in chunk, upload paused at '
                      'byte %d' % self.progress)
              self._ExecuteCallback(callback, response)
          if self.__complete and hasattr(self.stream, 'seek'):
              current_pos = self.stream.tell()
              self.stream.seek(0, os.SEEK_END)
              end_pos = self.stream.tell()
              self.stream.seek(current_pos)
              if current_pos != end_pos:
                  raise exceptions.TransferInvalidError(
                      'Upload complete with %s additional bytes left in stream' %
                      (int(end_pos) - int(current_pos)))
          self._ExecuteCallback(finish_callback, response)
          return response
function_tokens: def __StreamMedia ( self , callback = None , finish_callback = None , additional_headers = None , use_chunks = True ) : if self . strategy != RESUMABLE_UPLOAD : raise exceptions . InvalidUserInputError ( 'Cannot stream non-resumable upload' ) callback = callback or self . progress_callback finish_callback = finish_callback or self . finish_callback # final_response is set if we resumed an already-completed upload. response = self . __final_response send_func = self . __SendChunk if use_chunks else self . __SendMediaBody if use_chunks : self . __ValidateChunksize ( self . chunksize ) self . EnsureInitialized ( ) while not self . complete : response = send_func ( self . stream . tell ( ) , additional_headers = additional_headers ) if response . status_code in ( http_client . OK , http_client . CREATED ) : self . __complete = True break self . __progress = self . __GetLastByte ( response . info [ 'range' ] ) if self . progress + 1 != self . stream . tell ( ) : # TODO(craigcitro): Add a better way to recover here. raise exceptions . CommunicationError ( 'Failed to transfer all bytes in chunk, upload paused at ' 'byte %d' % self . progress ) self . _ExecuteCallback ( callback , response ) if self . __complete and hasattr ( self . stream , 'seek' ) : current_pos = self . stream . tell ( ) self . stream . seek ( 0 , os . SEEK_END ) end_pos = self . stream . tell ( ) self . stream . seek ( current_pos ) if current_pos != end_pos : raise exceptions . TransferInvalidError ( 'Upload complete with %s additional bytes left in stream' % ( int ( end_pos ) - int ( current_pos ) ) ) self . _ExecuteCallback ( finish_callback , response ) return response