# Path: src/ronkyuu/tools.py
# def normalizeURL(targetURL):
#     """Return the last URL (of any redirections) of a valid URL
#     """
#     result = None
#     ok, chain = getURLChain(targetURL)
#     if ok:
#         if len(chain) > 0:
#             result = chain[-1]
#         else:
#             result = targetURL
#     return result
# 
# def cleanURL(targetURL):
#     """Return from the given URL a "clean" URL that follows the RFC guidelines
#     """
#     scheme, netloc, path, query, fragment = urlsplit(targetURL)
#     if len(path) == 0:
#         path = '/'
#     return urlunsplit((scheme, netloc, path, query, fragment))


from urllib.parse import urlparse
from bs4 import BeautifulSoup
from .tools import normalizeURL, cleanURL
import requests
              'history': r.history,
              'content': r.text,
              'relme':   [],
              'url':     sourceURL
              }
    if r.status_code == requests.codes.ok:  # pylint: disable=no-member
        dom = BeautifulSoup(r.text, _html_parser)
        for link in dom.find_all('a', rel='me'):
            rel  = link.get('rel')
            href = link.get('href')
            if rel is not None and href is not None:
                url = urlparse(href)
                if url is not None and url.scheme in ('http', 'https'):
                    result['relme'].append(cleanURL(href))
    return result


def confirmRelMe(profileURL, resourceURL, profileRelMes=None, resourceRelMes=None):
    """Determine if a given :resourceURL: is authoritative for the :profileURL:

    TODO add https/http filtering for those who wish to limit/restrict urls to match fully
    TODO add code to ensure that each item in the redirect chain is authoritative

    :param profileURL: URL of the user
    :param resourceURL: URL of the resource to validate
    :param profileRelMes: optional list of rel="me" links within the profile URL
    :param resourceRelMes: optional list of rel="me" links found within resource URL
    :rtype: True if confirmed
    """
    result  = False

# Path: src/ronkyuu/tools.py
# def normalizeURL(targetURL):
#     """Return the last URL (of any redirections) of a valid URL
#     """
#     result = None
#     ok, chain = getURLChain(targetURL)
#     if ok:
#         if len(chain) > 0:
#             result = chain[-1]
#         else:
#             result = targetURL
#     return result
# 
# def cleanURL(targetURL):
#     """Return from the given URL a "clean" URL that follows the RFC guidelines
#     """
#     scheme, netloc, path, query, fragment = urlsplit(targetURL)
#     if len(path) == 0:
#         path = '/'
#     return urlunsplit((scheme, netloc, path, query, fragment))


# Path: src/ronkyuu/relme.py
from urllib.parse import urlparse
from bs4 import BeautifulSoup
from .tools import normalizeURL, cleanURL
import requests

              'history': r.history,
              'content': r.text,
              'relme':   [],
              'url':     sourceURL
              }
    if r.status_code == requests.codes.ok:  # pylint: disable=no-member
        dom = BeautifulSoup(r.text, _html_parser)
        for link in dom.find_all('a', rel='me'):
            rel  = link.get('rel')
            href = link.get('href')
            if rel is not None and href is not None:
                url = urlparse(href)
                if url is not None and url.scheme in ('http', 'https'):
                    result['relme'].append(cleanURL(href))
    return result


def confirmRelMe(profileURL, resourceURL, profileRelMes=None, resourceRelMes=None):
    """Determine if a given :resourceURL: is authoritative for the :profileURL:

    TODO add https/http filtering for those who wish to limit/restrict urls to match fully
    TODO add code to ensure that each item in the redirect chain is authoritative

    :param profileURL: URL of the user
    :param resourceURL: URL of the resource to validate
    :param profileRelMes: optional list of rel="me" links within the profile URL
    :param resourceRelMes: optional list of rel="me" links found within resource URL
    :rtype: True if confirmed
    """
    result  = False

    profile = normalizeURL(profileURL)