示例#1
0
async def check_proxy(proxy_url: str, timeout=None) -> tuple:
    results = []

    for checker in settings.PROXY_CHECKERS:
        result = await checker.check(proxy_url, timeout=timeout)
        if result[0] and settings.PROXY_CHECKING_CONDITION == 'or':
            return result

        results.append(result)

    additional_information = CheckerResult()

    if settings.PROXY_CHECKING_CONDITION == 'and':
        for result in results:
            if not result[0]:
                return False, additional_information

            additional_information.update_from_other(result[1])

        return True, additional_information

    return False, additional_information
示例#2
0
async def check_proxy(proxy_url: str, timeout=None) -> tuple:
    if not settings.PROXY_CHECKERS:
        raise Exception('add at least one checker')

    checkers = copy.copy(settings.PROXY_CHECKERS)
    random.shuffle(checkers)
    results = []

    for checker, _ in zip(checkers,
                          range(
                              settings.MINIMUM_NUMBER_OF_CHECKERS_PER_PROXY)):
        checker()
        result = await checker().check(proxy_url, timeout=timeout)
        if not result[0]:
            return False, None

        results.append(result)

    additional_information = CheckerResult()

    for result in results:
        additional_information.update_from_other(result[1])

    return True, additional_information