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
2022-04-06 21:14:12 -07:00
from . . . models import Error
from . . . models import FileConversionWithOutput
from . . . models import FileConversionSourceFormat
from . . . models import FileConversionOutputFormat
2021-12-15 06:11:05 -08:00
from . . . types import Response
2022-04-06 21:14:12 -07:00
from . . . api . file . create_file_conversion import sync as fc_sync , asyncio as fc_asyncio
2021-12-15 06:11:05 -08:00
def sync (
2022-04-06 21:14:12 -07:00
src_format : FileConversionSourceFormat ,
output_format : FileConversionOutputFormat ,
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 ,
2022-04-06 21:14:12 -07:00
) - > Optional [ Union [ Any , FileConversionWithOutput , Error ] ] :
2021-12-15 06:11:05 -08:00
""" 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 (
2022-04-06 21:14:12 -07:00
src_format = src_format ,
2021-12-15 06:11:05 -08:00
output_format = output_format ,
2022-02-27 22:30:43 -08:00
body = encoded ,
2021-12-15 06:11:05 -08:00
client = client ,
)
2022-04-06 21:14:12 -07:00
if isinstance ( fc , FileConversionWithOutput ) and fc . output != " " :
2021-12-15 06:11:05 -08:00
fc . output = base64 . b64decode ( fc . output )
return fc
async def asyncio (
2022-04-06 21:14:12 -07:00
src_format : FileConversionSourceFormat ,
output_format : FileConversionOutputFormat ,
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 ,
2022-04-06 21:14:12 -07:00
) - > Optional [ Union [ Any , FileConversionWithOutput , Error ] ] :
2021-12-15 06:11:05 -08:00
""" 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 (
2022-04-06 21:14:12 -07:00
src_format = src_format ,
2021-12-15 06:11:05 -08:00
output_format = output_format ,
2022-02-27 22:30:43 -08:00
body = encoded ,
2021-12-15 06:11:05 -08:00
client = client ,
)
2022-04-06 21:14:12 -07:00
if isinstance ( fc , FileConversionWithOutput ) and fc . output != " " :
2021-12-15 06:11:05 -08:00
fc . output = base64 . b64decode ( fc . output )
return fc