Skip to content

Commit

Permalink
Merge branch 'master' into normalise_fix_536
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Dec 13, 2022
2 parents 69ee99a + 8080779 commit 8b6628a
Show file tree
Hide file tree
Showing 30 changed files with 119 additions and 55 deletions.
34 changes: 13 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
cache: 'pip'
cache-dependency-path: 'requirements/*.txt'
- name: Install dependencies
uses: py-actions/py-dependency-install@v3
uses: py-actions/py-dependency-install@v4
with:
path: requirements/lint.txt
- name: Install itself
Expand All @@ -48,7 +48,7 @@ jobs:
make lint
- name: Install spell checker
run: |
sudo apt install libenchant-dev
sudo apt install libenchant-2-dev
pip install -r requirements/doc-spelling.txt
- name: Run docs spelling
run: |
Expand All @@ -67,31 +67,23 @@ jobs:
name: Test
strategy:
matrix:
pyver: ['3.7', '3.8', '3.9', '3.10']
pyver: ['3.7', '3.8', '3.9', '3.10', '3.11']
no-extensions: ['', 'Y']
os: [ubuntu, macos, windows]
experimental: [false]
exclude:
- os: macos
no-extensions: 'Y'
- os: windows
no-extensions: 'Y'
include:
- pyver: pypy-3.8
- pyver: pypy-3.9
no-extensions: 'Y'
os: ubuntu
experimental: false
- os: ubuntu
pyver: "3.11.0-alpha - 3.11.0"
experimental: true
no-extensions: ''
- os: ubuntu
pyver: "3.11.0-alpha - 3.11.0"
experimental: true
- pyver: pypy-3.8
no-extensions: 'Y'
os: ubuntu
fail-fast: false
runs-on: ${{ matrix.os }}-latest
continue-on-error: ${{ matrix.experimental }}
timeout-minutes: 15
steps:
- name: Checkout
Expand All @@ -104,15 +96,15 @@ jobs:
cache-dependency-path: 'requirements/*.txt'
- name: Install cython
if: ${{ matrix.no-extensions == '' }}
uses: py-actions/py-dependency-install@v3
uses: py-actions/py-dependency-install@v4
with:
path: requirements/cython.txt
- name: Cythonize
if: ${{ matrix.no-extensions == '' }}
run: |
make cythonize
- name: Install dependencies
uses: py-actions/py-dependency-install@v3
uses: py-actions/py-dependency-install@v4
with:
path: requirements/ci.txt
env:
Expand All @@ -125,7 +117,7 @@ jobs:
python -m pytest tests -vv
python -m coverage xml
- name: Upload coverage
uses: codecov/codecov-action@v3.1.0
uses: codecov/codecov-action@v3.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand Down Expand Up @@ -164,7 +156,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
- name: Install cython
uses: py-actions/py-dependency-install@v3
uses: py-actions/py-dependency-install@v4
with:
path: requirements/cython.txt
- name: Cythonize
Expand Down Expand Up @@ -215,14 +207,14 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
- name: Install cython
uses: py-actions/py-dependency-install@v3
uses: py-actions/py-dependency-install@v4
with:
path: requirements/cython.txt
- name: Cythonize
run: |
make cythonize
- name: Build wheels
uses: pypa/cibuildwheel@2.6.1
uses: pypa/cibuildwheel@v2.11.3
env:
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
- uses: actions/upload-artifact@v3
Expand All @@ -247,7 +239,7 @@ jobs:
name: dist
path: dist
- name: Make Release
uses: aio-libs/create-release@v1.6.4
uses: aio-libs/create-release@v1.6.6
with:
changes_file: CHANGES.rst
name: yarl
Expand Down
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ repos:
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+
# Black misbehaved and broke when click 8.1.0 was released with an internal
# module removed. See https://github.com/psf/black/issues/2964
additional_dependencies: ['click<8.1.0']
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.0.1'
hooks:
Expand Down Expand Up @@ -57,5 +60,6 @@ repos:
rev: v1.0.1
hooks:
- id: rst-linter
exclude: ^CHANGES\.rst$
files: >-
^[^/]+[.]rst$
43 changes: 43 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,49 @@ Changelog

.. towncrier release notes start
1.8.2 (2022-12-03)
==================

This is the first release that started shipping wheels for Python 3.11.


1.8.1 (2022-08-01)
==================

Misc
----

