How to use the ural.patterns.PROTOCOL_RE function in ural

To help you get started, we’ve selected a few ural examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github medialab / ural / ural / utils.py View on Github external
def safe_urlsplit(url, scheme='http'):
    if isinstance(url, SplitResult):
        return url

    if not re.match(PROTOCOL_RE, url):
        url = scheme + '://' + url

    splitted = urlsplit(url)

    return splitted
github medialab / ural / ural / force_protocol.py View on Github external
Args:
        url (str): Target URL as a string.
        protocol (str): protocol wanted. Is 'http' by default.

    Returns:
        string: The protocol-equipped url.

    """
    protocol = protocol.rstrip(':/')

    if not PROTOCOL_RE.match(url):
        url = protocol + '://' + url
    elif url[:2] == '//':
        url = protocol + ':' + url
    else:
        url = re.sub(PROTOCOL_RE, protocol + '://', url)

    return url
github medialab / ural / ural / strip_protocol.py View on Github external
def strip_protocol(url):
    """
    Function removing the protocol from the given url.

    Args:
        url (str): Target URL as a string.

    Returns:
        string: The url without protocol.

    """
    return PROTOCOL_RE.sub("", url)