-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathdecoder.py
More file actions
32 lines (25 loc) · 855 Bytes
/
decoder.py
File metadata and controls
32 lines (25 loc) · 855 Bytes
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
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
from abc import abstractmethod
from dataclasses import dataclass
from typing import Any, Generator, MutableMapping
import requests
DECODER_OUTPUT_TYPE = Generator[MutableMapping[str, Any], None, None]
@dataclass
class Decoder:
"""
Decoder strategy to transform a requests.Response into a Mapping[str, Any]
"""
@abstractmethod
def is_stream_response(self) -> bool:
"""
Set to True if you'd like to use stream=True option in http requester
"""
@abstractmethod
def decode(self, response: requests.Response) -> DECODER_OUTPUT_TYPE:
"""
Decodes a requests.Response into a Mapping[str, Any] or an array
:param response: the response to decode
:return: Generator of Mapping describing the response
"""