Skip to content

Commit

Permalink
Update python-furl to version 2.1.3 / rev 10 via SR 1096865
Browse files Browse the repository at this point in the history
https://build.opensuse.org/request/show/1096865
by user mcepl + favogt_factory
FOR STAGING:A

- Add 165-use-ipaddress-library.patch to use standard ipaddress
  library to parse IP addresses (gh#gruns/furl#164).
  • Loading branch information
mcepl authored and bmwiedemann committed Jul 6, 2023
1 parent c438432 commit 7c6cd81
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 5 deletions.
Binary file modified packages/p/python-furl/.files
Binary file not shown.
12 changes: 12 additions & 0 deletions packages/p/python-furl/.rev
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,16 @@
<comment>- add sle15_python_module_pythons (jsc#PED-68)</comment>
<requestid>1083113</requestid>
</revision>
<revision rev="10" vrev="3">
<srcmd5>2628f67574423cdc71f5ba4e575a5cc3</srcmd5>
<version>2.1.3</version>
<time>1688660868</time>
<user>favogt_factory</user>
<comment>FOR STAGING:A

- Add 165-use-ipaddress-library.patch to use standard ipaddress
library to parse IP addresses (gh#gruns/furl#164).
</comment>
<requestid>1096865</requestid>
</revision>
</revisionlist>
145 changes: 145 additions & 0 deletions packages/p/python-furl/165-use-ipaddress-library.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
From 38587f3dca7e2f75b04cb0d80e4fc30ea6e139dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89loi=20Rivard?= <[email protected]>
Date: Sat, 24 Sep 2022 15:40:59 +0200
Subject: [PATCH] Use ipaddress to detect valid and invalid IPs

---
furl/furl.py | 47 +++++++++++++++++++++++++++++++++++++---------
setup.py | 1 +
tests/test_furl.py | 21 +++++++++++----------
3 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/furl/furl.py b/furl/furl.py
index cd6d710..451767f 100644
--- a/furl/furl.py
+++ b/furl/furl.py
@@ -12,6 +12,7 @@

import re
import abc
+import ipaddress
import warnings
from copy import deepcopy
from posixpath import normpath
@@ -241,6 +242,37 @@ def is_valid_host(hostname):
return '' not in toks # Adjacent periods aren't allowed.


+def is_valid_ipv4(ip):
+ if isinstance(ip, six.binary_type):
+ ip = ip.decode()
+
+ try:
+ ipaddress.IPv4Address(ip)
+ return True
+ except ValueError:
+ return False
+
+
+def is_valid_ipv6(ip):
+ if isinstance(ip, six.binary_type):
+ ip = ip.decode()
+
+ # ipaddress handle IPs without brackets
+ if (
+ callable_attr(ip, 'startswith')
+ and callable_attr(ip, 'endswith')
+ and ip.startswith("[")
+ and ip.endswith("]")
+ ):
+ ip = ip[1:-1]
+
+ try:
+ ipaddress.IPv6Address(ip)
+ return True
+ except ValueError:
+ return False
+
+
def get_scheme(url):
if url.startswith(':'):
return ''
@@ -1434,15 +1466,12 @@ def host(self, host):
"""
Raises: ValueError on invalid host or malformed IPv6 address.
"""
- # Invalid IPv6 literal.
- urllib.parse.urlsplit('http://%s/' % host) # Raises ValueError.
-
- # Invalid host string.
- resembles_ipv6_literal = (
- host is not None and lget(host, 0) == '[' and ':' in host and
- lget(host, -1) == ']')
- if (host is not None and not resembles_ipv6_literal and
- not is_valid_host(host)):
+ if (
+ host
+ and not is_valid_host(host)
+ and not is_valid_ipv4(host)
+ and not is_valid_ipv6(host)
+ ):
errmsg = (
"Invalid host '%s'. Host strings must have at least one "
"non-period character, can't contain any of '%s', and can't "
diff --git a/setup.py b/setup.py
index 8322619..887ca2e 100644
--- a/setup.py
+++ b/setup.py
@@ -114,6 +114,7 @@ def run_tests(self):
install_requires=[
'six>=1.8.0',
'orderedmultidict>=1.0.1',
+ 'ipaddress>=1.0.23; python_version < "3.3"',
],
cmdclass={
'test': RunTests,
diff --git a/tests/test_furl.py b/tests/test_furl.py
index bc268c8..5666be7 100644
--- a/tests/test_furl.py
+++ b/tests/test_furl.py
@@ -1655,10 +1655,10 @@ def test_hosts(self):
# addresses.
f = furl.furl('http://1.2.3.4.5.6/')

- # Invalid, but well-formed, IPv6 addresses shouldn't raise an
- # exception because urlparse.urlsplit() doesn't raise an
- # exception on invalid IPv6 addresses.
- furl.furl('http://[0:0:0:0:0:0:0:1:1:1:1:1:1:1:1:9999999999999]/')
+ # Invalid, but well-formed, IPv6 addresses should raise an
+ # exception.
+ with self.assertRaises(ValueError):
+ furl.furl('http://[0:0:0:0:0:0:0:1:1:1:1:1:1:1:1:9999999999999]/')

# Malformed IPv6 should raise an exception because urlparse.urlsplit()
# raises an exception on malformed IPv6 addresses.
@@ -1684,12 +1684,17 @@ def test_netloc(self):
assert f.host == '1.2.3.4.5.6'
assert f.port == 999

- netloc = '[0:0:0:0:0:0:0:1:1:1:1:1:1:1:1:9999999999999]:888'
+ netloc = '[1:2:3:4:5:6:7:8]:888'
f.netloc = netloc
assert f.netloc == netloc
- assert f.host == '[0:0:0:0:0:0:0:1:1:1:1:1:1:1:1:9999999999999]'
+ assert f.host == '[1:2:3:4:5:6:7:8]'
assert f.port == 888

+ # Well-formed but invalid IPv6 should raise an exception
+ netloc = '[0:0:0:0:0:0:0:1:1:1:1:1:1:1:1:9999999999999]:888'
+ with self.assertRaises(ValueError):
+ f.netloc = netloc
+
# Malformed IPv6 should raise an exception because
# urlparse.urlsplit() raises an exception
with self.assertRaises(ValueError):
@@ -1703,10 +1708,6 @@ def test_netloc(self):
with self.assertRaises(ValueError):
f.netloc = 'pump2pump.org:777777777777'

- # No side effects.
- assert f.host == '[0:0:0:0:0:0:0:1:1:1:1:1:1:1:1:9999999999999]'
- assert f.port == 888
-
# Empty netloc.
f = furl.furl('//')
assert f.scheme is None and f.netloc == '' and f.url == '//'
6 changes: 6 additions & 0 deletions packages/p/python-furl/python-furl.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Jul 4 22:28:07 UTC 2023 - Matej Cepl <[email protected]>

- Add 165-use-ipaddress-library.patch to use standard ipaddress
library to parse IP addresses (gh#gruns/furl#164).

-------------------------------------------------------------------
Fri Apr 21 12:24:55 UTC 2023 - Dirk Müller <[email protected]>

Expand Down
13 changes: 8 additions & 5 deletions packages/p/python-furl/python-furl.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
#


%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define skip_python2 1
%{?sle15_python_module_pythons}
%define skip_python2 1
Name: python-furl
Version: 2.1.3
Release: 0
Expand All @@ -27,7 +26,11 @@ License: Unlicense
Group: Development/Languages/Python
URL: https://github.com/gruns/furl
Source: https://files.pythonhosted.org/packages/source/f/furl/furl-%{version}.tar.gz
BuildRequires: %{python_module setuptools}
# PATCH-FIX-UPSTREAM 165-use-ipaddress-library.patch gh#gruns/furl#164 [email protected]
# use ipaddress to parse IP addresses
Patch0: 165-use-ipaddress-library.patch
BuildRequires: %{python_module pip}
BuildRequires: %{python_module wheel}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
Requires: python-orderedmultidict >= 1.0.1
Expand All @@ -48,10 +51,10 @@ furl is a Python library for parsing and manipulating URLs.
chmod -x *.md furl.egg-info/*

%build
%python_build
%pyproject_wheel

%install
%python_install
%pyproject_install
%python_expand %fdupes %{buildroot}%{$python_sitelib}

%check
Expand Down

0 comments on commit 7c6cd81

Please sign in to comment.