1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-03-22 13:19:13 +00:00

fix: remove HTTPStatus constructs introduced in Python 3.11 (#11573)

* fix: remove HTTPStatus constructs introduced in Python 3.11

* add changelog frag
This commit is contained in:
Alexei Znamensky 2026-03-13 08:46:55 +13:00 committed by GitHub
parent 4cd91ba4d4
commit f9e583dae2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 21 additions and 24 deletions

View file

@ -117,8 +117,7 @@ class UTM:
returns the info for an object in utm
"""
info, result = self._lookup_entry(self.module, self.request_url)
_status = HTTPStatus(info["status"])
if _status.is_client_error or _status.is_server_error:
if info["status"] >= HTTPStatus.BAD_REQUEST: # 4xx and 5xx errors
self.module.fail_json(result=json.loads(info))
else:
if result is None:
@ -135,8 +134,7 @@ class UTM:
is_changed = False
info, result = self._lookup_entry(self.module, self.request_url)
_status = HTTPStatus(info["status"])
if _status.is_client_error or _status.is_server_error:
if info["status"] >= HTTPStatus.BAD_REQUEST: # 4xx and 5xx errors
self.module.fail_json(result=json.loads(info))
else:
data_as_json_string = self.module.jsonify(self.module.params)
@ -144,8 +142,7 @@ class UTM:
response, info = fetch_url(
self.module, self.request_url, method="POST", headers=combined_headers, data=data_as_json_string
)
_status = HTTPStatus(info["status"])
if _status.is_client_error or _status.is_server_error:
if info["status"] >= HTTPStatus.BAD_REQUEST: # 4xx and 5xx errors
self.module.fail_json(msg=json.loads(info["body"]))
is_changed = True
result = self._clean_result(json.loads(response.read()))
@ -158,8 +155,7 @@ class UTM:
headers=combined_headers,
data=data_as_json_string,
)
_status = HTTPStatus(info["status"])
if _status.is_client_error or _status.is_server_error:
if info["status"] >= HTTPStatus.BAD_REQUEST: # 4xx and 5xx errors
self.module.fail_json(msg=json.loads(info["body"]))
is_changed = True
result = self._clean_result(json.loads(response.read()))
@ -192,8 +188,7 @@ class UTM:
headers={"Accept": "application/json", "X-Restd-Err-Ack": "all"},
data=self.module.jsonify(self.module.params),
)
_status = HTTPStatus(info["status"])
if _status.is_client_error or _status.is_server_error:
if info["status"] >= HTTPStatus.BAD_REQUEST: # 4xx and 5xx errors
self.module.fail_json(msg=json.loads(info["body"]))
else:
is_changed = True