How to use the aiodns.error.ARES_ENOTFOUND function in aiodns

To help you get started, we’ve selected a few aiodns 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 saghul / aiodns / tests.py View on Github external
def test_query_a_bad(self):
        f = self.resolver.query('hgf8g2od29hdohid.com', 'A')
        try:
            self.loop.run_until_complete(f)
        except aiodns.error.DNSError as e:
            self.assertEqual(e.args[0], aiodns.error.ARES_ENOTFOUND)
github Snawoot / postfix-mta-sts-resolver / postfix_mta_sts_resolver / resolver.py View on Github external
sts_txt_domain = '_mta-sts.' + domain

        # Try to fetch it
        try:
            txt_records = await asyncio.wait_for(
                self._resolver.query(sts_txt_domain, 'TXT'),
                timeout=self._timeout)
        except aiodns.error.DNSError as error:
            if error.args[0] == aiodns.error.ARES_ETIMEOUT:  # pragma: no cover pylint: disable=no-else-return,no-member
                # This branch is not covered because of aiodns bug:
                # https://github.com/saghul/aiodns/pull/64
                # It's hard to decide what to do in case of timeout
                # Probably it's better to threat this as fetch error
                # so caller probably shall report such cases.
                return STSFetchResult.FETCH_ERROR, None
            elif error.args[0] == aiodns.error.ARES_ENOTFOUND:  # pylint: disable=no-else-return,no-member
                return STSFetchResult.NONE, None
            elif error.args[0] == aiodns.error.ARES_ENODATA:  # pylint: disable=no-else-return,no-member
                return STSFetchResult.NONE, None
            else:  # pragma: no cover
                return STSFetchResult.NONE, None
        except asyncio.TimeoutError:
            return STSFetchResult.FETCH_ERROR, None

        # workaround for floating return type of pycares
        txt_records = filter_text(rec.text for rec in txt_records)

        # RFC 8461 strictly defines version string as first field
        txt_records = [txt for txt in txt_records
                       if txt.startswith('v=STSv1')]

        # Exactly one record should exist

aiodns

Simple DNS resolver for asyncio

MIT
Latest version published 1 month ago

Package Health Score

85 / 100
Full package analysis

Similar packages