code: def ip_address(value,
                 allow_empty = False,
                 **kwargs):
      
      if not value and not allow_empty:
          raise errors.EmptyValueError('value (%s) was empty' % value)
      elif not value:
          return None
  
      if is_py2 and value and isinstance(value, unicode):
          value = value.encode('utf-8')
  
      try:
          value = ipv6(value, force_run = True)                                   # pylint: disable=E1123
          ipv6_failed = False
      except ValueError:
          ipv6_failed = True
  
      if ipv6_failed:
          try:
              value = ipv4(value, force_run = True)                               # pylint: disable=E1123
          except ValueError:
              raise errors.InvalidIPAddressError('value (%s) is not a valid IPv6 or '
                                                 'IPv4 address' % value)
  
      return value
docs: Validate that ``value`` is a valid IP address.
  
      .. note::
  
        First, the validator will check if the address is a valid IPv6 address.
        If that doesn't work, the validator will check if the address is a valid
        IPv4 address.
  
        If neither works, the validator will raise an error (as always).
  
      :param value: The value to validate.
  
      :param allow_empty: If ``True``, returns :obj:`None <python:None>` if
        ``value`` is empty. If ``False``, raises a
        :class:`EmptyValueError <validator_collection.errors.EmptyValueError>`
        if ``value`` is empty. Defaults to ``False``.
      :type allow_empty: :class:`bool <python:bool>`
  
      :returns: ``value`` / :obj:`None <python:None>`
  
      :raises EmptyValueError: if ``value`` is empty and ``allow_empty`` is ``False``
      :raises InvalidIPAddressError: if ``value`` is not a valid IP address or empty with
        ``allow_empty`` set to ``True``