import re
import six


def _is_valid_url(url):
    """Checks whether a URL is valid.

    :param url: a url string.
    :returns: True if the url is valid or None, False otherwise.
    """
    r = re.compile(
        r'^https?://'
        r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)*[A-Z]{2,6}\.?|'
        r'localhost|'
        r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
        r'(?::\d+)?'
        r'(?:/?|[/?]\S+)$', re.IGNORECASE)

    return bool(isinstance(url, six.string_types) and r.search(url))