Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(20)

Delta Between Two Patch Sets: Lib/ipaddress.py

Issue 21487: Assorted ipaddress performance improvements
Left Patch Set: Created 5 years, 8 months ago
Right Patch Set: Created 5 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # Copyright 2007 Google Inc. 1 # Copyright 2007 Google Inc.
2 # Licensed to PSF under a Contributor Agreement. 2 # Licensed to PSF under a Contributor Agreement.
3 3
4 """A fast, lightweight IPv4/IPv6 manipulation library in Python. 4 """A fast, lightweight IPv4/IPv6 manipulation library in Python.
5 5
6 This library is used to create/poke/manipulate IPv4 and IPv6 addresses 6 This library is used to create/poke/manipulate IPv4 and IPv6 addresses
7 and networks. 7 and networks.
8 8
9 """ 9 """
10 10
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 Args: 188 Args:
189 number: an integer. 189 number: an integer.
190 bits: maximum number of bits to count. 190 bits: maximum number of bits to count.
191 191
192 Returns: 192 Returns:
193 The number of zero bits on the right hand side of the number. 193 The number of zero bits on the right hand side of the number.
194 194
195 """ 195 """
196 if number == 0: 196 if number == 0:
197 return bits 197 return bits
198 for i in range(0, bits, 8): 198 return min(bits, (~number & (number-1)).bit_length())
199 if number & 0xff:
200 while True:
201 if number & 1:
202 return min(bits, i)
203 number = number >> 1
204 i = i + 1
205 number = number >> 8
206 # All bits of interest were zero, even if there are more in the number
207 return bits
208 199
209 200
210 def summarize_address_range(first, last): 201 def summarize_address_range(first, last):
211 """Summarize a network range given the first and last IP addresses. 202 """Summarize a network range given the first and last IP addresses.
212 203
213 Example: 204 Example:
214 >>> list(summarize_address_range(IPv4Address('192.0.2.0'), 205 >>> list(summarize_address_range(IPv4Address('192.0.2.0'),
215 ... IPv4Address('192.0.2.130'))) 206 ... IPv4Address('192.0.2.130')))
216 ... #doctest: +NORMALIZE_WHITESPACE 207 ... #doctest: +NORMALIZE_WHITESPACE
217 [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'), 208 [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'),
(...skipping 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after
2251 Note that the site-local address space has been deprecated by RFC 3879. 2242 Note that the site-local address space has been deprecated by RFC 3879.
2252 Use is_private to test if this address is in the space of unique local 2243 Use is_private to test if this address is in the space of unique local
2253 addresses as defined by RFC 4193. 2244 addresses as defined by RFC 4193.
2254 2245
2255 Returns: 2246 Returns:
2256 A boolean, True if the address is reserved per RFC 3513 2.5.6. 2247 A boolean, True if the address is reserved per RFC 3513 2.5.6.
2257 2248
2258 """ 2249 """
2259 return (self.network_address.is_site_local and 2250 return (self.network_address.is_site_local and
2260 self.broadcast_address.is_site_local) 2251 self.broadcast_address.is_site_local)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+