From: Kamil Madac Date: Wed, 4 Dec 2013 10:47:40 +0000 (+0100) Subject: Better comments X-Git-Tag: v2.1.0~1^2^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=947248129ba3b0917c86c013f24d7499c15cb8ae;p=services%2Fpython-requests.git Better comments --- diff --git a/requests/utils.py b/requests/utils.py index d785230..1bebbaa 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -407,8 +407,12 @@ def requote_uri(uri): return quote(unquote_unreserved(uri), safe="!#$%&'()*+,/:;=?@[]~") -def address_in_network(ip,net): - '''This function allows you to check if on IP belogs to a Network''' +def address_in_network(ip, net): + """ + This function allows you to check if on IP belongs to a Network subnet + Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24 + returns False if ip = 192.168.1.1 and net = 192.168.100.0/24 + """ ipaddr = struct.unpack('=L', socket.inet_aton(ip))[0] netaddr, bits = net.split('/') netmask = struct.unpack('=L', socket.inet_aton(dotted_netmask(int(bits))))[0] @@ -417,6 +421,10 @@ def address_in_network(ip,net): def dotted_netmask(mask): + """ + Converts mask from /xx format to xxx.xxx.xxx.xxx + Example: if mask is /24 function returns 255.255.255.0 + """ bits = 0xffffffff ^ (1 << 32 - mask) - 1 return socket.inet_ntoa(struct.pack('>I', bits)) @@ -430,6 +438,7 @@ def is_ipv4_address(string_ip): def is_ipv4_network(string_network): + """Very simple check of the network format in no_proxy variable""" if '/' in string_network: try: socket.inet_aton(string_network.split('/')[0])