Skip to content

Commit f72cf87

Browse files
committed
Refactor
1 parent b6920f1 commit f72cf87

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

pymongo/asynchronous/srv_resolver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,19 @@ async def _get_srv_response_and_hosts(
129129
) -> tuple[resolver.Answer, list[tuple[str, Any]]]:
130130
results = await self._resolve_uri(encapsulate_errors)
131131

132-
if self.__fqdn == results[0].target.to_text():
133-
raise ConfigurationError(
134-
"Invalid SRV host: return address is identical to SRV hostname"
135-
)
136-
137132
# Construct address tuples
138133
nodes = [
139134
(maybe_decode(res.target.to_text(omit_final_dot=True)), res.port) # type: ignore[attr-defined]
140135
for res in results
141136
]
142137

143138
# Validate hosts
139+
srv_host = results[0].target.to_text()
144140
for node in nodes:
141+
if self.__fqdn == srv_host:
142+
raise ConfigurationError(
143+
"Invalid SRV host: return address is identical to SRV hostname"
144+
)
145145
try:
146146
nlist = node[0].lower().split(".")[1:][-self.__slen :]
147147
except Exception:

pymongo/synchronous/srv_resolver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,19 @@ def _get_srv_response_and_hosts(
129129
) -> tuple[resolver.Answer, list[tuple[str, Any]]]:
130130
results = self._resolve_uri(encapsulate_errors)
131131

132-
if self.__fqdn == results[0].target.to_text():
133-
raise ConfigurationError(
134-
"Invalid SRV host: return address is identical to SRV hostname"
135-
)
136-
137132
# Construct address tuples
138133
nodes = [
139134
(maybe_decode(res.target.to_text(omit_final_dot=True)), res.port) # type: ignore[attr-defined]
140135
for res in results
141136
]
142137

143138
# Validate hosts
139+
srv_host = results[0].target.to_text()
144140
for node in nodes:
141+
if self.__fqdn == srv_host:
142+
raise ConfigurationError(
143+
"Invalid SRV host: return address is identical to SRV hostname"
144+
)
145145
try:
146146
nlist = node[0].lower().split(".")[1:][-self.__slen :]
147147
except Exception:

0 commit comments

Comments
 (0)