def _wrap_encryption_errors():
    """Context manager to wrap encryption related errors."""
    try:
        yield
    except BSONError:
        # BSON encoding/decoding errors are unrelated to encryption so
        # we should propagate them unchanged.
        raise
    except Exception as exc:
        raise EncryptionError(exc)
Context manager to wrap encryption related errors.
stackoverflow/venv/lib/python3.6/site-packages/pymongo/encryption.py