code: def ip_addresses(
      *,
      v: Optional[Literal[4, 6]] = None,
      network: Optional[Union[str, IPv4Network, IPv6Network]] = None,
  ) -> SearchStrategy[Union[IPv4Address, IPv6Address]]:
      r"""Generate IP addresses - ``v=4`` for :class:`~python:ipaddress.IPv4Address`\ es,
      ``v=6`` for :class:`~python:ipaddress.IPv6Address`\ es, or leave unspecified
      to allow both versions.
  
      ``network`` may be an :class:`~python:ipaddress.IPv4Network` or
      :class:`~python:ipaddress.IPv6Network`, or a string representing a network such as
      ``"127.0.0.0/24"`` or ``"2001:db8::/32"``.  As well as generating addresses within
      a particular routable network, this can be used to generate addresses from a
      reserved range listed in the
      `IANA <https://www.iana.org/assignments/iana-ipv4-special-registry/>`__
      `registries <https://www.iana.org/assignments/iana-ipv6-special-registry/>`__.
  
      If you pass both ``v`` and ``network``, they must be for the same version.
      """
      if v is not None:
          check_type(int, v, "v")
          if v not in (4, 6):
              raise InvalidArgument(
                  f"{v=}, but only v=4 or v=6 are valid"
              )
      if network is None:
          # We use the reserved-address registries to boost the chance
          # of generating one of the various special types of address.
          four = binary(min_size=4, max_size=4).map(
              IPv4Address
          ) | sampled_from(SPECIAL_IPv4_RANGES).flatmap(
              lambda network: ip_addresses(network=network)
          )
          six = binary(min_size=16, max_size=16).map(
              IPv6Address
          ) | sampled_from(SPECIAL_IPv6_RANGES).flatmap(
              lambda network: ip_addresses(network=network)
          )
          if v == 4:
              return four
          if v == 6:
              return six
          return four | six
      if isinstance(network, str):
          network = ip_network(network)
      check_type((IPv4Network, IPv6Network), network, "network")
      assert isinstance(network, (IPv4Network, IPv6Network))  # for Mypy
      if v not in (None, network.version):
          raise InvalidArgument(f"{v=} is incompatible with {network=}")
      addr_type = IPv4Address if network.version == 4 else IPv6Address
      return integers(int(network[0]), int(network[-1])).map(addr_type)
  
file_path: catboost/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/ipaddress.py
imports: from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network, ip_network
  from typing import Literal, Optional, Union
  from hypothesis.errors import InvalidArgument
  from hypothesis.internal.validation import check_type
  from hypothesis.strategies._internal.core import binary, sampled_from
  from hypothesis.strategies._internal.numbers import integers
  from hypothesis.strategies._internal.strategies import SearchStrategy
  from hypothesis.strategies._internal.utils import defines_strategy
label_desc: Use image node_id 1 for calling a global function with example usage: ip_addresses() and returns: integers, unknown, four, six