# Path: dyndnsc/detector/base.py
# LOG = logging.getLogger(__name__)
# class IPDetector(Subject, DynamicCliMixin):
#     def __init__(self, *args, **kwargs):
#     def can_detect_offline(self):
#     def af(self):
#     def get_old_value(self):
#     def set_old_value(self, value):
#     def get_current_value(self, default=None):
#     def set_current_value(self, value):
#     def has_changed(self):
#     def configuration_key_prefix():
# 
# Path: dyndnsc/common/six.py
# def ipaddress(addr):
#     """Return an ipaddress.ip_address object from the given string IP."""
#     return _ipaddress.ip_address(addr)
# 
# Path: dyndnsc/common/constants.py
# REQUEST_HEADERS_DEFAULT = {
#     # dyndns2 standard requires that we set our own user agent:
#     "User-Agent": "python-dyndnsc/%s" % __version__,
# }


import logging
import re
import requests
    import json
from random import choice
from .base import IPDetector, AF_INET, AF_INET6, AF_UNSPEC
from ..common.six import ipaddress
from ..common import constants


def _get_ip_from_url(url, parser, timeout=10):
    LOG.debug("Querying IP address from '%s'", url)
    try:
        req = requests.get(url, headers=constants.REQUEST_HEADERS_DEFAULT, timeout=timeout)
    except requests.exceptions.RequestException as exc:
        LOG.debug("webcheck failed for url '%s'", url, exc_info=exc)
        return None
    else:
        if req.status_code == 200:
            return parser(req.text)
        else:
            LOG.debug("Wrong http status code for '%s': %i", url, req.status_code)
    return None


def _parser_plain(text):
    try:
        return str(ipaddress(text.strip()))
    except ValueError as exc:
        LOG.warning("Error parsing IP address '%s':", text, exc_info=exc)
        return None


def _parser_line_regex(text, pattern="Current IP Address: (.*?)(<.*){0,1}$"):
    regex = re.compile(pattern)
    for line in text.splitlines():
        match_obj = regex.search(line)
        if match_obj is not None:

# Path: dyndnsc/detector/base.py
# LOG = logging.getLogger(__name__)
# class IPDetector(Subject, DynamicCliMixin):
#     def __init__(self, *args, **kwargs):
#     def can_detect_offline(self):
#     def af(self):
#     def get_old_value(self):
#     def set_old_value(self, value):
#     def get_current_value(self, default=None):
#     def set_current_value(self, value):
#     def has_changed(self):
#     def configuration_key_prefix():
# 
# Path: dyndnsc/common/six.py
# def ipaddress(addr):
#     """Return an ipaddress.ip_address object from the given string IP."""
#     return _ipaddress.ip_address(addr)
# 
# Path: dyndnsc/common/constants.py
# REQUEST_HEADERS_DEFAULT = {
#     # dyndns2 standard requires that we set our own user agent:
#     "User-Agent": "python-dyndnsc/%s" % __version__,
# }


# Path: dyndnsc/detector/webcheck.py
import logging
import re
import requests
    import json
from random import choice
from .base import IPDetector, AF_INET, AF_INET6, AF_UNSPEC
from ..common.six import ipaddress
from ..common import constants



def _get_ip_from_url(url, parser, timeout=10):
    LOG.debug("Querying IP address from '%s'", url)
    try:
        req = requests.get(url, headers=constants.REQUEST_HEADERS_DEFAULT, timeout=timeout)
    except requests.exceptions.RequestException as exc:
        LOG.debug("webcheck failed for url '%s'", url, exc_info=exc)
        return None
    else:
        if req.status_code == 200:
            return parser(req.text)
        else:
            LOG.debug("Wrong http status code for '%s': %i", url, req.status_code)
    return None


def _parser_plain(text):
    try:
        return str(ipaddress(text.strip()))
    except ValueError as exc:
        LOG.warning("Error parsing IP address '%s':", text, exc_info=exc)
        return None


def _parser_line_regex(text, pattern="Current IP Address: (.*?)(<.*){0,1}$"):
    regex = re.compile(pattern)
    for line in text.splitlines():
        match_obj = regex.search(line)
        if match_obj is not None:

            return str(ipaddress(match_obj.group(1)))