# Path: src/ronkyuu/validators.py
# class URLValidator(RegexValidator):  # pylint: disable=R0903
#     """URL Validation using a regular expression
#     """
#     regex = re.compile(
#         r'^(?:[a-z0-9\.\-]*)://'  # scheme is validated separately
#         r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'  # domain...
#         r'localhost|'  # localhost...
#         r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|'  # ...or ipv4
#         r'\[?[A-F0-9]*:[A-F0-9:]+\]?)'  # ...or ipv6
#         r'(?::\d+)?'  # optional port
#         r'(?:/?|[/?]\S+)$', re.IGNORECASE)
#     message = 'Enter a valid URL.'
#     # check only http and https
#     schemes = ['http', 'https']
# 
#     def __init__(self, schemes=None, **kwargs):
#         super(URLValidator, self).__init__(**kwargs)
#         if schemes is not None:
#             self.schemes = schemes
# 
#     def __call__(self, value):
#         e = ValueError(self.message)
#         # Check for None, and empty string
#         if value in (None, ''):
#             raise e
#         value = str(value)
#         # Check first if the scheme is valid
#         scheme = value.split('://')[0].lower()
#         if scheme not in self.schemes:
#             raise e
# 
#         # Then check full URL
#         try:
#             super(URLValidator, self).__call__(value)
#         except ValueError:
#             # Trivial case failed. Try for possible IDN domain
#             if value:
#                 scheme, netloc, path, query, fragment = urlsplit(value)
#                 try:
#                     netloc = netloc.encode('idna').decode('ascii')  # IDN -> ACE
#                 except UnicodeError:  # invalid domain part
#                     raise e
#                 url = urlunsplit((scheme, netloc, path, query, fragment))
#                 super(URLValidator, self).__call__(url)
#             else:
#                 raise e
#         else:
#             url = value
# 
# Path: src/ronkyuu/tools.py
# def parse_link_header(link):
#     """takes the link header as a string and returns a dictionary with rel values as keys and urls as values
#     :param link: link header as a string
#     :rtype: dictionary {rel_name: rel_value}
#     """
#     rel_dict = {}
#     for rels in link.split(','):
#         rel_break = quoted_split(rels, ';')
#         try:
#             rel_url = re.search('<(.+?)>', rel_break[0]).group(1)
#             rel_names = quoted_split(rel_break[1], '=')[-1]
#             if rel_names.startswith('"') and rel_names.endswith('"'):
#                 rel_names = rel_names[1:-1]
#             for name in rel_names.split():
#                 rel_dict[name] = rel_url
#         except (AttributeError, IndexError):
#             pass
# 
#     return rel_dict


from urllib.parse import urlparse, urljoin
from bs4 import BeautifulSoup
from .validators import URLValidator
from .tools import parse_link_header
import requests
            requests.exceptions.TooManyRedirects, requests.exceptions.Timeout) as error:
        debugOutput.append('exception during GET request: {} {}'.format(error.__class__.__name__, error))
        returnCode = 500
    debugOutput.append('returnCode: %s - endpointURL: %s' % (returnCode, endpointURL))
    if debug:
        return (returnCode, endpointURL, debugOutput)
    return (returnCode, endpointURL)


def sendWebmention(sourceURL, targetURL, webmention=None, test_urls=True, vouchDomain=None,
                   headers=None, timeout=None, debug=False):
    """Send to the :targetURL: a WebMention for the :sourceURL:

    The WebMention will be discovered if not given in the :webmention:
    parameter.

    :param sourceURL: URL that is referencing :targetURL:
    :param targetURL: URL of mentioned post
    :param webmention: optional WebMention endpoint
    :param test_urls: optional flag to test URLs for validation
    :param headers: optional headers to send with any web requests
    :type headers dict
    :param timeout: optional timeout for web requests
    :type timeout float

    :rtype: HTTPrequest object if WebMention endpoint was valid
    """
    if headers is None:
        headers = {}
    if test_urls:

