def __init__(self, *args, **kwargs):
version = kwargs.pop('version', None)
super(Protocol, self).__init__(*args, **kwargs)
scheme = 'https' if self.has_ssl else 'http'
self.wsdl_url = '%s://%s/EWS/Services.wsdl' % (scheme, self.server)
self.messages_url = '%s://%s/EWS/messages.xsd' % (scheme, self.server)
self.types_url = '%s://%s/EWS/types.xsd' % (scheme, self.server)
# Autodetect authentication type if necessary
if self.auth_type is None:
self.auth_type = get_service_authtype(service_endpoint=self.service_endpoint, versions=API_VERSIONS,
name=self.credentials.username)
# Default to the auth type used by the service. We only need this if 'version' is None
self.docs_auth_type = self.auth_type
# Try to behave nicely with the Exchange server. We want to keep the connection open between requests.
# We also want to re-use sessions, to avoid the NTLM auth handshake on every request.
self._session_pool = LifoQueue(maxsize=self.SESSION_POOLSIZE)
for _ in range(self.SESSION_POOLSIZE):
self._session_pool.put(self.create_session(), block=False)
if version:
isinstance(version, Version)
self.version = version
else:
# Version.guess() needs auth objects and a working session pool
try:
# Try to get the auth_type of 'types.xsd' so we can fetch it and look at the version contained there
self.docs_auth_type = get_docs_authtype(docs_url=self.types_url)
except TransportError:
pass
self.version = Version.guess(self)
# Used by services to process service requests that are able to run in parallel. Thread pool should be
# larger than the connection pool so we have time to process data without idling the connection.
# Create the pool as the last thing here, since we may fail in the version or auth type guessing, which would
# leave open threads around to be garbage collected.
thread_poolsize = 4 * self.SESSION_POOLSIZE
self.thread_pool = ThreadPool(processes=thread_poolsize)
评论列表
文章目录