Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #68: allow IPv6 literal in to_uri() #1

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
python: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "pypy2", "pypy3"]
python: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9"]#, "pypy2.7", "pypy3.9"]

steps:

- name: Checkout source code
uses: actions/checkout@v2

- name: Install Python
uses: actions/setup-python@v1
uses: MatteoH2O1999/setup-python@v4
with:
python-version: ${{ matrix.python }}

Expand All @@ -204,7 +204,7 @@ jobs:
set -eux
py="${{ matrix.python }}";
if [[ $py =~ pypy ]]; then # PyPy
py_test="${py}";
py_test="${py/./}"; # remove "."
else # CPython
py_test="py${py/./}"; # Add "py" prefix, remove "."
fi;
Expand All @@ -215,7 +215,7 @@ jobs:

- name: Upload pytest log artifact
if: failure()
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: pytest-logs
path: pytest-logs.tgz
Expand Down
18 changes: 17 additions & 1 deletion src/hyperlink/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,22 @@ def user(self):
"""
return self.userinfo.split(u":")[0]

@property
def _host_idna_error(self):
# type: () -> bool
"""Whether idna can encode the host

idna does not encode empty strings and ipv6 addresses.
This is by design.
"""
if not hasattr(self, "_host_is_ipv6_literal"):
try:
socket.inet_pton(socket.AF_INET6, self.host)
self._host_is_ipv6_literal = True
except OSError:
self._host_is_ipv6_literal = False
return self._host_is_ipv6_literal or not self.host

def authority(self, with_password=False, **kw):
# type: (bool, Any) -> Text
"""Compute and return the appropriate host/port/userinfo combination.
Expand Down Expand Up @@ -1669,7 +1685,7 @@ def to_uri(self):
)
new_host = (
self.host
if not self.host
if self._host_idna_error
else idna_encode(self.host, uts46=True).decode("ascii")
)
return self.replace(
Expand Down
30 changes: 19 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,28 @@ basepython =
py39: python3.9
py310: python3.10

pypy2: pypy
pypy3: pypy3
pypy27: pypy
pypy39: pypy3

deps =
{[default]deps}

# In Python 2, we need to pull in typing, mock
py{26,27,py2}: typing==3.10.0.0
py{26,27,py2}: mock==3.0.5 # rq.filter: <4
py{26,27,py27}: typing==3.10.0.0
py{26,27,py27}: mock==3.0.5 # rq.filter: <4

# For pytest
py{26,27,34,py2}: pytest==4.6.11 # rq.filter: <5
py{35,36,37,38,39,py3}: pytest==5.2.4
py{26,27,34,py27}: pytest==4.6.11 # rq.filter: <5
py{35,36,37,38,39,py39}: pytest==5.2.4

# For code coverage
{[testenv:coverage_report]deps}
py{26,27,34,py2}: pytest-cov==2.8.1 # rq.filter: <2.9
py{35,36,37,38,39,py3}: pytest-cov==2.10.1
py{26,27,34,py27}: pytest-cov==2.8.1 # rq.filter: <2.9
py{35,36,37,38,39,py39}: pytest-cov==2.10.1

# For hypothesis. Note Python 3.4 isn't supported by hypothesis.
py{26,27,py2}: hypothesis==4.43.9 # rq.filter: <4.44
py{35,36,37,38,39,py3}: hypothesis==5.8.6
py{26,27,py27}: hypothesis==4.43.9 # rq.filter: <4.44
py{35,36,37,38,39,py39}: hypothesis==5.8.6

setenv =
{[default]setenv}
Expand Down Expand Up @@ -93,7 +93,8 @@ basepython = {[default]basepython}
skip_install = True

deps =
black==21.7b0
black==21.12b0
click==8.0.4

setenv =
BLACK_LINT_ARGS=--check
Expand Down Expand Up @@ -325,6 +326,12 @@ basepython = {[default]basepython}
deps =
Sphinx==4.1.2
sphinx-rtd-theme==0.5.2
sphinxcontrib-applehelp==1.0.4
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5

commands =
sphinx-build \
Expand Down Expand Up @@ -367,6 +374,7 @@ deps =
check-manifest==0.46
readme-renderer==29.0
twine==3.4.2
bleach==4.1.0

commands =
check-manifest
Expand Down
Loading