__init__.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014-2016 OpenMarket Ltd
  3. # Copyright 2018-9 New Vector Ltd
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """ This is a reference implementation of a Matrix homeserver.
  17. """
  18. import json
  19. import os
  20. import sys
  21. # Check that we're not running on an unsupported Python version.
  22. if sys.version_info < (3, 5):
  23. print("Synapse requires Python 3.5 or above.")
  24. sys.exit(1)
  25. # Twisted and canonicaljson will fail to import when this file is executed to
  26. # get the __version__ during a fresh install. That's OK and subsequent calls to
  27. # actually start Synapse will import these libraries fine.
  28. try:
  29. from twisted.internet import protocol
  30. from twisted.internet.protocol import Factory
  31. from twisted.names.dns import DNSDatagramProtocol
  32. protocol.Factory.noisy = False
  33. Factory.noisy = False
  34. DNSDatagramProtocol.noisy = False
  35. except ImportError:
  36. pass
  37. # Use the standard library json implementation instead of simplejson.
  38. try:
  39. from canonicaljson import set_json_library
  40. set_json_library(json)
  41. except ImportError:
  42. pass
  43. __version__ = "1.31.0"
  44. if bool(os.environ.get("SYNAPSE_TEST_PATCH_LOG_CONTEXTS", False)):
  45. # We import here so that we don't have to install a bunch of deps when
  46. # running the packaging tox test.
  47. from synapse.util.patch_inline_callbacks import do_patch
  48. do_patch()