# Path: src/pif/base.py
# class BasePublicIPChecker(object):
#     """Base public IP checker."""
# 
#     uid = None
#     verbose = False
# 
#     def __init__(self, verbose=False):
#         """Constructor.
# 
#         :param bool verbose:
#         """
#         assert self.uid
#         self.verbose = verbose
#         self.logger = logging.getLogger(__name__)
# 
#     def get_local_ip(self):
#         """Get local IP.
# 
#         :return str:
#         """
#         return socket.gethostbyname(socket.gethostname())
# 
#     def get_public_ip(self):
#         """Get public IP.
# 
#         :return str:
#         """
#         raise NotImplementedError(
#             "You should override ``get_ip`` method in your IP checker class."
#         )
# 
# @property
# def registry(self):
#     """Registry."""
#     return self._registry
# 
# Path: src/pif/utils.py
# def get_public_ip(preferred_checker=None, verbose=False):
#     """Get IP using one of the services.
# 
#     :param str preferred_checker: Checker UID. If given, the preferred
#         checker is used.
#     :param bool verbose: If set to True, debug info is printed.
#     :return str:
#     """
#     ensure_autodiscover()
# 
#     # If use preferred checker.
#     if preferred_checker:
#         ip_checker_cls = registry.get(preferred_checker)
# 
#         if not ip_checker_cls:
#             return False
# 
#         ip_checker = ip_checker_cls(verbose=verbose)
#         public_ip = ip_checker.get_public_ip()
# 
#         if verbose:
#             LOGGER.info('provider: %s', ip_checker_cls.__name__)
#         return public_ip
# 
#     # Using all checkers.
# 
#     for ip_checker_name, ip_checker_cls in registry.registry.items():
#         ip_checker = ip_checker_cls(verbose=verbose)
#         try:
#             public_ip = ip_checker.get_public_ip()
#             if public_ip:
#                 if verbose:
#                     LOGGER.info('provider: %s', ip_checker_cls.__name__)
#                 return public_ip
# 
#         except Exception as err:
#             if verbose:
#                 LOGGER.error(err)
# 
#     return False
# 
# def list_checkers():
#     """List available checkers.
# 
#     :return list:
#     """
#     ensure_autodiscover()
#     return registry.registry.keys()
# 
# def ensure_autodiscover():
#     """Ensure the IP checkers are auto-discovered."""
#     if not registry.registry:
#         autodiscover()
# 
# Path: src/pif/discover.py
# def autodiscover():
#     """Autodiscovers the pif IP checkers in checkers directory."""
#     ip_checkers_dir = get_setting('IP_CHECKERS_DIR')
#     ip_checker_module_name = get_setting('IP_CHECKER_MODULE_NAME')
#     debug = get_setting('DEBUG')
# 
#     for app_path in os.listdir(PROJECT_DIR(ip_checkers_dir)):
#         full_app_path = [ip_checkers_dir]
#         full_app_path.append(app_path)
#         if os.path.isdir(PROJECT_DIR(full_app_path)):
#             try:
#                 import_module(
#                     "pif.%s.%s.%s" % (ip_checkers_dir,
#                                       app_path,
#                                       ip_checker_module_name)
#                 )
#             except ImportError as err:
#                 if debug:
#                     LOGGER.debug(str(err))
#             except Exception as err:
#                 if debug:
#                     LOGGER.debug(str(err))
#         else:
#             pass


import logging
import unittest
from .base import BasePublicIPChecker, registry
from .utils import get_public_ip, list_checkers, ensure_autodiscover
from .discover import autodiscover
        if result is not None:
            LOGGER.info(result)

        return result
    return inner


class PifTest(unittest.TestCase):
    """Tests."""

    def setUp(self):
        """Set up."""
        pass

    @log_info
    def test_01_autodiscover(self):
        """Test ``autodiscover``."""
        autodiscover()
        self.assertTrue(len(registry.registry) > 0)

    @log_info
    def test_02_get_public_ip(self):
        """Test get IP."""
        res = get_public_ip(verbose=True)
        self.assertIsNotNone(res)
        return res

    @log_info
    def _test_get_public_ip_using_preferred_checker(self, checker):
        """Test get_public_ip using preferred checker."""

