# Path: capirca/lib/nacaddr.py
# def IP(ip, comment='', token='', strict=True):
# def _is_subnet_of(a, b):  # pylint: disable=invalid-name
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def AddComment(self, comment=''):
#   def supernet(self, prefixlen_diff=1):
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def supernet(self, prefixlen_diff=1):
#   def AddComment(self, comment=''):
# def _InNetList(adders, ip):
# def IsSuperNet(supernets, subnets):
# def CollapseAddrListPreserveTokens(addresses):
# def _SafeToMerge(address, merge_target, check_addresses):
# def _CollapseAddrListInternal(addresses, complements_by_network):
# def CollapseAddrList(addresses, complement_addresses=None):
# def SortAddrList(addresses):
# def RemoveAddressFromList(superset, exclude):
# def AddressListExclude(superset, excludes, collapse_addrs=True):
# class IPv4(ipaddress.IPv4Network):
# class IPv6(ipaddress.IPv6Network):
# class PrefixlenDiffInvalidError(ipaddress.NetmaskValueError):


import collections
from capirca.lib import nacaddr

  Useful for debugging.

  Args:
    num: number to be prettily formatted

  Returns:
    prettily formatted string
  """
  # like ipaddr make assumption that this is ipv4
  byte_strings = []
  while num > 0 or len(byte_strings) < 4:
    byte_strings.append('{0:08b}'.format(num & 0xff))
    num >>= 8
  return ' '.join(reversed(byte_strings))


def Summarize(nets):
  """Summarizes networks while allowing for discontinuous subnet mask.

  Args:
    nets: list of nacaddr.IPv4 or nacaddr.IPv6 objects.
        Address family can be mixed, however there is no support for rendering
        anything other than IPv4.

  Returns:
    sorted list of DSMIPNet objects.
  """

  result = []

# Path: capirca/lib/nacaddr.py
# def IP(ip, comment='', token='', strict=True):
# def _is_subnet_of(a, b):  # pylint: disable=invalid-name
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def AddComment(self, comment=''):
#   def supernet(self, prefixlen_diff=1):
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def supernet(self, prefixlen_diff=1):
#   def AddComment(self, comment=''):
# def _InNetList(adders, ip):
# def IsSuperNet(supernets, subnets):
# def CollapseAddrListPreserveTokens(addresses):
# def _SafeToMerge(address, merge_target, check_addresses):
# def _CollapseAddrListInternal(addresses, complements_by_network):
# def CollapseAddrList(addresses, complement_addresses=None):
# def SortAddrList(addresses):
# def RemoveAddressFromList(superset, exclude):
# def AddressListExclude(superset, excludes, collapse_addrs=True):
# class IPv4(ipaddress.IPv4Network):
# class IPv6(ipaddress.IPv6Network):
# class PrefixlenDiffInvalidError(ipaddress.NetmaskValueError):


# Path: capirca/lib/summarizer.py
import collections
from capirca.lib import nacaddr


  Useful for debugging.

  Args:
    num: number to be prettily formatted

  Returns:
    prettily formatted string
  """
  # like ipaddr make assumption that this is ipv4
  byte_strings = []
  while num > 0 or len(byte_strings) < 4:
    byte_strings.append('{0:08b}'.format(num & 0xff))
    num >>= 8
  return ' '.join(reversed(byte_strings))


def Summarize(nets):
  """Summarizes networks while allowing for discontinuous subnet mask.

  Args:
    nets: list of nacaddr.IPv4 or nacaddr.IPv6 objects.
        Address family can be mixed, however there is no support for rendering
        anything other than IPv4.

  Returns:
    sorted list of DSMIPNet objects.
  """

  result = []

  optimized_nets = nacaddr.CollapseAddrList(nets)