- `#694 <https://github.com/aio-libs/yarl/issues/694>`_, `#699 <https://github.com/aio-libs/yarl/issues/699>`_, `#700 <https://github.com/aio-libs/yarl/issues/700>`_, `#701 <https://github.com/aio-libs/yarl/issues/701>`_, `#702 <https://github.com/aio-libs/yarl/issues/702>`_, `#703 <https://github.com/aio-libs/yarl/issues/703>`_, `#739 <https://github.com/aio-libs/yarl/issues/739>`_


1.8.0 (2022-08-01)
==================

Features
--------

- Added ``URL.raw_suffix``, ``URL.suffix``, ``URL.raw_suffixes``, ``URL.suffixes``, ``URL.with_suffix``. (`#613 <https://github.com/aio-libs/yarl/issues/613>`_)


Improved Documentation
----------------------

- Fixed broken internal references to :meth:`~URL.human_repr`. (`#665 <https://github.com/aio-libs/yarl/issues/665>`_)
- Fixed broken external references to :doc:`multidict:index` docs. (`#665 <https://github.com/aio-libs/yarl/issues/665>`_)


Deprecations and Removals
-------------------------

- Dropped Python 3.6 support. (`#672 <https://github.com/aio-libs/yarl/issues/672>`_)


Misc
----

- `#646 <https://github.com/aio-libs/yarl/issues/646>`_, `#699 <https://github.com/aio-libs/yarl/issues/699>`_, `#701 <https://github.com/aio-libs/yarl/issues/701>`_


1.7.2 (2021-11-01)
==================

Expand Down
1 change: 0 additions & 1 deletion CHANGES/613.feature.rst

This file was deleted.

1 change: 0 additions & 1 deletion CHANGES/646.misc

This file was deleted.

1 change: 0 additions & 1 deletion CHANGES/665.doc.1

This file was deleted.

1 change: 0 additions & 1 deletion CHANGES/665.doc.2

This file was deleted.

1 change: 0 additions & 1 deletion CHANGES/672.removal

This file was deleted.

1 change: 0 additions & 1 deletion CHANGES/694.misc.rst

This file was deleted.

1 change: 0 additions & 1 deletion CHANGES/699.misc.rst

This file was deleted.

1 change: 0 additions & 1 deletion CHANGES/700.misc.rst

This file was deleted.

2 changes: 0 additions & 2 deletions CHANGES/701.misc.rst

This file was deleted.

2 changes: 0 additions & 2 deletions CHANGES/702.misc.rst

This file was deleted.

1 change: 0 additions & 1 deletion CHANGES/703.misc.rst

This file was deleted.

1 change: 0 additions & 1 deletion CHANGES/739.misc.rst

This file was deleted.

1 change: 1 addition & 0 deletions CHANGES/792.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue with update_query() not getting rid of the query when argument is None.
1 change: 1 addition & 0 deletions CHANGES/793.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added some input restrictions on with_port() function to prevent invalid boolean inputs or out of valid port inputs; handled incorrect 0 port representation.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
yarl
====

The module provides handy URL class for URL parsing and changing.

.. image:: https://github.com/aio-libs/yarl/workflows/CI/badge.svg
:target: https://github.com/aio-libs/yarl/actions?query=workflow%3ACI
:align: right
Expand Down
2 changes: 1 addition & 1 deletion requirements/cython.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cython==0.29.30
cython==0.29.32
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-r ci.txt
towncrier==21.9.0
towncrier==22.8.0
2 changes: 1 addition & 1 deletion requirements/doc-spelling.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-r doc.txt
sphinxcontrib-spelling==7.5.0; platform_system!="Windows" # We only use it in Azure CI
sphinxcontrib-spelling==7.7.0; platform_system!="Windows" # We only use it in Azure CI
2 changes: 1 addition & 1 deletion requirements/doc.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sphinx==5.0.1
sphinx==5.3.0
4 changes: 2 additions & 2 deletions requirements/lint.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mypy==0.961; implementation_name=="cpython"
pre-commit==2.19.0
mypy==0.971; implementation_name=="cpython"
pre-commit==2.20.0
8 changes: 4 additions & 4 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-e .
idna==3.3
multidict==6.0.2
pytest==7.1.2
idna==3.4
multidict==6.0.3
pytest==7.2.0
pytest-cov>=2.3.1
typing_extensions==4.2.0
typing_extensions==4.4.0
2 changes: 1 addition & 1 deletion requirements/towncrier.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
towncrier==21.9.0
towncrier==22.8.0
16 changes: 14 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@ def read(name):
return f.read()