# Path: src/pif/base.py
# class BasePublicIPChecker(object):
#     """Base public IP checker."""
# 
#     uid = None
#     verbose = False
# 
#     def __init__(self, verbose=False):
#         """Constructor.
# 
#         :param bool verbose:
#         """
#         assert self.uid
#         self.verbose = verbose
#         self.logger = logging.getLogger(__name__)
# 
#     def get_local_ip(self):
#         """Get local IP.
# 
#         :return str:
#         """
#         return socket.gethostbyname(socket.gethostname())
# 
#     def get_public_ip(self):
#         """Get public IP.
# 
#         :return str:
#         """
#         raise NotImplementedError(
#             "You should override ``get_ip`` method in your IP checker class."
#         )
# 
# @property
# def registry(self):
#     """Registry."""
#     return self._registry
# 
# Path: src/pif/utils.py
# def get_public_ip(preferred_checker=None, verbose=False):
#     """Get IP using one of the services.
# 
#     :param str preferred_checker: Checker UID. If given, the preferred
#         checker is used.
#     :param bool verbose: If set to True, debug info is printed.
#     :return str:
#     """
#     ensure_autodiscover()
# 
#     # If use preferred checker.
#     if preferred_checker:
#         ip_checker_cls = registry.get(preferred_checker)
# 
#         if not ip_checker_cls:
#             return False
# 
#         ip_checker = ip_checker_cls(verbose=verbose)
#         public_ip = ip_checker.get_public_ip()
# 
#         if verbose:
#             LOGGER.info('provider: %s', ip_checker_cls.__name__)
#         return public_ip
# 
#     # Using all checkers.
# 
#     for ip_checker_name, ip_checker_cls in registry.registry.items():
#         ip_checker = ip_checker_cls(verbose=verbose)
#         try:
#             public_ip = ip_checker.get_public_ip()
#             if public_ip:
#                 if verbose:
#                     LOGGER.info('provider: %s', ip_checker_cls.__name__)
#                 return public_ip
# 
#         except Exception as err:
#             if verbose:
#                 LOGGER.error(err)
# 
#     return False
# 
# def list_checkers():
#     """List available checkers.
# 
#     :return list:
#     """
#     ensure_autodiscover()
#     return registry.registry.keys()
# 
# def ensure_autodiscover():
#     """Ensure the IP checkers are auto-discovered."""
#     if not registry.registry:
#         autodiscover()
# 
# Path: src/pif/discover.py
# def autodiscover():
#     """Autodiscovers the pif IP checkers in checkers directory."""
#     ip_checkers_dir = get_setting('IP_CHECKERS_DIR')
#     ip_checker_module_name = get_setting('IP_CHECKER_MODULE_NAME')
#     debug = get_setting('DEBUG')
# 
#     for app_path in os.listdir(PROJECT_DIR(ip_checkers_dir)):
#         full_app_path = [ip_checkers_dir]
#         full_app_path.append(app_path)
#         if os.path.isdir(PROJECT_DIR(full_app_path)):
#             try:
#                 import_module(
#                     "pif.%s.%s.%s" % (ip_checkers_dir,
#                                       app_path,
#                                       ip_checker_module_name)
#                 )
#             except ImportError as err:
#                 if debug:
#                     LOGGER.debug(str(err))
#             except Exception as err:
#                 if debug:
#                     LOGGER.debug(str(err))
#         else:
#             pass


# Path: src/pif/tests.py
import logging
import unittest
from .base import BasePublicIPChecker, registry
from .utils import get_public_ip, list_checkers, ensure_autodiscover
from .discover import autodiscover

        if result is not None:
            LOGGER.info(result)

        return result
    return inner


class PifTest(unittest.TestCase):
    """Tests."""

    def setUp(self):
        """Set up."""
        pass

    @log_info
    def test_01_autodiscover(self):
        """Test ``autodiscover``."""
        autodiscover()
        self.assertTrue(len(registry.registry) > 0)

    @log_info
    def test_02_get_public_ip(self):
        """Test get IP."""
        res = get_public_ip(verbose=True)
        self.assertIsNotNone(res)
        return res

    @log_info
    def _test_get_public_ip_using_preferred_checker(self, checker):
        """Test get_public_ip using preferred checker."""

        res = get_public_ip(checker, verbose=True)