|
38 | 38 |
|
39 | 39 |
|
40 | 40 | _bytes = bytes |
| 41 | +_str = str |
| 42 | +_int = int |
41 | 43 |
|
42 | 44 | logging_DEBUG = logging.DEBUG |
43 | 45 |
|
@@ -110,19 +112,23 @@ def datagram_received( |
110 | 112 | ) |
111 | 113 | return |
112 | 114 |
|
113 | | - v6_flow_scope: Union[Tuple[()], Tuple[int, int]] = () |
114 | 115 | if len(addrs) == 2: |
| 116 | + v6_flow_scope: Union[Tuple[()], Tuple[int, int]] = () |
115 | 117 | # https://github.com/python/mypy/issues/1178 |
116 | 118 | addr, port = addrs # type: ignore |
| 119 | + addr_port = addrs |
| 120 | + if TYPE_CHECKING: |
| 121 | + addr_port = cast(Tuple[str, int], addr_port) |
117 | 122 | scope = None |
118 | 123 | else: |
119 | 124 | # https://github.com/python/mypy/issues/1178 |
120 | 125 | addr, port, flow, scope = addrs # type: ignore |
121 | 126 | if debug: # pragma: no branch |
122 | 127 | log.debug('IPv6 scope_id %d associated to the receiving interface', scope) |
123 | 128 | v6_flow_scope = (flow, scope) |
| 129 | + addr_port = (addr, port) |
124 | 130 |
|
125 | | - msg = DNSIncoming(data, (addr, port), scope, now) |
| 131 | + msg = DNSIncoming(data, addr_port, scope, now) |
126 | 132 | self.data = data |
127 | 133 | self.last_time = now |
128 | 134 | self.last_message = msg |
@@ -176,22 +182,23 @@ def handle_query_or_defer( |
176 | 182 | return |
177 | 183 | deferred.append(msg) |
178 | 184 | delay = millis_to_seconds(random.randint(*_TC_DELAY_RANDOM_INTERVAL)) |
179 | | - assert self.zc.loop is not None |
| 185 | + loop = self.zc.loop |
| 186 | + assert loop is not None |
180 | 187 | self._cancel_any_timers_for_addr(addr) |
181 | | - self._timers[addr] = self.zc.loop.call_later( |
182 | | - delay, self._respond_query, None, addr, port, transport, v6_flow_scope |
| 188 | + self._timers[addr] = loop.call_at( |
| 189 | + loop.time() + delay, self._respond_query, None, addr, port, transport, v6_flow_scope |
183 | 190 | ) |
184 | 191 |
|
185 | | - def _cancel_any_timers_for_addr(self, addr: str) -> None: |
| 192 | + def _cancel_any_timers_for_addr(self, addr: _str) -> None: |
186 | 193 | """Cancel any future truncated packet timers for the address.""" |
187 | 194 | if addr in self._timers: |
188 | 195 | self._timers.pop(addr).cancel() |
189 | 196 |
|
190 | 197 | def _respond_query( |
191 | 198 | self, |
192 | 199 | msg: Optional[DNSIncoming], |
193 | | - addr: str, |
194 | | - port: int, |
| 200 | + addr: _str, |
| 201 | + port: _int, |
195 | 202 | transport: _WrappedTransport, |
196 | 203 | v6_flow_scope: Union[Tuple[()], Tuple[int, int]] = (), |
197 | 204 | ) -> None: |
|
0 commit comments