def __init__(self, relay=None, port=25, helo=None, timeout=5, debug=False, starttls=False, nameservers=None, no_cache=False): self.port = port self.relay = relay if helo is None: self.helo = self.get_helo_name() else: self.helo = helo self.timeout = timeout self.starttls = starttls self.debug = debug self.no_cache = no_cache if nameservers: self.resolver = Resolver(configure=False) self.resolver.nameservers = [ n.strip() for n in nameservers.split(',') ] else: self.resolver = Resolver() if not self.no_cache: self.resolver.cache = Cache() # TODO: Add option to parser self.reorder_recipients = True
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
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()
from dns.resolver import Resolver, Cache from dns.asyncresolver import Resolver as AsyncResolver from dns.exception import DNSException except ImportError: raise ImportError( "the module psycopg._dns requires the package 'dnspython' installed" ) from . import pq from . import errors as e if TYPE_CHECKING: from dns.rdtypes.IN.SRV import SRV resolver = Resolver() resolver.cache = Cache() async_resolver = AsyncResolver() async_resolver.cache = Cache() async def resolve_hostaddr_async(params: Dict[str, Any]) -> Dict[str, Any]: """ Perform async DNS lookup of the hosts and return a new params dict. :param params: The input parameters, for instance as returned by `~psycopg.conninfo.conninfo_to_dict()`. If a ``host`` param is present but not ``hostname``, resolve the host addresses dynamically.