Skip to content

Commit

Permalink
Merge pull request #91 from nylas/revert-bb5bc9e
Browse files Browse the repository at this point in the history
revert bb5bc9e
  • Loading branch information
pengfeiye authored Apr 17, 2023
2 parents 9bf610f + 2001577 commit 0a6d82b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions exchangelib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def set_xml_value(elem, value, version):
from .ewsdatetime import EWSDateTime, EWSDate
from .fields import FieldPath, FieldOrder
from .folders import EWSElement
from .version import Version
if isinstance(value, string_types + (bool, bytes, int, Decimal, datetime.time, EWSDate, EWSDateTime)):
elem.text = value_to_xml_text(value)
elif isinstance(value, RestrictedElement):
Expand All @@ -195,6 +196,8 @@ def set_xml_value(elem, value, version):
if isinstance(v, (FieldPath, FieldOrder)):
elem.append(v.to_xml())
elif isinstance(v, EWSElement):
if not isinstance(version, Version):
raise ValueError("'version' %r must be a Version instance" % version)
elem.append(v.to_xml(version=version))
elif isinstance(v, RestrictedElement):
elem.append(v)
Expand All @@ -205,6 +208,8 @@ def set_xml_value(elem, value, version):
elif isinstance(value, (FieldPath, FieldOrder)):
elem.append(value.to_xml())
elif isinstance(value, EWSElement):
if not isinstance(version, Version):
raise ValueError("'version' %s must be a Version instance" % version)
elem.append(value.to_xml(version=version))
else:
raise ValueError('Unsupported type %s for value %s on elem %s' % (type(value), value, elem))
Expand Down
9 changes: 4 additions & 5 deletions exchangelib/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,12 @@ def guess(cls, protocol):
@classmethod
def _guess_version_from_service(cls, protocol, hint=None):
# The protocol doesn't have a version yet, so add one with our hint, or default to latest supported version.
# Use ConvertId as a minimal request to the server to test if the version is correct. If not, ConvertId will
# try to guess the version automatically. Make sure the call to ConvertId does not require a version build.
from .properties import ENTRY_ID, EWS_ID, AlternateId
from .services import ConvertId
# Use ResolveNames as a minimal request to the server to test if the version is correct. If not, ResolveNames
# will try to guess the version automatically.
from .services import ResolveNames
protocol.version = Version(build=None, api_version=hint or API_VERSIONS[-1])
try:
list(ConvertId(protocol=protocol).call([AlternateId(id="DUMMY", format=EWS_ID, mailbox="DUMMY")], ENTRY_ID))
list(ResolveNames(protocol=protocol).call(unresolved_entries=[protocol.credentials.username]))
except (ErrorInvalidSchemaVersionForMailboxVersion, ErrorInvalidServerVersion):
raise TransportError('Unable to guess version')
except ResponseMessageError:
Expand Down

0 comments on commit 0a6d82b

Please sign in to comment.