3838
3939_ROUTES : set [Route ] = set ()
4040
41- _ResponseType = str
41+ _ResponseType = tuple [ int , dict [ str , str ], str ]
4242
4343
4444def route (
4545 path_pattern : str ,
4646 http_methods : set [HTTPMethod ],
47- ) -> Callable [[Callable [..., str ]], Callable [..., _ResponseType ]]:
47+ ) -> Callable [[Callable [..., _ResponseType ]], Callable [..., _ResponseType ]]:
4848 """
4949 Register a decorated method so that it can be recognized as a route.
5050
@@ -184,14 +184,14 @@ def add_target(self, request: PreparedRequest) -> _ResponseType:
184184 localtime = False ,
185185 usegmt = True ,
186186 )
187- context . status_code = HTTPStatus .CREATED
187+ status_code = HTTPStatus .CREATED
188188 body = {
189189 "transaction_id" : uuid .uuid4 ().hex ,
190190 "result_code" : ResultCodes .TARGET_CREATED .value ,
191191 "target_id" : new_target .target_id ,
192192 }
193193 body_json = json_dump (body = body )
194- context . headers = {
194+ headers = {
195195 "Connection" : "keep-alive" ,
196196 "Content-Type" : "application/json" ,
197197 "server" : "envoy" ,
@@ -202,7 +202,7 @@ def add_target(self, request: PreparedRequest) -> _ResponseType:
202202 "x-aws-region" : "us-east-2, us-west-2" ,
203203 "x-content-type-options" : "nosniff" ,
204204 }
205- return body_json
205+ return status_code , headers , body_json
206206
207207 @route (
208208 path_pattern = f"/targets/{ _TARGET_ID_PATTERN } " ,
@@ -240,9 +240,11 @@ def delete_target(self, request: PreparedRequest) -> _ResponseType:
240240
241241 if target .status == TargetStatuses .PROCESSING .value :
242242 target_processing_exception = TargetStatusProcessingError ()
243- context .headers = target_processing_exception .headers
244- context .status_code = target_processing_exception .status_code
245- return target_processing_exception .response_text
243+ return (
244+ target_processing_exception .status_code ,
245+ target_processing_exception .headers ,
246+ target_processing_exception .response_text ,
247+ )
246248
247249 now = datetime .datetime .now (tz = target .upload_date .tzinfo )
248250 new_target = dataclasses .replace (target , delete_date = now )
@@ -280,7 +282,6 @@ def database_summary(self, request: PreparedRequest) -> _ResponseType:
280282 Fake implementation of
281283 https://developer.vuforia.com/library/web-api/cloud-targets-web-services-api#summary-report
282284 """
283- breakpoint ()
284285 try :
285286 run_services_validators (
286287 request_headers = request .headers ,
@@ -516,7 +517,7 @@ def get_duplicates(self, request: PreparedRequest) -> _ResponseType:
516517 "similar_targets" : similar_targets ,
517518 }
518519 body_json = json_dump (body = body )
519- context . headers = {
520+ headers = {
520521 "Connection" : "keep-alive" ,
521522 "Content-Length" : str (len (body_json )),
522523 "Content-Type" : "application/json" ,
@@ -528,7 +529,7 @@ def get_duplicates(self, request: PreparedRequest) -> _ResponseType:
528529 "x-content-type-options" : "nosniff" ,
529530 }
530531
531- return body_json
532+ return HTTPStatus . OK , headers , body_json
532533
533534 @route (
534535 path_pattern = f"/targets/{ _TARGET_ID_PATTERN } " ,
@@ -572,9 +573,11 @@ def update_target(self, request: PreparedRequest) -> _ResponseType:
572573
573574 if target .status != TargetStatuses .SUCCESS .value :
574575 exception = TargetStatusNotSuccessError ()
575- context .headers = exception .headers
576- context .status_code = exception .status_code
577- return exception .response_text
576+ return (
577+ exception .status_code ,
578+ exception .headers ,
579+ exception .response_text ,
580+ )
578581
579582 request_json : dict [str , Any ] = json .loads (s = request .body or b"" )
580583 width = request_json .get ("width" , target .width )
@@ -591,18 +594,22 @@ def update_target(self, request: PreparedRequest) -> _ResponseType:
591594
592595 if "active_flag" in request_json and active_flag is None :
593596 fail_exception = FailError (status_code = HTTPStatus .BAD_REQUEST )
594- context .headers = fail_exception .headers
595- context .status_code = fail_exception .status_code
596- return fail_exception .response_text
597+ return (
598+ fail_exception .status_code ,
599+ fail_exception .headers ,
600+ fail_exception .response_text ,
601+ )
597602
598603 if (
599604 "application_metadata" in request_json
600605 and application_metadata is None
601606 ):
602607 fail_exception = FailError (status_code = HTTPStatus .BAD_REQUEST )
603- context .headers = fail_exception .headers
604- context .status_code = fail_exception .status_code
605- return fail_exception .response_text
608+ return (
609+ fail_exception .status_code ,
610+ fail_exception .headers ,
611+ fail_exception .response_text ,
612+ )
606613
607614 gmt = ZoneInfo (key = "GMT" )
608615 last_modified_date = datetime .datetime .now (tz = gmt )
@@ -636,7 +643,7 @@ def update_target(self, request: PreparedRequest) -> _ResponseType:
636643 "x-aws-region" : "us-east-2, us-west-2" ,
637644 "x-content-type-options" : "nosniff" ,
638645 }
639- return body_json
646+ return HTTPStatus . OK , headers , body_json
640647
641648 @route (
642649 path_pattern = f"/summary/{ _TARGET_ID_PATTERN } " ,
@@ -658,9 +665,7 @@ def target_summary(self, request: PreparedRequest) -> _ResponseType:
658665 databases = self ._target_manager .databases ,
659666 )
660667 except ValidatorError as exc :
661- context .headers = exc .headers
662- context .status_code = exc .status_code
663- return exc .response_text
668+ return exc .status_code , exc .headers , exc .response_text
664669
665670 database = get_database_matching_server_keys (
666671 request_headers = request .headers ,
@@ -691,7 +696,7 @@ def target_summary(self, request: PreparedRequest) -> _ResponseType:
691696 "previous_month_recos" : target .previous_month_recos ,
692697 }
693698 body_json = json_dump (body = body )
694- context . headers = {
699+ headers = {
695700 "Connection" : "keep-alive" ,
696701 "Content-Length" : str (len (body_json )),
697702 "Content-Type" : "application/json" ,
@@ -703,4 +708,4 @@ def target_summary(self, request: PreparedRequest) -> _ResponseType:
703708 "x-content-type-options" : "nosniff" ,
704709 }
705710
706- return body_json
711+ return HTTPStatus . OK , headers , body_json
0 commit comments