__init__.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright 2014 OpenMarket Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. def threePidAssocFromDict(d):
  15. """
  16. Instantiates a ThreepidAssociation from the given dict.
  17. :param d: The dict to use when instantiating the ThreepidAssociation.
  18. :type d: dict[str, any]
  19. :return: The instantiated ThreepidAssociation.
  20. :rtype: ThreepidAssociation
  21. """
  22. assoc = ThreepidAssociation(
  23. d["medium"],
  24. d["address"],
  25. None, # empty lookup_hash digest by default
  26. d["mxid"],
  27. d["ts"],
  28. d["not_before"],
  29. d["not_after"],
  30. )
  31. return assoc
  32. class ThreepidAssociation:
  33. def __init__(self, medium, address, lookup_hash, mxid, ts, not_before, not_after):
  34. """
  35. :param medium: The medium of the 3pid (eg. email)
  36. :param address: The identifier (eg. email address)
  37. :param lookup_hash: A hash digest of the 3pid. Can be a str or None
  38. :param mxid: The matrix ID the 3pid is associated with
  39. :param ts: The creation timestamp of this association, ms
  40. :param not_before: The timestamp, in ms, at which this association becomes valid
  41. :param not_after: The timestamp, in ms, at which this association ceases to be valid
  42. """
  43. self.medium = medium
  44. self.address = address
  45. self.lookup_hash = lookup_hash
  46. self.mxid = mxid
  47. self.ts = ts
  48. self.not_before = not_before
  49. self.not_after = not_after
  50. self.extra_fields = {}