def validate(context, url, normalize_url_func=_normalize_url):
    url = normalize_url_func(url)
    res = urlparse(url)

    if not res.hostname:
        return False

    if not context.config.ALLOWED_SOURCES:
        return True

    for pattern in context.config.ALLOWED_SOURCES:
        if isinstance(pattern, re._pattern_type):
            match = url
        else:
            pattern = '^%s$' % pattern
            match = res.hostname

        if re.match(pattern, match):
            return True

    return False
dataset/ETHPy150Open thumbor/thumbor/thumbor/loaders/http_loader.py/validate/original