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
2021-12-15 15:46:54 -08:00
from . . . models . valid_file_type import ValidFileType
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 (
2021-12-15 15:46:54 -08:00
source_format : ValidFileType ,
output_format : ValidFileType ,
2021-12-15 06:11:05 -08:00
content : bytes ,
* ,
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. """
encoded = base64 . b64encode ( content )
fc = fc_sync (
source_format = source_format ,
output_format = output_format ,
content = encoded ,
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 (
2021-12-15 15:46:54 -08:00
source_format : ValidFileType ,
output_format : ValidFileType ,
2021-12-15 06:11:05 -08:00
content : bytes ,
* ,
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. """
encoded = base64 . b64encode ( content )
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 ,
content = encoded ,
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