def summarize_address_range(first, last):
if (not (isinstance(first, _BaseAddress) and<EOL>isinstance(last, _BaseAddress))):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if first.version != last.version:<EOL><INDENT>raise TypeError("<STR_LIT>" % (<EOL>first, last))<EOL><DEDENT>if first > last:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if first.version == <NUM_LIT:4>:<EOL><INDENT>ip = IPv4Network<EOL><DEDENT>elif first.version == <NUM_LIT:6>:<EOL><INDENT>ip = IPv6Network<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>ip_bits = first._max_prefixlen<EOL>first_int = first._ip<EOL>last_int = last._ip<EOL>while first_int <= last_int:<EOL><INDENT>nbits = min(_count_righthand_zero_bits(first_int, ip_bits),<EOL>_compat_bit_length(last_int - first_int + <NUM_LIT:1>) - <NUM_LIT:1>)<EOL>net = ip((first_int, ip_bits - nbits))<EOL>yield net<EOL>first_int += <NUM_LIT:1> << nbits<EOL>if first_int - <NUM_LIT:1> == ip._ALL_ONES:<EOL><INDENT>break<EOL><DEDENT><DEDENT>
Summarize a network range given the first and last IP addresses.

    Example:
        >>> list(summarize_address_range(IPv4Address('192.0.2.0'),
        ...                              IPv4Address('192.0.2.130')))
        ...                                #doctest: +NORMALIZE_WHITESPACE
        [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'),
         IPv4Network('192.0.2.130/32')]

    Args:
        first: the first IPv4Address or IPv6Address in the range.
        last: the last IPv4Address or IPv6Address in the range.

    Returns:
        An iterator of the summarized IPv(4|6) network objects.

    Raise:
        TypeError:
            If the first and last objects are not IP addresses.
            If the first and last objects are not the same version.
        ValueError:
            If the last object is not greater than the first.
            If the version of the first address is not 4 or 6.