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.

utils.py 759B

1234567891011121314151617181920212223242526272829303132333435
  1. # -*- coding: utf-8 -*-
  2. """
  3. celery.security.utils
  4. ~~~~~~~~~~~~~~~~~~~~~
  5. Utilities used by the message signing serializer.
  6. """
  7. from __future__ import absolute_import
  8. import sys
  9. from contextlib import contextmanager
  10. from celery.exceptions import SecurityError
  11. from celery.five import reraise
  12. try:
  13. from OpenSSL import crypto
  14. except ImportError: # pragma: no cover
  15. crypto = None # noqa
  16. __all__ = ['reraise_errors']
  17. @contextmanager
  18. def reraise_errors(msg='{0!r}', errors=None):
  19. assert crypto is not None
  20. errors = (crypto.Error, ) if errors is None else errors
  21. try:
  22. yield
  23. except errors as exc:
  24. reraise(SecurityError,
  25. SecurityError(msg.format(exc)),
  26. sys.exc_info()[2])