• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python dns.DNSResolver类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ptrlookup.PtrLookup类代码示例发布时间:2022-05-27
下一篇:
Python deque.BlockingDeque类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap