2021-12-15 06:11:05 -08:00
from typing import Any , Dict , Optional , Union
2021-12-15 06:14:46 -08:00
import base64
2021-12-15 06:11:05 -08:00
import httpx
2022-02-27 22:24:39 -08:00
from . . . client import Client
2021-12-15 06:11:05 -08:00
from . . . models . file_conversion import FileConversion
2022-02-27 22:25:36 -08:00
from . . . models . valid_source_file_format import ValidSourceFileFormat
from . . . models . valid_output_file_format import ValidOutputFileFormat
2021-12-15 06:11:05 -08:00
from . . . types import Response
2022-02-27 21:48:13 -08:00
from . . . api . file . post_file_conversion import sync as fc_sync , asyncio as fc_asyncio
2021-12-15 06:11:05 -08:00
def sync (
2022-02-27 22:25:36 -08:00
source_format : ValidSourceFileFormat ,
output_format : ValidOutputFileFormat ,
2022-02-27 22:30:43 -08:00
body : bytes ,
2021-12-15 06:11:05 -08:00
* ,
2022-02-27 22:24:39 -08:00
client : Client ,
2021-12-15 06:11:05 -08:00
) - > Optional [ Union [ Any , FileConversion ] ] :
""" 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. """
2022-02-27 22:30:43 -08:00
encoded = base64 . b64encode ( body )
2021-12-15 06:11:05 -08:00
fc = fc_sync (
source_format = source_format ,
output_format = output_format ,
2022-02-27 22:30:43 -08:00
body = encoded ,
2021-12-15 06:11:05 -08:00
client = client ,
)
2021-12-15 08:33:25 -08:00
if fc != None and fc . output != " " :
2021-12-15 06:11:05 -08:00
fc . output = base64 . b64decode ( fc . output )
return fc
async def asyncio (
2022-02-27 22:25:36 -08:00
source_format : ValidSourceFileFormat ,
output_format : ValidOutputFileFormat ,
2022-02-27 22:30:43 -08:00
body : bytes ,
2021-12-15 06:11:05 -08:00
* ,
2022-02-27 22:24:39 -08:00
client : Client ,
2021-12-15 06:11:05 -08:00
) - > Optional [ Union [ Any , FileConversion ] ] :
""" 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. """
2022-02-27 22:30:43 -08:00
encoded = base64 . b64encode ( body )
2021-12-15 06:11:05 -08:00
2021-12-15 06:21:45 -08:00
fc = await fc_asyncio (
2021-12-15 06:11:05 -08:00
source_format = source_format ,
output_format = output_format ,
2022-02-27 22:30:43 -08:00
body = encoded ,
2021-12-15 06:11:05 -08:00
client = client ,
)
2021-12-15 08:33:25 -08:00
if fc != None and fc . output != " " :
2021-12-15 06:11:05 -08:00
fc . output = base64 . b64decode ( fc . output )
return fc