Download pool/shard000/Python/0000049_formdata.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 4.79 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard000/Python/0000049_formdata.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard000/Python/0000049_formdata.py
-
curl -L -o 0000049_formdata.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard000/Python/0000049_formdata.py
4.79 kB
| # coding=utf-8 | |
| # -------------------------------------------------------------------------- | |
| # Copyright (c) Microsoft Corporation. All rights reserved. | |
| # Licensed under the MIT License. See License.txt in the project root for | |
| # license information. | |
| # | |
| # Code generated by Microsoft (R) AutoRest Code Generator. | |
| # Changes may cause incorrect behavior and will be lost if the code is | |
| # regenerated. | |
| # -------------------------------------------------------------------------- | |
| from msrest.pipeline import ClientRawResponse | |
| from .. import models | |
| class Formdata(object): | |
| def __init__(self, client, config, serializer, deserializer): | |
| self._client = client | |
| self._serialize = serializer | |
| self._deserialize = deserializer | |
| self.config = config | |
| def upload_file( | |
| self, file_content, file_name, custom_headers={}, raw=False, callback=None, **operation_config): | |
| """ | |
| Upload file | |
| :param file_content: File to upload. | |
| :type file_content: object | |
| :param file_name: File name to upload. Name has to be spelled exactly | |
| as written here. | |
| :type file_name: str | |
| :param dict custom_headers: headers that will be added to the request | |
| :param boolean raw: returns the direct response alongside the | |
| deserialized response | |
| :param callback: if provided, the runtime will call the callback while | |
| streaming upload/download. If streaming upload, response kwarg will | |
| be None | |
| :type callback: Callable[[concurrent.futures.Future], None] or None | |
| :rtype: object or (object, requests.response) or | |
| concurrent.futures.Future | |
| """ | |
| # Construct URL | |
| url = '/formdata/stream/uploadfile' | |
| # Construct parameters | |
| query_parameters = {} | |
| # Construct headers | |
| header_parameters = {} | |
| header_parameters['Content-Type'] = 'multipart/form-data' | |
| if custom_headers: | |
| header_parameters.update(custom_headers) | |
| # Construct form data | |
| form_data_content = { | |
| 'fileContent': file_content, | |
| 'fileName': file_name, | |
| } | |
| # Construct and send request | |
| request = self._client.post(url, query_parameters) | |
| response = self._client.send_formdata( | |
| request, header_parameters, form_data_content, **operation_config) | |
| if response.status_code not in [200]: | |
| raise models.ErrorException(self._deserialize, response) | |
| deserialized = None | |
| if response.status_code == 200: | |
| deserialized = self._client.stream_download(response, callback) | |
| if raw: | |
| client_raw_response = ClientRawResponse(deserialized, response) | |
| return client_raw_response | |
| return deserialized | |
| def upload_file_via_body( | |
| self, file_content, file_name, custom_headers={}, raw=False, callback=None, **operation_config): | |
| """ | |
| Upload file | |
| :param file_content: File to upload. | |
| :type file_content: object | |
| :param file_name: File name to upload. Name has to be spelled exactly | |
| as written here. | |
| :type file_name: str | |
| :param dict custom_headers: headers that will be added to the request | |
| :param boolean raw: returns the direct response alongside the | |
| deserialized response | |
| :param callback: if provided, the runtime will call the callback while | |
| streaming upload/download. If streaming upload, response kwarg will | |
| be None | |
| :type callback: Callable[[concurrent.futures.Future], None] or None | |
| :rtype: object or (object, requests.response) or | |
| concurrent.futures.Future | |
| """ | |
| # Construct URL | |
| url = '/formdata/stream/uploadfile' | |
| # Construct parameters | |
| query_parameters = {} | |
| # Construct headers | |
| header_parameters = {} | |
| header_parameters['Content-Type'] = 'application/octet-stream' | |
| if custom_headers: | |
| header_parameters.update(custom_headers) | |
| # Construct body | |
| body_content = self._client.stream_upload(file_content, callback) | |
| # Construct and send request | |
| request = self._client.put(url, query_parameters) | |
| response = self._client.send( | |
| request, header_parameters, body_content, **operation_config) | |
| if response.status_code not in [200]: | |
| raise models.ErrorException(self._deserialize, response) | |
| deserialized = None | |
| if response.status_code == 200: | |
| deserialized = self._client.stream_download(response, callback) | |
| if raw: | |
| client_raw_response = ClientRawResponse(deserialized, response) | |
| return client_raw_response | |
| return deserialized | |