Skip to content

Commit

Permalink
Remove fallback to getservbyname in _get_default_port (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Sep 1, 2024
1 parent 6339581 commit 7c1220b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGES/1076.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Removed support :rfc:`3986#section-3.2.3` port normalization when the scheme is not one of ``http``, ``https``, ``wss``, or ``ws`` -- by :user:`bdraco`.

Support for port normalization was recently added in :issue:`1033` and contained code that would do blocking I/O if the scheme was not one of the four listed above. The code has been removed because this library is intended to be safe for usage with ``asyncio``.
13 changes: 3 additions & 10 deletions yarl/_url.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import functools
import math
import socket
import warnings
from collections.abc import Mapping, Sequence
from contextlib import suppress
Expand Down Expand Up @@ -423,16 +422,10 @@ def raw_authority(self):
return self._val.netloc

def _get_default_port(self) -> Union[int, None]:
if not self.scheme:
scheme = self.scheme
if not scheme:
return None

with suppress(KeyError):
return DEFAULT_PORTS[self.scheme]

with suppress(OSError):
return socket.getservbyname(self.scheme)

return None
return DEFAULT_PORTS.get(scheme)

def _get_port(self) -> Union[int, None]:
"""Port or None if default port"""
Expand Down

0 comments on commit 7c1220b

Please sign in to comment.