# Path: src/ronkyuu/validators.py
# class URLValidator(RegexValidator):  # pylint: disable=R0903
#     """URL Validation using a regular expression
#     """
#     regex = re.compile(
#         r'^(?:[a-z0-9\.\-]*)://'  # scheme is validated separately
#         r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'  # domain...
#         r'localhost|'  # localhost...
#         r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|'  # ...or ipv4
#         r'\[?[A-F0-9]*:[A-F0-9:]+\]?)'  # ...or ipv6
#         r'(?::\d+)?'  # optional port
#         r'(?:/?|[/?]\S+)$', re.IGNORECASE)
#     message = 'Enter a valid URL.'
#     # check only http and https
#     schemes = ['http', 'https']
# 
#     def __init__(self, schemes=None, **kwargs):
#         super(URLValidator, self).__init__(**kwargs)
#         if schemes is not None:
#             self.schemes = schemes
# 
#     def __call__(self, value):
#         e = ValueError(self.message)
#         # Check for None, and empty string
#         if value in (None, ''):
#             raise e
#         value = str(value)
#         # Check first if the scheme is valid
#         scheme = value.split('://')[0].lower()
#         if scheme not in self.schemes:
#             raise e
# 
#         # Then check full URL
#         try:
#             super(URLValidator, self).__call__(value)
#         except ValueError:
#             # Trivial case failed. Try for possible IDN domain
#             if value:
#                 scheme, netloc, path, query, fragment = urlsplit(value)
#                 try:
#                     netloc = netloc.encode('idna').decode('ascii')  # IDN -> ACE
#                 except UnicodeError:  # invalid domain part
#                     raise e
#                 url = urlunsplit((scheme, netloc, path, query, fragment))
#                 super(URLValidator, self).__call__(url)
#             else:
#                 raise e
#         else:
#             url = value
# 
# Path: src/ronkyuu/tools.py
# def parse_link_header(link):
#     """takes the link header as a string and returns a dictionary with rel values as keys and urls as values
#     :param link: link header as a string
#     :rtype: dictionary {rel_name: rel_value}
#     """
#     rel_dict = {}
#     for rels in link.split(','):
#         rel_break = quoted_split(rels, ';')
#         try:
#             rel_url = re.search('<(.+?)>', rel_break[0]).group(1)
#             rel_names = quoted_split(rel_break[1], '=')[-1]
#             if rel_names.startswith('"') and rel_names.endswith('"'):
#                 rel_names = rel_names[1:-1]
#             for name in rel_names.split():
#                 rel_dict[name] = rel_url
#         except (AttributeError, IndexError):
#             pass
# 
#     return rel_dict


# Path: src/ronkyuu/webmention.py
from urllib.parse import urlparse, urljoin
from bs4 import BeautifulSoup
from .validators import URLValidator
from .tools import parse_link_header
import requests

            requests.exceptions.TooManyRedirects, requests.exceptions.Timeout) as error:
        debugOutput.append('exception during GET request: {} {}'.format(error.__class__.__name__, error))
        returnCode = 500
    debugOutput.append('returnCode: %s - endpointURL: %s' % (returnCode, endpointURL))
    if debug:
        return (returnCode, endpointURL, debugOutput)
    return (returnCode, endpointURL)


def sendWebmention(sourceURL, targetURL, webmention=None, test_urls=True, vouchDomain=None,
                   headers=None, timeout=None, debug=False):
    """Send to the :targetURL: a WebMention for the :sourceURL:

    The WebMention will be discovered if not given in the :webmention:
    parameter.

    :param sourceURL: URL that is referencing :targetURL:
    :param targetURL: URL of mentioned post
    :param webmention: optional WebMention endpoint
    :param test_urls: optional flag to test URLs for validation
    :param headers: optional headers to send with any web requests
    :type headers dict
    :param timeout: optional timeout for web requests
    :type timeout float

    :rtype: HTTPrequest object if WebMention endpoint was valid
    """
    if headers is None:
        headers = {}
    if test_urls:

        v = URLValidator()