11import os
22import io
33import zipfile
4- from typing import List , Optional
5-
6- from typing import List , Optional
74
85import traceback
96import yaml
@@ -27,25 +24,26 @@ class Lyrx(BaseModel):
2724 type : str
2825 version : str
2926 build : int
30- layers : Optional [ List [ str ]]
31- layerDefinitions : List [dict ]
32- binaryReferences : Optional [ List [ dict ]]
33- elevationSurfaces : Optional [ List [ dict ]]
34- rGBColorProfile : Optional [ str ]
35- cMYKColorProfile : Optional [ str ]
27+ layers : list [ str ] | None = None
28+ layerDefinitions : list [dict ]
29+ binaryReferences : list [ dict ] | None = None
30+ elevationSurfaces : list [ dict ] | None = None
31+ rGBColorProfile : str | None = None
32+ cMYKColorProfile : str | None
3633
3734
3835app = FastAPI ()
3936
4037LOG = logging .getLogger ("app" )
41- with open (' config.yaml' ) as f :
38+ with open (" config.yaml" ) as f :
4239 config = yaml .load (f , Loader = yaml .FullLoader )
4340 logging .config .dictConfig (config )
4441
42+
4543@app .post ("/v1/lyrx2sld/" )
4644async def lyrx_to_sld (lyrx : Lyrx , replaceesri : bool = False ):
4745
48- options = {' tolowercase' : True , ' replaceesri' : replaceesri }
46+ options = {" tolowercase" : True , " replaceesri" : replaceesri }
4947 warnings = []
5048
5149 try :
@@ -69,20 +67,14 @@ async def lyrx_to_sld(lyrx: Lyrx, replaceesri: bool = False):
6967 return Response (
7068 content = s .getvalue (),
7169 media_type = "application/x-zip-compressed" ,
72- headers = {
73- 'Content-Disposition' : 'attachment;filename=style.zip'
74- }
75- )
70+ headers = {"Content-Disposition" : "attachment;filename=style.zip" },
71+ )
7672
7773 except Exception as e :
7874 errors = traceback .format_exception (None , e , e .__traceback__ )
7975 for error in errors :
8076 LOG .error (error )
8177 return JSONResponse (
8278 status_code = status .HTTP_422_UNPROCESSABLE_ENTITY ,
83- content = jsonable_encoder (
84- {
85- 'warnings' : warnings ,
86- 'errors' : errors
87- })
88- )
79+ content = jsonable_encoder ({"warnings" : warnings , "errors" : errors }),
80+ )
0 commit comments