Skip to content
Myr

function is_ipv4_network renamed

Before adoption: this commit came in with the history the project adopted, so no landing records it.

more detailed check of cidr format

authored by Kamil Madac · committed by Kamil Madac · parent f3bc8b6 · Browse files · 2 files+16 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−8 removed

  • other:+16 added−8 removed

2 files+16 added−8 removed

modified:requests/utils.py+12 added-4 removed
435 unmodified lines
436 return False437 return True438439440def is_ipv4_network(string_network):441 """Very simple check of the network format in no_proxy variable"""442 if '/' in string_network:440def is_valid_cidr(string_network):441 """Very simple check of the cidr format in no_proxy variable"""442 if string_network.count('/') == 1:443 try:444 mask = int(string_network.split('/')[1])445 except ValueError:446 return False447448 if mask < 1 or mask > 32:449 return False450451 try:452 socket.inet_aton(string_network.split('/')[0])453 except socket.error:454 return False455 else:
18 unmodified lines
474475 ip = netloc.split(':')[0]476 if is_ipv4_address(ip):477 for proxy_ip in no_proxy:470 if is_ipv4_network(proxy_ip):478 if is_valid_cidr(proxy_ip):479 if address_in_network(ip, proxy_ip):480 return {}481 else:482 for host in no_proxy:
160 unmodified lines
modified:test_requests.py+4 added-4 removed
932 unmodified lines
933 assert is_ipv4_address('8.8.8.8')934 assert not is_ipv4_address('8.8.8.8.8')935 assert not is_ipv4_address('localhost.localdomain')936937 def test_is_ipv4_network(self):938 from requests.utils import is_ipv4_network939 assert not is_ipv4_network('8.8.8.8')940 assert is_ipv4_network('192.168.1.0/24')937 def test_is_valid_cidr(self):938 from requests.utils import is_valid_cidr939 assert not is_valid_cidr('8.8.8.8')940 assert is_valid_cidr('192.168.1.0/24')941942 def test_dotted_netmask(self):943 from requests.utils import dotted_netmask944 assert dotted_netmask(8) == '255.0.0.0'
11 unmodified lines