Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(3)  |  Call(3)  |  Derive(0)  |  Import(0)

        def lookup_receiver_policy(host):
    '''Lookup the reciever policy for a host. Returns a ReceiverPolicy.'''
    dmarcHost = '_dmarc.{0}'.format(host)
    try:
        dnsAnswer = dns_query(dmarcHost, 'TXT')
    except (NXDOMAIN, NoAnswer):
        retval = ReceiverPolicy.none
    else:
        answer = str(dnsAnswer[0])
        tags = answer_to_dict(answer)
        policy = tags.get('p', 'none')
        retval = ReceiverPolicy[policy]

    assert isinstance(retval, ReceiverPolicy)
    return retval
        


src/g/s/gs.dmarc-1.0.0/gs/dmarc/tests/lookup.py   gs.dmarc(Download)
    def lookup_receiver_policy(self, policy):
        queryResp = self.create_response(policy)
        gs.dmarc.lookup.dns_query = MagicMock(return_value=queryResp)
        host = 'example.com'
        retval = gs.dmarc.lookup.lookup_receiver_policy(host)
    def test_lookup_nxdomain(self):
        gs.dmarc.lookup.dns_query = MagicMock(side_effect=dns.resolver.NXDOMAIN)
        host = 'example.com'
        r = gs.dmarc.lookup.lookup_receiver_policy(host)
        self.assertEqual(r, gs.dmarc.lookup.ReceiverPolicy.none)
 
    def test_lookup_noanswer(self):
        gs.dmarc.lookup.dns_query = MagicMock(side_effect=dns.resolver.NoAnswer)
        host = 'example.com'
        r = gs.dmarc.lookup.lookup_receiver_policy(host)