# $ echo ':something:`test <sdf>`' | sed 's/:\w\+:`\(\w\+\)\(\s\+\(.*\)\)\?`/``\1``/g'
# ``test``
def sanitize_rst_roles(rst_source_text: str) -> str:
"""Replace RST roles with inline highlighting."""
role_regex = r":\w+:`(?P<rendered_text>[^`]+)(\s+(.*))?`"
substitution_pattern = r"``(?P=rendered_text)``"
return re.sub(role_regex, substitution_pattern, rst_source_text)


args = dict(
name="yarl",
version=version,
description=("Yet another URL library"),
long_description="\n\n".join([read("README.rst"), read("CHANGES.rst")]),
long_description="\n\n".join(
[read("README.rst"), sanitize_rst_roles(read("CHANGES.rst"))]
),
long_description_content_type="text/x-rst",
classifiers=[
"License :: OSI Approved :: Apache Software License",
Expand All @@ -53,12 +64,13 @@ def read(name):
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Internet :: WWW/HTTP",
],
author="Andrew Svetlov",
author_email="andrew.svetlov@gmail.com",
url="https://github.com/aio-libs/yarl/",
license="Apache 2",
license="Apache-2.0",
packages=["yarl"],
install_requires=install_requires,
python_requires=">=3.7",
Expand Down
6 changes: 6 additions & 0 deletions tests/test_update_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def test_update_query_with_multiple_args():
url.update_query("a", "b")


def test_update_query_with_none_arg():
url = URL("http://example.com/?foo=bar&baz=foo")
expected_url = URL("http://example.com/")
assert url.update_query(None) == expected_url


def test_with_query_list_of_pairs():
url = URL("http://example.com")
assert str(url.with_query([("a", "1")])) == "http://example.com/?a=1"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_url_update_netloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ def test_with_port():
assert str(url.with_port(8888)) == "http://example.com:8888"


def test_with_port_with_no_port():
url = URL("http://example.com")
assert str(url.with_port(None)) == "http://example.com"


def test_with_port_ipv6():
url = URL("http://[::1]:8080/")
assert str(url.with_port(80)) == "http://[::1]:80/"
Expand All @@ -214,3 +219,10 @@ def test_with_port_for_relative_url():
def test_with_port_invalid_type():
with pytest.raises(TypeError):
URL("http://example.com").with_port("123")
with pytest.raises(TypeError):
URL("http://example.com").with_port(True)


def test_with_port_invalid_range():
with pytest.raises(ValueError):
URL("http://example.com").with_port(-1)
2 changes: 1 addition & 1 deletion yarl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ._url import URL, cache_clear, cache_configure, cache_info

__version__ = "1.7.2"
__version__ = "1.8.2"

__all__ = ("URL", "cache_clear", "cache_configure", "cache_info")
17 changes: 11 additions & 6 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ def _make_netloc(
ret = cls._encode_host(host)
else:
ret = host
if port:
if port is not None:
ret = ret + ":" + str(port)
if password is not None:
if not user:
Expand Down Expand Up @@ -873,8 +873,11 @@ def with_port(self, port):
"""
# N.B. doesn't cleanup query/fragment
if port is not None and not isinstance(port, int):
raise TypeError(f"port should be int or None, got {type(port)}")
if port is not None:
if isinstance(port, bool) or not isinstance(port, int):
raise TypeError(f"port should be int or None, got {type(port)}")
if port < 0 or port > 65535:
raise ValueError(f"port must be between 0 and 65535, got {port}")
if not self.is_absolute():
raise ValueError("port replacement is not allowed for relative URLs")
val = self._val
Expand Down Expand Up @@ -986,9 +989,11 @@ def with_query(self, *args, **kwargs):
def update_query(self, *args, **kwargs):
"""Return a new URL with query part updated."""
s = self._get_str_query(*args, **kwargs)
new_query = MultiDict(parse_qsl(s, keep_blank_values=True))
query = MultiDict(self.query)
query.update(new_query)
query = None
if s:
new_query = MultiDict(parse_qsl(s, keep_blank_values=True))
query = MultiDict(self.query)
query.update(new_query)

return URL(self._val._replace(query=self._get_str_query(query)), encoded=True)

Expand Down

0 comments on commit 8b6628a

Please sign in to comment.