1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-23 20:29:08 +00:00

[PR #11573/f9e583da backport][stable-12] fix: remove HTTPStatus constructs introduced in Python 3.11 (#11575)

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

* fix: remove HTTPStatus constructs introduced in Python 3.11

* add changelog frag

(cherry picked from commit f9e583dae2)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2026-03-12 20:59:26 +01:00 committed by GitHub
parent 7f8bc6f99d
commit 7415220cad
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