* bump Signed-off-by: Jess Frazelle <github@jessfraz.com> * some fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * YOYO NEW API SPEC! * reformat Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixups Signed-off-by: Jess Frazelle <github@jessfraz.com> * for now force true Signed-off-by: Jess Frazelle <github@jessfraz.com> * run the tests on generations Signed-off-by: Jess Frazelle <github@jessfraz.com> * add tests Signed-off-by: Jess Frazelle <github@jessfraz.com> * update Signed-off-by: Jess Frazelle <github@jessfraz.com> * update Signed-off-by: Jess Frazelle <github@jessfraz.com> * update Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * update Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix some types Signed-off-by: Jess Frazelle <github@jessfraz.com> * float to top Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix mypy Signed-off-by: Jess Frazelle <github@jessfraz.com> * more noqa Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixups Signed-off-by: Jess Frazelle <github@jessfraz.com> * ruff pass Signed-off-by: Jess Frazelle <github@jessfraz.com> * add docs Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * even less mypy errors Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * add test Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixups Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * new path Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes for mypy Signed-off-by: Jess Frazelle <github@jessfraz.com> * skip tests Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
import base64
|
|
from typing import Any, Optional, Union
|
|
|
|
from ...api.file.create_file_conversion import asyncio as fc_asyncio, sync as fc_sync
|
|
from ...client import Client
|
|
from ...models import Error, FileConversion, FileExportFormat, FileImportFormat
|
|
|
|
|
|
def sync(
|
|
src_format: FileImportFormat,
|
|
output_format: FileExportFormat,
|
|
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 != "":
|
|
if isinstance(fc.output, str):
|
|
b = base64.b64decode(fc.output)
|
|
# decode the bytes to a string
|
|
fc.output = b.decode("utf-8")
|
|
|
|
return fc
|
|
|
|
|
|
async def asyncio(
|
|
src_format: FileImportFormat,
|
|
output_format: FileExportFormat,
|
|
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 != "":
|
|
if isinstance(fc.output, str):
|
|
b = base64.b64decode(fc.output)
|
|
# decode the bytes to a string
|
|
fc.output = b.decode("utf-8")
|
|
|
|
return fc
|