| OLD | NEW |
| 1 # Copyright 2014 The LUCI Authors. All rights reserved. | 1 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Utilities for working with IPv4 and IPv6 addresses.""" | 5 """Utilities for working with IPv4 and IPv6 addresses.""" |
| 6 | 6 |
| 7 import collections | 7 import collections |
| 8 | 8 |
| 9 | 9 |
| 10 # Part of public API of 'auth' component, exposed by this module. | 10 # Part of public API of 'auth' component, exposed by this module. |
| 11 __all__ = [ | 11 __all__ = [ |
| 12 'IP', | 12 'IP', |
| 13 'ip_from_string', | 13 'ip_from_string', |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 It will also zero non significant bits of an IP address used as a subnet base. | 158 It will also zero non significant bits of an IP address used as a subnet base. |
| 159 | 159 |
| 160 Raises ValueError if subnet_str is not a valid subnet. | 160 Raises ValueError if subnet_str is not a valid subnet. |
| 161 """ | 161 """ |
| 162 return subnet_to_string(subnet_from_string(subnet_str)) | 162 return subnet_to_string(subnet_from_string(subnet_str)) |
| 163 | 163 |
| 164 | 164 |
| 165 def is_in_subnet(ip, subnet): | 165 def is_in_subnet(ip, subnet): |
| 166 """True if given IP instance belongs to Subnet.""" | 166 """True if given IP instance belongs to Subnet.""" |
| 167 return ip.bits == subnet.bits and (ip.value & subnet.mask) == subnet.base | 167 return ip.bits == subnet.bits and (ip.value & subnet.mask) == subnet.base |
| OLD | NEW |