22
33import abc
44import csv
5- import json
65import re
76from dataclasses import dataclass , field
87from typing import Any , Callable , Dict , Generator , Iterable , List , Literal , Optional
@@ -113,7 +112,7 @@ def write(self, line: str):
113112
114113def create_html_response (
115114 request : Request ,
116- data : str ,
115+ data : Any ,
117116 templates : Jinja2Templates ,
118117 template_name : str ,
119118 router_prefix : Optional [str ] = None ,
@@ -142,7 +141,7 @@ def create_html_response(
142141 request ,
143142 name = f"{ template_name } .html" ,
144143 context = {
145- "response" : orjson . loads ( data ) ,
144+ "response" : data ,
146145 "template" : {
147146 "api_root" : baseurl ,
148147 "params" : request .query_params ,
@@ -207,7 +206,7 @@ def url_for(self, request: Request, name: str, **path_params: Any) -> str:
207206 def _create_html_response (
208207 self ,
209208 request : Request ,
210- data : str ,
209+ data : Any ,
211210 template_name : str ,
212211 ) -> _TemplateResponse :
213212 return create_html_response (
@@ -262,7 +261,7 @@ def conformance(
262261 if output_type == MediaType .html :
263262 return self ._create_html_response (
264263 request ,
265- data .model_dump_json (exclude_none = True ),
264+ data .model_dump (exclude_none = True , mode = "json" ),
266265 template_name = "conformance" ,
267266 )
268267
@@ -325,7 +324,7 @@ def landing(
325324 if output_type == MediaType .html :
326325 return self ._create_html_response (
327326 request ,
328- data .model_dump_json (exclude_none = True ),
327+ data .model_dump (exclude_none = True , mode = "json" ),
329328 template_name = "landing" ,
330329 )
331330
@@ -354,33 +353,36 @@ def links(self, request: Request) -> List[model.Link]:
354353 rel = "data" ,
355354 ),
356355 model .Link (
357- title = "Collection metadata" ,
356+ title = "Collection metadata (Template URL) " ,
358357 href = self .url_for (
359358 request ,
360359 "collection" ,
361360 collectionId = "{collectionId}" ,
362361 ),
363362 type = MediaType .json ,
364363 rel = "data" ,
364+ templated = True ,
365365 ),
366366 model .Link (
367- title = "Collection queryables" ,
367+ title = "Collection queryables (Template URL) " ,
368368 href = self .url_for (
369369 request ,
370370 "queryables" ,
371371 collectionId = "{collectionId}" ,
372372 ),
373373 type = MediaType .schemajson ,
374374 rel = "queryables" ,
375+ templated = True ,
375376 ),
376377 model .Link (
377- title = "Collection Features" ,
378+ title = "Collection Features (Template URL) " ,
378379 href = self .url_for (request , "items" , collectionId = "{collectionId}" ),
379380 type = MediaType .geojson ,
380381 rel = "data" ,
382+ templated = True ,
381383 ),
382384 model .Link (
383- title = "Collection Feature" ,
385+ title = "Collection Feature (Template URL) " ,
384386 href = self .url_for (
385387 request ,
386388 "item" ,
@@ -389,6 +391,7 @@ def links(self, request: Request) -> List[model.Link]:
389391 ),
390392 type = MediaType .geojson ,
391393 rel = "data" ,
394+ templated = True ,
392395 ),
393396 ]
394397
@@ -515,7 +518,7 @@ def collections(
515518 if output_type == MediaType .html :
516519 return self ._create_html_response (
517520 request ,
518- data .model_dump_json (exclude_none = True ),
521+ data .model_dump (exclude_none = True , mode = "json" ),
519522 template_name = "collections" ,
520523 )
521524
@@ -602,7 +605,7 @@ def collection(
602605 if output_type == MediaType .html :
603606 return self ._create_html_response (
604607 request ,
605- data .model_dump_json (exclude_none = True ),
608+ data .model_dump (exclude_none = True , mode = "json" ),
606609 template_name = "collection" ,
607610 )
608611
@@ -647,7 +650,7 @@ def queryables(
647650 if output_type == MediaType .html :
648651 return self ._create_html_response (
649652 request ,
650- data .model_dump_json (exclude_none = True ),
653+ data .model_dump (exclude_none = True , mode = "json" ),
651654 template_name = "queryables" ,
652655 )
653656
@@ -902,7 +905,9 @@ async def items( # noqa: C901
902905 # HTML Response
903906 if output_type == MediaType .html :
904907 return self ._create_html_response (
905- request , orjsonDumps (data ).decode (), template_name = "items"
908+ request ,
909+ orjson .loads (orjsonDumps (data ).decode ()),
910+ template_name = "items" ,
906911 )
907912
908913 # GeoJSONSeq Response
@@ -1067,7 +1072,7 @@ async def item(
10671072 if output_type == MediaType .html :
10681073 return self ._create_html_response (
10691074 request ,
1070- orjsonDumps (data ).decode (),
1075+ orjson . loads ( orjsonDumps (data ).decode () ),
10711076 template_name = "item" ,
10721077 )
10731078
@@ -1091,7 +1096,7 @@ def links(self, request: Request) -> List[model.Link]:
10911096 """OGC Tiles API links."""
10921097 return [
10931098 model .Link (
1094- title = "Collection Vector Tiles" ,
1099+ title = "Collection Vector Tiles (Template URL) " ,
10951100 href = self .url_for (
10961101 request ,
10971102 "collection_get_tile" ,
@@ -1102,19 +1107,21 @@ def links(self, request: Request) -> List[model.Link]:
11021107 ),
11031108 type = MediaType .mvt ,
11041109 rel = "data" ,
1110+ templated = True ,
11051111 ),
11061112 model .Link (
1107- title = "Collection TileSets" ,
1113+ title = "Collection TileSets (Template URL) " ,
11081114 href = self .url_for (
11091115 request ,
11101116 "collection_tileset_list" ,
11111117 collectionId = "{collectionId}" ,
11121118 ),
11131119 type = MediaType .json ,
11141120 rel = "data" ,
1121+ templated = True ,
11151122 ),
11161123 model .Link (
1117- title = "Collection TileSet" ,
1124+ title = "Collection TileSet (Template URL) " ,
11181125 href = self .url_for (
11191126 request ,
11201127 "collection_tileset" ,
@@ -1123,6 +1130,7 @@ def links(self, request: Request) -> List[model.Link]:
11231130 ),
11241131 type = MediaType .json ,
11251132 rel = "data" ,
1133+ templated = True ,
11261134 ),
11271135 model .Link (
11281136 title = "TileMatrixSets" ,
@@ -1134,14 +1142,15 @@ def links(self, request: Request) -> List[model.Link]:
11341142 rel = "data" ,
11351143 ),
11361144 model .Link (
1137- title = "TileMatrixSet" ,
1145+ title = "TileMatrixSet (Template URL) " ,
11381146 href = self .url_for (
11391147 request ,
11401148 "tilematrixset" ,
11411149 tileMatrixSetId = "{tileMatrixSetId}" ,
11421150 ),
11431151 type = MediaType .json ,
11441152 rel = "data" ,
1153+ templated = True ,
11451154 ),
11461155 ]
11471156
@@ -1201,7 +1210,7 @@ async def tilematrixsets(
12011210 if output_type == MediaType .html :
12021211 return self ._create_html_response (
12031212 request ,
1204- data .model_dump_json (exclude_none = True ),
1213+ data .model_dump (exclude_none = True , mode = "json" ),
12051214 template_name = "tilematrixsets" ,
12061215 )
12071216
@@ -1234,23 +1243,20 @@ async def tilematrixset(
12341243 """
12351244 OGC Specification: http://docs.opengeospatial.org/per/19-069.html#_tilematrixset
12361245 """
1237- data = self .supported_tms .get (tileMatrixSetId )
1246+ tms = self .supported_tms .get (tileMatrixSetId )
12381247
12391248 if output_type == MediaType .html :
1240- # For visualization purpose we add the tms bbox
1241- data = {
1242- ** data .model_dump (exclude_none = True , mode = "json" ),
1243- "bbox" : data .bbox ,
1244- }
12451249 return self ._create_html_response (
12461250 request ,
1247- json .dumps (
1248- data ,
1249- ),
1251+ {
1252+ ** tms .model_dump (exclude_none = True , mode = "json" ),
1253+ # For visualization purpose we add the tms bbox
1254+ "bbox" : tms .bbox ,
1255+ },
12501256 template_name = "tilematrixset" ,
12511257 )
12521258
1253- return data
1259+ return tms
12541260
12551261 def _tilesets_routes (self ):
12561262 @self .router .get (
@@ -1338,7 +1344,7 @@ async def collection_tileset_list(
13381344 if output_type == MediaType .html :
13391345 return self ._create_html_response (
13401346 request ,
1341- data .model_dump_json (exclude_none = True ),
1347+ data .model_dump (exclude_none = True , mode = "json" ),
13421348 template_name = "tilesets" ,
13431349 )
13441350
@@ -1452,7 +1458,7 @@ async def collection_tileset(
14521458 if output_type == MediaType .html :
14531459 return self ._create_html_response (
14541460 request ,
1455- data .model_dump_json (exclude_none = True ),
1461+ data .model_dump (exclude_none = True , mode = "json" ),
14561462 template_name = "tileset" ,
14571463 )
14581464
@@ -1713,12 +1719,7 @@ async def collection_stylejson(
17131719 minzoom = minzoom if minzoom is not None else tms .minzoom
17141720 maxzoom = maxzoom if maxzoom is not None else tms .maxzoom
17151721
1716- bounds = collection .bounds or [
1717- 180 ,
1718- - 85.05112877980659 ,
1719- 180 ,
1720- 85.0511287798066 ,
1721- ]
1722+ bounds = list (collection .bounds ) or list (tms .bbox )
17221723
17231724 style_json = {
17241725 "name" : "TiPg" ,
0 commit comments