Skip to content
Myr

Better comments

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

authored by Kamil Madac · committed by Kamil Madac · parent 0a4e65c · Browse files · 1 file+11 added−2 removed
This commit

State

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

Diff stats

1 file+11 added−2 removed

  • other:+11 added−2 removed

1 file+11 added−2 removed

modified:requests/utils.py+11 added-2 removed
405 unmodified lines
406 # or '%')407 return quote(unquote_unreserved(uri), safe="!#$%&'()*+,/:;=?@[]~")408409410def address_in_network(ip,net):411 '''This function allows you to check if on IP belogs to a Network'''410def address_in_network(ip, net):411 """412 This function allows you to check if on IP belongs to a Network subnet413 Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24414 returns False if ip = 192.168.1.1 and net = 192.168.100.0/24415 """416 ipaddr = struct.unpack('=L', socket.inet_aton(ip))[0]417 netaddr, bits = net.split('/')418 netmask = struct.unpack('=L', socket.inet_aton(dotted_netmask(int(bits))))[0]419 network = struct.unpack('=L', socket.inet_aton(netaddr))[0] & netmask420 return (ipaddr & netmask) == (network & netmask)421422423def dotted_netmask(mask):424 """425 Converts mask from /xx format to xxx.xxx.xxx.xxx426 Example: if mask is /24 function returns 255.255.255.0427 """428 bits = 0xffffffff ^ (1 << 32 - mask) - 1429 return socket.inet_ntoa(struct.pack('>I', bits))430431
5 unmodified lines
437 return True438439440def is_ipv4_network(string_network):441 """Very simple check of the network format in no_proxy variable"""442 if '/' in string_network:443 try:444 socket.inet_aton(string_network.split('/')[0])445 except OSError:
189 unmodified lines