當前位置: 首頁>>代碼示例>>Python>>正文


Python dns.DNSResolver類代碼示例

本文整理匯總了Python中slimta.util.dns.DNSResolver的典型用法代碼示例。如果您正苦於以下問題:Python DNSResolver類的具體用法?Python DNSResolver怎麽用?Python DNSResolver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DNSResolver類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_result_cb_error

 def test_result_cb_error(self):
     result = AsyncResult()
     DNSResolver._result_cb(result, 13, pycares.errno.ARES_ENOTFOUND)
     with self.assertRaises(DNSError) as cm:
         result.get()
     self.assertEqual('Domain name not found [ARES_ENOTFOUND]',
                      str(cm.exception))
開發者ID:madhugb,項目名稱:python-slimta,代碼行數:7,代碼來源:test_slimta_util_dns.py

示例2: get

    def get(self, ip, timeout=None, strict=False):
        """Checks this DNSBL for the given IP address. This method does not
        check the answer, only that the response was not ``NXDOMAIN``.

        :param ip: The IP address string to check.
        :param timeout: A timeout in seconds before ``False`` is returned.
        :param strict: If ``True``, DNS exceptions that are not ``NXDOMAIN``
                       (including timeouts) will also  result in a ``True``
                       return value.
        :returns: ``True`` if the DNSBL had an entry for the given IP address,
                  ``False`` otherwise.

        """
        with gevent.Timeout(timeout, None):
            query = self._build_query(ip)
            try:
                DNSResolver.query(query, 'A').get()
            except DNSError as exc:
                if exc.errno == ARES_ENOTFOUND:
                    return False
                logging.log_exception(__name__, query=query)
                return not strict
            else:
                return True
        return strict
開發者ID:madhugb,項目名稱:python-slimta,代碼行數:25,代碼來源:dnsbl.py

示例3: test_query

 def test_query(self):
     channel = self.mox.CreateMock(pycares.Channel)
     self.mox.StubOutWithMock(pycares, 'Channel')
     self.mox.StubOutWithMock(gevent, 'spawn')
     pycares.Channel().AndReturn(channel)
     channel.query('example.com', 13, IgnoreArg())
     gevent.spawn(IgnoreArg())
     self.mox.ReplayAll()
     DNSResolver.query('example.com', 13)
開發者ID:madhugb,項目名稱:python-slimta,代碼行數:9,代碼來源:test_slimta_util_dns.py

示例4: test_dnsblocklistgroup_get_reasons

 def test_dnsblocklistgroup_get_reasons(self):
     group = DnsBlocklistGroup()
     group.add_dnsbl('test1.example.com')
     group.add_dnsbl('test2.example.com')
     group.add_dnsbl('test3.example.com')
     DNSResolver.query('4.3.2.1.test1.example.com', 'TXT').InAnyOrder().AndReturn(FakeAsyncResult(['reason one']))
     DNSResolver.query('4.3.2.1.test3.example.com', 'TXT').InAnyOrder().AndReturn(FakeAsyncResult())
     self.mox.ReplayAll()
     self.assertEqual({'test1.example.com': 'reason one', 'test3.example.com': None},
                      group.get_reasons(set(['test1.example.com', 'test3.example.com']), '1.2.3.4'))
開發者ID:thestick613,項目名稱:python-slimta,代碼行數:10,代碼來源:test_slimta_util_dnsbl.py

示例5: test_wait_channel_error

 def test_wait_channel_error(self):
     DNSResolver._channel = channel = self.mox.CreateMockAnything()
     self.mox.StubOutWithMock(select, 'select')
     channel.getsock().AndReturn(('read', 'write'))
     channel.timeout().AndReturn(1.0)
     select.select('read', 'write', [], 1.0).AndRaise(ValueError(13))
     channel.cancel()
     self.mox.ReplayAll()
     with self.assertRaises(ValueError):
         DNSResolver._wait_channel()
     self.assertIsNone(DNSResolver._channel)
