# Path: via/exceptions.py
# class BadURL(RequestBasedException):
#     """An invalid URL was discovered."""
# 
#     def __init__(self, message, requests_err=None, url=None):
#         super().__init__(message, requests_err)
#         self.url = url
# 
#     status_int = 400


from urllib.parse import unquote, urlparse
from h_vialib import Configuration
from pyramid.httpexceptions import HTTPBadRequest
from via.exceptions import BadURL
    def url_from_query(self):
        """Get the 'url' parameter from the query.

        :return: The URL as a string
        :raise HTTPBadRequest: If the URL is missing or empty
        :raise BadURL: If the URL is malformed
        """
        try:
            url = self._request.params["url"].strip()
        except KeyError as err:
            raise HTTPBadRequest("Required parameter 'url' missing") from err

        if not url:
            raise HTTPBadRequest("Required parameter 'url' is blank")

        return self._normalise_url(url)


def get_original_url(context):
    """Get the original URL from a provided context object (if any)."""

    if isinstance(context, QueryURLResource):
        getter = context.url_from_query
    elif isinstance(context, PathURLResource):
        getter = context.url_from_path
    else:
        return None

    try:
        return getter()

# Path: via/exceptions.py
# class BadURL(RequestBasedException):
#     """An invalid URL was discovered."""
# 
#     def __init__(self, message, requests_err=None, url=None):
#         super().__init__(message, requests_err)
#         self.url = url
# 
#     status_int = 400


# Path: via/resources.py
from urllib.parse import unquote, urlparse
from h_vialib import Configuration
from pyramid.httpexceptions import HTTPBadRequest
from via.exceptions import BadURL

    def url_from_query(self):
        """Get the 'url' parameter from the query.

        :return: The URL as a string
        :raise HTTPBadRequest: If the URL is missing or empty
        :raise BadURL: If the URL is malformed
        """
        try:
            url = self._request.params["url"].strip()
        except KeyError as err:
            raise HTTPBadRequest("Required parameter 'url' missing") from err

        if not url:
            raise HTTPBadRequest("Required parameter 'url' is blank")

        return self._normalise_url(url)


def get_original_url(context):
    """Get the original URL from a provided context object (if any)."""

    if isinstance(context, QueryURLResource):
        getter = context.url_from_query
    elif isinstance(context, PathURLResource):
        getter = context.url_from_path
    else:
        return None

    try:
        return getter()

    except BadURL as err: