def security_context(conf, debug=None):
    """ Creates a security context based on the configuration

    :param conf: The configuration
    :return: A SecurityContext instance
    """
    if not conf:
        return None

    if debug is None:
        try:
            debug = conf.debug
        except AttributeError:
            pass

    try:
        metadata = conf.metadata
    except __HOLE__:
        metadata = None

    _only_md = conf.only_use_keys_in_metadata
    if _only_md is None:
        _only_md = False

    if conf.crypto_backend == 'xmlsec1':
        xmlsec_binary = conf.xmlsec_binary
        if not xmlsec_binary:
            try:
                _path = conf.xmlsec_path
            except AttributeError:
                _path = []
            xmlsec_binary = get_xmlsec_binary(_path)
            # verify that xmlsec is where it's supposed to be
        if not os.path.exists(xmlsec_binary):
            #if not os.access(, os.F_OK):
            raise SigverError(
                "xmlsec binary not in '%s' !" % xmlsec_binary)
        crypto = _get_xmlsec_cryptobackend(xmlsec_binary, debug=debug)
    elif conf.crypto_backend == 'XMLSecurity':
        # new and somewhat untested pyXMLSecurity crypto backend.
        crypto = CryptoBackendXMLSecurity(debug=debug)
    else:
        raise SigverError('Unknown crypto_backend %s' % (
            repr(conf.crypto_backend)))

    return SecurityContext(
        crypto, conf.key_file, cert_file=conf.cert_file, metadata=metadata,
        debug=debug, only_use_keys_in_metadata=_only_md,
        cert_handler_extra_class=conf.cert_handler_extra_class,
        generate_cert_info=conf.generate_cert_info,
        tmp_cert_file=conf.tmp_cert_file,
        tmp_key_file=conf.tmp_key_file,
        validate_certificate=conf.validate_certificate,
        key_file_passphrase=conf.key_file_passphrase)
dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/pysaml2-2.4.0/src/saml2/sigver.py/security_context