|
13 | 13 |
|
14 | 14 |
|
15 | 15 | class RequestedResponseFormats(StrEnum): |
16 | | - DICT = ValidAcceptHeaders.JSON # Convert to dict using json.loads() |
| 16 | + DICT = ValidAcceptHeaders.JSON # Convert to dict using Response.json() |
17 | 17 | DECODED_STRING = ValidAcceptHeaders.PLAIN_TEXT # Use utf-8 decoding in response |
18 | 18 | RAW_BYTE_STRING = ValidAcceptHeaders.RAW_BYTES # Use raw bytes in response |
19 | 19 |
|
@@ -60,11 +60,10 @@ def _cached_get( |
60 | 60 | """ |
61 | 61 |
|
62 | 62 | try: |
63 | | - r = requests.get( |
64 | | - self._url + endpoint + (f"/{item}"), headers={"Accept": accept_header} |
65 | | - ) |
| 63 | + request_url = self._url + endpoint + (f"/{item}") |
| 64 | + r = requests.get(request_url, headers={"Accept": accept_header}) |
66 | 65 | r.raise_for_status() |
67 | | - self._log.debug(f"Cache set for {endpoint}/{item}.") |
| 66 | + self._log.debug(f"Cache set for {request_url}.") |
68 | 67 | return r |
69 | 68 | except requests.exceptions.HTTPError as e: |
70 | 69 | self._log.error(f"HTTP error: {e}") |
@@ -121,21 +120,22 @@ def get_file_contents( |
121 | 120 | ) -> Any: |
122 | 121 | """ |
123 | 122 | Get contents of a file from the config server in the format specified. |
124 | | - If data parsing fails, the return type will be bytes. Optionally try to use |
125 | | - cached result. |
| 123 | + If data parsing fails, contents will return as raw bytes. Optionally look |
| 124 | + for cached result before making request. |
126 | 125 |
|
127 | 126 | Args: |
128 | 127 | file_path: Path to the file. |
129 | 128 | requested_response_format: Specify how to parse the response. |
130 | | - reset_cached_result: Whether to reset cache for specific request. |
| 129 | + reset_cached_result: If true, make a request and store response in cache, |
| 130 | + otherwise look for cached response before making |
| 131 | + new request |
131 | 132 | Returns: |
132 | 133 | The file contents, in the format specified. |
133 | 134 | """ |
134 | 135 |
|
135 | | - accept_header = requested_response_format |
136 | 136 | return self._get( |
137 | 137 | ENDPOINTS.CONFIG, |
138 | | - accept_header, |
| 138 | + requested_response_format, |
139 | 139 | file_path, |
140 | 140 | reset_cached_result=reset_cached_result, |
141 | 141 | ) |
0 commit comments