Skip to content

Commit

Permalink
Allow customizing dns.resolver.Resolver class attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ecederstrand committed Oct 21, 2020
1 parent 17cc10e commit 62d1af4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@ Change Log

HEAD
----
- Allow overriding `dns.resolver.Resolver` class attributes via `Autodiscovery.DNS_RESOLVER_ATTRS`.


3.3.0
Expand Down
6 changes: 5 additions & 1 deletion exchangelib/autodiscover/discovery.py
Expand Up @@ -75,6 +75,9 @@ class Autodiscovery:
INITIAL_RETRY_POLICY = FailFast()
RETRY_WAIT = 10 # Seconds to wait before retry on connection errors
MAX_REDIRECTS = 10 # Maximum number of URL redirects before we give up
DNS_RESOLVER_ATTRS = {
'timeout': AutodiscoverProtocol.TIMEOUT,
}

def __init__(self, email, credentials=None, auth_type=None, retry_policy=None):
"""
Expand Down Expand Up @@ -149,7 +152,8 @@ def _cache_key(self):
@threaded_cached_property
def resolver(self):
resolver = dns.resolver.Resolver()
resolver.timeout = AutodiscoverProtocol.TIMEOUT
for k, v in self.DNS_RESOLVER_ATTRS.items():
setattr(resolver, k, v)
return resolver

def _build_response(self, ad_response):
Expand Down

0 comments on commit 62d1af4

Please sign in to comment.