本文整理汇总了Python中dns.resolver.Resolver.cache方法的典型用法代码示例。如果您正苦于以下问题:Python Resolver.cache方法的具体用法?Python Resolver.cache怎么用?Python Resolver.cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dns.resolver.Resolver
的用法示例。
在下文中一共展示了Resolver.cache方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dns_query_function
# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import cache [as 别名]
def dns_query_function(server=None):
'''
Return a dns query function using the given DNS server address, or
getaddrinfo if none is given.
'''
if server:
from dns.resolver import Resolver, Cache
resolver = Resolver(configure=False)
resolver.cache = Cache()
resolver.nameservers.append(server)
def dns_query(host):
for rr in resolver.query(host):
return rr.address
else:
import socket
def dns_query(host):
for family, socktype, proto, canonname, sockaddr in \
socket.getaddrinfo(host, 0):
return sockaddr[0]
return dns_query
示例2: open
# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import cache [as 别名]
first page gets the special key `subject`)
"""
r = {}
with open(fpath, 'rb') as f:
pages = list(split_and_escape(f.read().decode('utf8')))
for i, page in enumerate(pages, 1):
tmpl = '\n' * page.offset + page.content
content_type, renderer = parse_specline(page.header)
key = 'subject' if i == 1 else content_type
env = jinja_env_html if content_type == 'text/html' else jinja_env
r[key] = SimplateLoader(fpath, tmpl).load(env, fpath)
return r
DNS = Resolver()
DNS.cache = Cache()
def normalize_email_address(email):
"""Normalize an email address.
Returns:
str: the normalized email address
Raises:
BadEmailAddress: if the address appears to be invalid
BadEmailDomain: if the domain name is invalid
"""
# Remove any surrounding whitespace
email = email.strip()