開發者ID:madhugb,項目名稱:python-slimta,代碼行數:11,代碼來源:test_slimta_util_dns.py

示例6: test_wait_channel

 def test_wait_channel(self):
     DNSResolver._channel = channel = self.mox.CreateMockAnything()
     self.mox.StubOutWithMock(select, 'select')
     channel.getsock().AndReturn(('read', 'write'))
     channel.timeout().AndReturn(1.0)
     select.select('read', 'write', [], 1.0).AndReturn(
         ([1, 2, 3], [4, 5, 6], None))
     for fd in [1, 2, 3]:
         channel.process_fd(fd, pycares.ARES_SOCKET_BAD)
     for fd in [4, 5, 6]:
         channel.process_fd(pycares.ARES_SOCKET_BAD, fd)
     channel.getsock().AndReturn(('read', 'write'))
     channel.timeout().AndReturn(None)
     channel.process_fd(pycares.ARES_SOCKET_BAD, pycares.ARES_SOCKET_BAD)
     channel.getsock().AndReturn((None, None))
     self.mox.ReplayAll()
     DNSResolver._wait_channel()
開發者ID:madhugb,項目名稱:python-slimta,代碼行數:17,代碼來源:test_slimta_util_dns.py

示例7: _resolve_a

 def _resolve_a(self):
     answer = DNSResolver.query(self.domain, 'A').get()
     expiration = 0
     now = time.time()
     ret = []
     for rdata in answer:
         ret.append((0, str(rdata.host)))
         expiration = max(expiration, now + rdata.ttl)
     return ret, expiration
開發者ID:thestick613,項目名稱:python-slimta,代碼行數:9,代碼來源:mx.py

示例8: test_check_dnsrbl

    def test_check_dnsrbl(self):
        class TestSession(object):
            address = ('1.2.3.4', 56789)
        class TestValidators(object):
            def __init__(self):
                self.session = TestSession()
            @check_dnsbl('test.example.com')
            def validate_mail(self, reply, sender):
                assert False

        DNSResolver.query('4.3.2.1.test.example.com', 'A').AndRaise(DNSError(ARES_ENOTFOUND))
        DNSResolver.query('4.3.2.1.test.example.com', 'A').AndReturn(FakeAsyncResult())
        self.mox.ReplayAll()
        validators = TestValidators()
        reply = Reply('250', '2.0.0 Ok')
        self.assertRaises(AssertionError, validators.validate_mail, reply, 'asdf')
        self.assertEqual('250', reply.code)
        self.assertEqual('2.0.0 Ok', reply.message)
        validators.validate_mail(reply, 'asdf')
        self.assertEqual('550', reply.code)
        self.assertEqual('5.7.1 Access denied', reply.message)
開發者ID:thestick613,項目名稱:python-slimta,代碼行數:21,代碼來源:test_slimta_util_dnsbl.py

示例9: test_dnsblocklist_get_reason

 def test_dnsblocklist_get_reason(self):
     DNSResolver.query('4.3.2.1.test.example.com', 'TXT').AndReturn(FakeAsyncResult())
     DNSResolver.query('4.3.2.1.test.example.com', 'TXT').AndReturn(FakeAsyncResult(['good reason']))
     DNSResolver.query('8.7.6.5.test.example.com', 'TXT').AndRaise(DNSError(ARES_ENOTFOUND))
     self.mox.ReplayAll()
     self.assertEqual(None, self.dnsbl.get_reason('1.2.3.4'))
     self.assertEqual('good reason', self.dnsbl.get_reason('1.2.3.4'))
     self.assertEqual(None, self.dnsbl['5.6.7.8'])
開發者ID:thestick613,項目名稱:python-slimta,代碼行數:8,代碼來源:test_slimta_util_dnsbl.py

示例10: _resolve_mx

 def _resolve_mx(self):
     answer = DNSResolver.query(self.domain, 'MX').get()
     expiration = 0
     now = time.time()
     ret = []
     for rdata in answer:
         for i, rec in enumerate(ret):
             if rec[0] > rdata.priority:
                 ret.insert(i, (rdata.priority, str(rdata.host)))
                 break
         else:
             ret.append((rdata.priority, str(rdata.host)))
         expiration = max(expiration, now + rdata.ttl)
     return ret, expiration
