Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. """
  2. kombu.transport
  3. ===============
  4. Built-in transports.
  5. """
  6. from __future__ import absolute_import
  7. from kombu.five import string_t
  8. from kombu.syn import _detect_environment
  9. from kombu.utils import symbol_by_name
  10. def supports_librabbitmq():
  11. if _detect_environment() == 'default':
  12. try:
  13. import librabbitmq # noqa
  14. except ImportError: # pragma: no cover
  15. pass
  16. else: # pragma: no cover
  17. return True
  18. def _ghettoq(name, new, alias=None):
  19. xxx = new # stupid enclosing
  20. def __inner():
  21. import warnings
  22. _new = callable(xxx) and xxx() or xxx
  23. gtransport = 'ghettoq.taproot.{0}'.format(name)
  24. ktransport = 'kombu.transport.{0}.Transport'.format(_new)
  25. this = alias or name
  26. warnings.warn("""
  27. Ghettoq does not work with Kombu, but there is now a built-in version
  28. of the {0} transport.
  29. You should replace {1!r} with: {2!r}
  30. """.format(name, gtransport, this))
  31. return ktransport
  32. return __inner
  33. TRANSPORT_ALIASES = {
  34. 'amqp': 'kombu.transport.pyamqp:Transport',
  35. 'pyamqp': 'kombu.transport.pyamqp:Transport',
  36. 'librabbitmq': 'kombu.transport.librabbitmq:Transport',
  37. 'memory': 'kombu.transport.memory:Transport',
  38. 'redis': 'kombu.transport.redis:Transport',
  39. 'SQS': 'kombu.transport.SQS:Transport',
  40. 'sqs': 'kombu.transport.SQS:Transport',
  41. 'beanstalk': 'kombu.transport.beanstalk:Transport',
  42. 'mongodb': 'kombu.transport.mongodb:Transport',
  43. 'couchdb': 'kombu.transport.couchdb:Transport',
  44. 'zookeeper': 'kombu.transport.zookeeper:Transport',
  45. 'django': 'kombu.transport.django:Transport',
  46. 'sqlalchemy': 'kombu.transport.sqlalchemy:Transport',
  47. 'sqla': 'kombu.transport.sqlalchemy:Transport',
  48. 'SLMQ': 'kombu.transport.SLMQ.Transport',
  49. 'slmq': 'kombu.transport.SLMQ.Transport',
  50. 'ghettoq.taproot.Redis': _ghettoq('Redis', 'redis', 'redis'),
  51. 'ghettoq.taproot.Database': _ghettoq('Database', 'django', 'django'),
  52. 'ghettoq.taproot.MongoDB': _ghettoq('MongoDB', 'mongodb'),
  53. 'ghettoq.taproot.Beanstalk': _ghettoq('Beanstalk', 'beanstalk'),
  54. 'ghettoq.taproot.CouchDB': _ghettoq('CouchDB', 'couchdb'),
  55. 'filesystem': 'kombu.transport.filesystem:Transport',
  56. 'zeromq': 'kombu.transport.zmq:Transport',
  57. 'zmq': 'kombu.transport.zmq:Transport',
  58. 'amqplib': 'kombu.transport.amqplib:Transport',
  59. 'qpid': 'kombu.transport.qpid:Transport',
  60. }
  61. _transport_cache = {}
  62. def resolve_transport(transport=None):
  63. if isinstance(transport, string_t):
  64. try:
  65. transport = TRANSPORT_ALIASES[transport]
  66. except KeyError:
  67. if '.' not in transport and ':' not in transport:
  68. from kombu.utils.text import fmatch_best
  69. alt = fmatch_best(transport, TRANSPORT_ALIASES)
  70. if alt:
  71. raise KeyError(
  72. 'No such transport: {0}. Did you mean {1}?'.format(
  73. transport, alt))
  74. raise KeyError('No such transport: {0}'.format(transport))
  75. else:
  76. if callable(transport):
  77. transport = transport()
  78. return symbol_by_name(transport)
  79. return transport
  80. def get_transport_cls(transport=None):
  81. """Get transport class by name.
  82. The transport string is the full path to a transport class, e.g.::
  83. "kombu.transport.pyamqp:Transport"
  84. If the name does not include `"."` (is not fully qualified),
  85. the alias table will be consulted.
  86. """
  87. if transport not in _transport_cache:
  88. _transport_cache[transport] = resolve_transport(transport)
  89. return _transport_cache[transport]