def configure_request(self, upload_config, http_request, url_builder): """Configure the request and url for this upload. :type upload_config: instance w/ ``max_size`` and ``accept`` attributes :param upload_config: transfer policy object to be queried :type http_request: :class:`gcloud.streaming.http_wrapper.Request` :param http_request: the request to be updated :type url_builder: instance with settable 'relative_path' and 'query_params' attributes. :param url_builder: transfer policy object to be updated :raises: :exc:`ValueError` if the requested upload is too big, or does not have an acceptable MIME type. """ # Validate total_size vs. max_size if (self.total_size and upload_config.max_size and self.total_size > upload_config.max_size): raise ValueError( 'Upload too big: %s larger than max size %s' % ( self.total_size, upload_config.max_size)) # Validate mime type if not acceptable_mime_type(upload_config.accept, self.mime_type): raise ValueError( 'MIME type %s does not match any accepted MIME ranges %s' % ( self.mime_type, upload_config.accept)) self._set_default_strategy(upload_config, http_request) if self.strategy == SIMPLE_UPLOAD: url_builder.relative_path = upload_config.simple_path if http_request.body: url_builder.query_params['uploadType'] = 'multipart' self._configure_multipart_request(http_request) else: url_builder.query_params['uploadType'] = 'media' self._configure_media_request(http_request) else: url_builder.relative_path = upload_config.resumable_path url_builder.query_params['uploadType'] = 'resumable' self._configure_resumable_request(http_request)
def configure_request(self, upload_config, http_request, url_builder): """Configure the request and url for this upload. :type upload_config: instance w/ ``max_size`` and ``accept`` attributes :param upload_config: transfer policy object to be queried :type http_request: :class:`gcloud.streaming.http_wrapper.Request` :param http_request: the request to be updated :type url_builder: instance with settable 'relative_path' and 'query_params' attributes. :param url_builder: transfer policy object to be updated :raises: :exc:`ValueError` if the requested upload is too big, or does not have an acceptable MIME type. """ # Validate total_size vs. max_size if (self.total_size and upload_config.max_size and self.total_size > upload_config.max_size): raise ValueError('Upload too big: %s larger than max size %s' % (self.total_size, upload_config.max_size)) # Validate mime type if not acceptable_mime_type(upload_config.accept, self.mime_type): raise ValueError( 'MIME type %s does not match any accepted MIME ranges %s' % (self.mime_type, upload_config.accept)) self._set_default_strategy(upload_config, http_request) if self.strategy == SIMPLE_UPLOAD: url_builder.relative_path = upload_config.simple_path if http_request.body: url_builder.query_params['uploadType'] = 'multipart' self._configure_multipart_request(http_request) else: url_builder.query_params['uploadType'] = 'media' self._configure_media_request(http_request) else: url_builder.relative_path = upload_config.resumable_path url_builder.query_params['uploadType'] = 'resumable' self._configure_resumable_request(http_request)
def _callFUT(self, *args, **kw): from gcloud.streaming.util import acceptable_mime_type return acceptable_mime_type(*args, **kw)