開發者ID:thestick613,項目名稱:python-slimta,代碼行數:14,代碼來源:mx.py

示例11: get_reason

    def get_reason(self, ip, timeout=None):
        """Gets the TXT record for the IP address on this DNSBL. This is
        usually a reason for why the IP address matched. As such, this function
        should only be called after :meth:`.get()` returns ``True``.

        :param ip: The IP address to get a match reason for.
        :param timeout: A timeout in seconds before giving up.
        :returns: A string with the reason, or ``None``.

        """
        with gevent.Timeout(timeout, None):
            query = self._build_query(ip)
            try:
                answers = DNSResolver.query(query, 'TXT').get()
            except DNSError:
                pass
            else:
                if answers:
                    for rdata in answers:
                        return rdata.text
開發者ID:madhugb,項目名稱:python-slimta,代碼行數:20,代碼來源:dnsbl.py

示例12: test_get_query_type

 def test_get_query_type(self):
     self.assertEqual(pycares.QUERY_TYPE_MX,
                      DNSResolver._get_query_type('MX'))
     self.assertEqual(13, DNSResolver._get_query_type(13))
開發者ID:madhugb,項目名稱:python-slimta,代碼行數:4,代碼來源:test_slimta_util_dns.py

示例13: test_result_cb

 def test_result_cb(self):
     result = AsyncResult()
     DNSResolver._result_cb(result, 13, None)
     self.assertEqual(13, result.get())
開發者ID:madhugb,項目名稱:python-slimta,代碼行數:4,代碼來源:test_slimta_util_dns.py

示例14: test_dnsblocklist_get

 def test_dnsblocklist_get(self):
     DNSResolver.query('4.3.2.1.test.example.com', 'A').AndReturn(FakeAsyncResult())
     DNSResolver.query('8.7.6.5.test.example.com', 'A').AndRaise(DNSError(ARES_ENOTFOUND))
     self.mox.ReplayAll()
     self.assertTrue(self.dnsbl.get('1.2.3.4'))
     self.assertNotIn('5.6.7.8', self.dnsbl)
開發者ID:thestick613,項目名稱:python-slimta,代碼行數:6,代碼來源:test_slimta_util_dnsbl.py

示例15: test_dnsblocklistgroup_get

 def test_dnsblocklistgroup_get(self):
     group = DnsBlocklistGroup()
     group.add_dnsbl('test1.example.com')
     group.add_dnsbl('test2.example.com')
     group.add_dnsbl('test3.example.com')
     DNSResolver.query('4.3.2.1.test1.example.com', 'A').InAnyOrder('one').AndReturn(FakeAsyncResult())
     DNSResolver.query('4.3.2.1.test2.example.com', 'A').InAnyOrder('one').AndRaise(DNSError(ARES_ENOTFOUND))
     DNSResolver.query('4.3.2.1.test3.example.com', 'A').InAnyOrder('one').AndReturn(FakeAsyncResult())
     DNSResolver.query('8.7.6.5.test1.example.com', 'A').InAnyOrder('two').AndRaise(DNSError(ARES_ENOTFOUND))
     DNSResolver.query('8.7.6.5.test2.example.com', 'A').InAnyOrder('two').AndRaise(DNSError(ARES_ENOTFOUND))
     DNSResolver.query('8.7.6.5.test3.example.com', 'A').InAnyOrder('two').AndRaise(DNSError(ARES_ENOTFOUND))
     self.mox.ReplayAll()
     self.assertEqual(set(['test1.example.com', 'test3.example.com']), group.get('1.2.3.4'))
     self.assertNotIn('5.6.7.8', group)
開發者ID:thestick613,項目名稱:python-slimta,代碼行數:14,代碼來源:test_slimta_util_dnsbl.py


注:本文中的slimta.util.dns.DNSResolver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。