Skip to content

Commit

Permalink
Allow customizing dns.resolver.Resolver class attributes (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecederstrand authored Oct 21, 2020
1 parent 17cc10e commit d9b815f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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: 6 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,14 @@ account = Account(primary_smtp_address='[email protected]', credentials=credentia
# different 'access_type':
account = Account(primary_smtp_address='[email protected]', credentials=credentials,
autodiscover=True, access_type=IMPERSONATION)

# Autodiscover needs to make some DNS queries. We use the dnspython package for that. Here's
# an example of customizing the way the dns.resolver.Resolver object is created:
from exchangelib.autodiscover import Autodiscovery
Autodiscovery.DNS_RESOLVER_ATTRS['edns'] = False # Disable EDNS queries
```


### Optimizing connections
```python
from exchangelib import DELEGATE, Account, Configuration, Credentials, NTLM, Build, Version
Expand Down
6 changes: 5 additions & 1 deletion exchangelib/autodiscover/discovery.py
Original file line number Diff line number Diff line change
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 d9b815f

Please sign in to comment.