@ -29,7 +29,27 @@ def _get_kwargs(
|
||||
|
||||
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
|
||||
if response.status_code == 200:
|
||||
response_200 = AsyncApiCallOutput.from_dict(response.json())
|
||||
try:
|
||||
if not isinstance(data, dict):
|
||||
raise TypeError()
|
||||
option = FileConversion.from_dict(data)
|
||||
return option
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if not isinstance(data, dict):
|
||||
raise TypeError()
|
||||
option = FileMass.from_dict(data)
|
||||
return option
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if not isinstance(data, dict):
|
||||
raise TypeError()
|
||||
option = FileVolume.from_dict(data)
|
||||
return option
|
||||
except:
|
||||
raise
|
||||
return response_200
|
||||
if response.status_code == 400:
|
||||
response_4XX = Error.from_dict(response.json())
|
||||
|
@ -0,0 +1,59 @@
|
||||
from typing import Any, Dict, Optional, Union
|
||||
|
||||
import base64
|
||||
import httpx
|
||||
|
||||
from ...client import Client
|
||||
from ...models import Error
|
||||
from ...models import FileConversion
|
||||
from ...models import FileSourceFormat
|
||||
from ...models import FileOutputFormat
|
||||
from ...types import Response
|
||||
from ...api.file.create_file_conversion import sync as fc_sync, asyncio as fc_asyncio
|
||||
|
||||
def sync(
|
||||
src_format: FileSourceFormat,
|
||||
output_format: FileOutputFormat,
|
||||
body: bytes,
|
||||
*,
|
||||
client: Client,
|
||||
) -> Optional[Union[Any, FileConversion, Error]]:
|
||||
"""Convert a CAD file from one format to another. If the file being converted is larger than a certain size it will be performed asynchronously. This function automatically base64 encodes the request body and base64 decodes the request output."""
|
||||
|
||||
encoded = base64.b64encode(body)
|
||||
|
||||
fc = fc_sync(
|
||||
src_format=src_format,
|
||||
output_format=output_format,
|
||||
body=encoded,
|
||||
client=client,
|
||||
)
|
||||
|
||||
if isinstance(fc, FileConversion) and fc.output != "":
|
||||
fc.output = base64.b64decode(fc.output)
|
||||
|
||||
return fc
|
||||
|
||||
|
||||
async def asyncio(
|
||||
src_format: FileSourceFormat,
|
||||
output_format: FileOutputFormat,
|
||||
body: bytes,
|
||||
*,
|
||||
client: Client,
|
||||
) -> Optional[Union[Any, FileConversion, Error]]:
|
||||
"""Convert a CAD file from one format to another. If the file being converted is larger than a certain size it will be performed asynchronously. This function automatically base64 encodes the request body and base64 decodes the request output."""
|
||||
|
||||
encoded = base64.b64encode(body)
|
||||
|
||||
fc = await fc_asyncio(
|
||||
src_format=src_format,
|
||||
output_format=output_format,
|
||||
body=encoded,
|
||||
client=client,
|
||||
)
|
||||
|
||||
if isinstance(fc, FileConversion) and fc.output != "":
|
||||
fc.output = base64.b64decode(fc.output)
|
||||
|
||||
return fc
|
@ -29,7 +29,27 @@ def _get_kwargs(
|
||||
|
||||
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
|
||||
if response.status_code == 200:
|
||||
response_200 = AsyncApiCallOutput.from_dict(response.json())
|
||||
try:
|
||||
if not isinstance(data, dict):
|
||||
raise TypeError()
|
||||
option = FileConversion.from_dict(data)
|
||||
return option
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if not isinstance(data, dict):
|
||||
raise TypeError()
|
||||
option = FileMass.from_dict(data)
|
||||
return option
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if not isinstance(data, dict):
|
||||
raise TypeError()
|
||||
option = FileVolume.from_dict(data)
|
||||
return option
|
||||
except:
|
||||
raise
|
||||
return response_200
|
||||
if response.status_code == 400:
|
||||
response_4XX = Error.from_dict(response.json())
|
||||
|
@ -29,7 +29,27 @@ def _get_kwargs(
|
||||
|
||||
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
|
||||
if response.status_code == 200:
|
||||
response_200 = AsyncApiCallOutput.from_dict(response.json())
|
||||
try:
|
||||
if not isinstance(data, dict):
|
||||
raise TypeError()
|
||||
option = FileConversion.from_dict(data)
|
||||
return option
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if not isinstance(data, dict):
|
||||
raise TypeError()
|
||||
option = FileMass.from_dict(data)
|
||||
return option
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if not isinstance(data, dict):
|
||||
raise TypeError()
|
||||
option = FileVolume.from_dict(data)
|
||||
return option
|
||||
except:
|
||||
raise
|
||||
return response_200
|
||||
if response.status_code == 400:
|
||||
response_4XX = Error.from_dict(response.json())
|
||||
|
46
kittycad/api/file/get_file_conversion_with_base64_helper.py
Normal file
46
kittycad/api/file/get_file_conversion_with_base64_helper.py
Normal file
@ -0,0 +1,46 @@
|
||||
from typing import Any, Dict, Optional, Union
|
||||
|
||||
import base64
|
||||
import httpx
|
||||
|
||||
from ...client import Client
|
||||
from ...models import Error
|
||||
from ...models.file_conversion import FileConversion
|
||||
from ...types import Response
|
||||
from ...api.file.get_file_conversion import sync as fc_sync, asyncio as fc_asyncio
|
||||
|
||||
|
||||
def sync(
|
||||
id: str,
|
||||
*,
|
||||
client: Client,
|
||||
) -> Optional[Union[Any, FileConversion, Error]]:
|
||||
"""Get the status of a file conversion. This function automatically base64 decodes the output response if there is one."""
|
||||
|
||||
fc = fc_sync(
|
||||
id=id,
|
||||
client=client,
|
||||
)
|
||||
|
||||
if isinstance(fc, FileConversion) and fc.output != "":
|
||||
fc.output = base64.b64decode(fc.output)
|
||||
|
||||
return fc
|
||||
|
||||
|
||||
async def asyncio(
|
||||
id: str,
|
||||
*,
|
||||
client: Client,
|
||||
) -> Optional[Union[Any, FileConversion, Error]]:
|
||||
"""Get the status of a file conversion. This function automatically base64 decodes the output response if there is one."""
|
||||
|
||||
fc = await fc_asyncio(
|
||||
id=id,
|
||||
client=client,
|
||||
)
|
||||
|
||||
if isinstance(fc, FileConversion) and fc.output != "":
|
||||
fc.output = base64.b64decode(fc.output)
|
||||
|
||||
return fc
|
Reference in New Issue
Block a user