File: responses.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (126 lines) | stat: -rw-r--r-- 3,915 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import json

from moto.core.common_types import TYPE_RESPONSE
from moto.core.responses import BaseResponse

from .models import RekognitionBackend, rekognition_backends


class RekognitionResponse(BaseResponse):
    """Handler for Rekognition requests and responses."""

    def __init__(self) -> None:
        super().__init__(service_name="rekognition")

    @property
    def rekognition_backend(self) -> RekognitionBackend:
        return rekognition_backends[self.current_account][self.region]

    def get_face_search(self) -> str:
        (
            job_status,
            status_message,
            video_metadata,
            persons,
            next_token,
            text_model_version,
        ) = self.rekognition_backend.get_face_search()

        return json.dumps(
            {
                "JobStatus": job_status,
                "StatusMessage": status_message,
                "VideoMetadata": video_metadata,
                "Persons": persons,
                "NextToken": next_token,
                "TextModelVersion": text_model_version,
            }
        )

    def get_text_detection(self) -> str:
        (
            job_status,
            status_message,
            video_metadata,
            text_detections,
            next_token,
            text_model_version,
        ) = self.rekognition_backend.get_text_detection()

        return json.dumps(
            {
                "JobStatus": job_status,
                "StatusMessage": status_message,
                "VideoMetadata": video_metadata,
                "TextDetections": text_detections,
                "NextToken": next_token,
                "TextModelVersion": text_model_version,
            }
        )

    def compare_faces(self) -> str:
        (
            face_matches,
            source_image_orientation_correction,
            target_image_orientation_correction,
            unmatched_faces,
            source_image_face,
        ) = self.rekognition_backend.compare_faces()

        return json.dumps(
            {
                "FaceMatches": face_matches,
                "SourceImageOrientationCorrection": source_image_orientation_correction,
                "TargetImageOrientationCorrection": target_image_orientation_correction,
                "UnmatchedFaces": unmatched_faces,
                "SourceImageFace": source_image_face,
            }
        )

    def detect_labels(self) -> str:
        (
            labels,
            image_properties,
            label_model_version,
        ) = self.rekognition_backend.detect_labels()
        return json.dumps(
            {
                "Labels": labels,
                "ImageProperties": image_properties,
                "LabelModelVersion": label_model_version,
            }
        )

    def detect_text(self) -> str:
        (
            text_detections,
            text_model_version,
        ) = self.rekognition_backend.detect_text()
        return json.dumps(
            {
                "TextDetections": text_detections,
                "TextModelVersion": text_model_version,
            }
        )

    def detect_custom_labels(self) -> str:
        (custom_labels,) = self.rekognition_backend.detect_custom_labels()
        return json.dumps(
            {
                "CustomLabels": custom_labels,
            }
        )

    def start_face_search(self) -> TYPE_RESPONSE:
        headers = {"Content-Type": "application/x-amz-json-1.1"}
        job_id = self.rekognition_backend.start_face_search()
        response = ('{"JobId":"' + job_id + '"}').encode()

        return 200, headers, response

    def start_text_detection(self) -> TYPE_RESPONSE:
        headers = {"Content-Type": "application/x-amz-json-1.1"}
        job_id = self.rekognition_backend.start_text_detection()
        response = ('{"JobId":"' + job_id + '"}').encode()

        return 200, headers, response