def InitializeUpload(self, http_request, http=None, client=None):
        """Initialize this upload from the given http_request."""
        if self.strategy is None:
            raise exceptions.UserError(
                'No upload strategy set; did you call ConfigureRequest?')
        if http is None and client is None:
            raise exceptions.UserError('Must provide client or http.')
        if self.strategy != RESUMABLE_UPLOAD:
            return
        http = http or client.http
        if client is not None:
            http_request.url = client.FinalizeTransferUrl(http_request.url)
        self.EnsureUninitialized()
        http_response = http_wrapper.MakeRequest(http,
                                                 http_request,
                                                 retries=self.num_retries)
        if http_response.status_code != httplib.OK:
            raise exceptions.HttpError.FromResponse(http_response)

        self.__server_chunk_granularity = http_response.info.get(
            'X-Goog-Upload-Chunk-Granularity')
        self.__ValidateChunksize()
        url = http_response.info['location']
        if client is not None:
            url = client.FinalizeTransferUrl(url)
        self._Initialize(http, url)

        # Unless the user has requested otherwise, we want to just
        # go ahead and pump the bytes now.
        if self.auto_transfer:
            return self.StreamInChunks()
    def InitializeDownload(self, http_request, http=None, client=None):
        """Initialize this download by making a request.

    Args:
      http_request: The HttpRequest to use to initialize this download.
      http: The httplib2.Http instance for this request.
      client: If provided, let this client process the final URL before
          sending any additional requests. If client is provided and
          http is not, client.http will be used instead.
    """
        self.EnsureUninitialized()
        if http is None and client is None:
            raise exceptions.UserError('Must provide client or http.')
        http = http or client.http
        if client is not None:
            http_request.url = client.FinalizeTransferUrl(http_request.url)
        url = http_request.url
        if client is not None:
            url = client.FinalizeTransferUrl(url)
        self._Initialize(http, url)
        # Unless the user has requested otherwise, we want to just
        # go ahead and pump the bytes now.
        if self.auto_transfer:
            self.StreamInChunks()
 def strategy(self, value):
     if value not in (SIMPLE_UPLOAD, RESUMABLE_UPLOAD):
         raise exceptions.UserError(
             ('Invalid value "%s" for upload strategy, must be one of '
              '"simple" or "resumable".') % value)
     self.__strategy = value