def is_valid(self, request_data, raise_exceptions=False):
self.__error = None<EOL>lowercase_urlencoding = False<EOL>try:<EOL><INDENT>dom = fromstring(self.__logout_request, forbid_dtd=True)<EOL>idp_data = self.__settings.get_idp_data()<EOL>idp_entity_id = idp_data['<STR_LIT>']<EOL>if '<STR_LIT>' in request_data.keys():<EOL><INDENT>get_data = request_data['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>get_data = {}<EOL><DEDENT>if '<STR_LIT>' in request_data.keys():<EOL><INDENT>lowercase_urlencoding = request_data['<STR_LIT>']<EOL><DEDENT>if self.__settings.is_strict():<EOL><INDENT>res = OneLogin_Saml2_Utils.validate_xml(dom, '<STR_LIT>', self.__settings.is_debug_active())<EOL>if not isinstance(res, Document):<EOL><INDENT>raise OneLogin_Saml2_ValidationError(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_ValidationError.INVALID_XML_FORMAT<EOL>)<EOL><DEDENT>security = self.__settings.get_security_data()<EOL>current_url = OneLogin_Saml2_Utils.get_self_url_no_query(request_data)<EOL>if dom.get('<STR_LIT>', None):<EOL><INDENT>na = OneLogin_Saml2_Utils.parse_SAML_to_time(dom.get('<STR_LIT>'))<EOL>if na <= OneLogin_Saml2_Utils.now():<EOL><INDENT>raise OneLogin_Saml2_ValidationError(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_ValidationError.RESPONSE_EXPIRED<EOL>)<EOL><DEDENT><DEDENT>if dom.get('<STR_LIT>', None):<EOL><INDENT>destination = dom.get('<STR_LIT>')<EOL>if destination != '<STR_LIT>':<EOL><INDENT>if current_url not in destination:<EOL><INDENT>raise Exception(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>{<EOL>'<STR_LIT>': current_url,<EOL>'<STR_LIT>': destination,<EOL>},<EOL>OneLogin_Saml2_ValidationError.WRONG_DESTINATION<EOL>)<EOL><DEDENT><DEDENT><DEDENT>issuer = OneLogin_Saml2_Logout_Request.get_issuer(dom)<EOL>if issuer is not None and issuer != idp_entity_id:<EOL><INDENT>raise OneLogin_Saml2_ValidationError(<EOL>'<STR_LIT>' %<EOL>{<EOL>'<STR_LIT>': idp_entity_id,<EOL>'<STR_LIT>': issuer<EOL>},<EOL>OneLogin_Saml2_ValidationError.WRONG_ISSUER<EOL>)<EOL><DEDENT>if security['<STR_LIT>']:<EOL><INDENT>if '<STR_LIT>' not in get_data:<EOL><INDENT>raise OneLogin_Saml2_ValidationError(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_ValidationError.NO_SIGNED_MESSAGE<EOL>)<EOL><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' in get_data:<EOL><INDENT>if '<STR_LIT>' not in get_data:<EOL><INDENT>sign_alg = OneLogin_Saml2_Constants.RSA_SHA1<EOL><DEDENT>else:<EOL><INDENT>sign_alg = get_data['<STR_LIT>']<EOL><DEDENT>signed_query = '<STR_LIT>' % OneLogin_Saml2_Utils.get_encoded_parameter(get_data, '<STR_LIT>', lowercase_urlencoding=lowercase_urlencoding)<EOL>if '<STR_LIT>' in get_data:<EOL><INDENT>signed_query = '<STR_LIT>' % (signed_query, OneLogin_Saml2_Utils.get_encoded_parameter(get_data, '<STR_LIT>', lowercase_urlencoding=lowercase_urlencoding))<EOL><DEDENT>signed_query = '<STR_LIT>' % (signed_query, OneLogin_Saml2_Utils.get_encoded_parameter(get_data, '<STR_LIT>', OneLogin_Saml2_Constants.RSA_SHA1, lowercase_urlencoding=lowercase_urlencoding))<EOL>exists_x509cert = '<STR_LIT>' in idp_data and idp_data['<STR_LIT>']<EOL>exists_multix509sign = '<STR_LIT>' in idp_data and'<STR_LIT>' in idp_data['<STR_LIT>'] andidp_data['<STR_LIT>']['<STR_LIT>']<EOL>if not (exists_x509cert or exists_multix509sign):<EOL><INDENT>raise OneLogin_Saml2_Error(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_Error.CERT_NOT_FOUND<EOL>)<EOL><DEDENT>if exists_multix509sign:<EOL><INDENT>for cert in idp_data['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>if OneLogin_Saml2_Utils.validate_binary_sign(signed_query, b64decode(get_data['<STR_LIT>']), cert, sign_alg):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>raise OneLogin_Saml2_ValidationError(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_ValidationError.INVALID_SIGNATURE<EOL>)<EOL><DEDENT>else:<EOL><INDENT>cert = idp_data['<STR_LIT>']<EOL>if not OneLogin_Saml2_Utils.validate_binary_sign(signed_query, b64decode(get_data['<STR_LIT>']), cert, sign_alg):<EOL><INDENT>raise OneLogin_Saml2_ValidationError(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_ValidationError.INVALID_SIGNATURE<EOL>)<EOL><DEDENT><DEDENT><DEDENT>return True<EOL><DEDENT>except Exception as err:<EOL><INDENT>self.__error = err.__str__()<EOL>debug = self.__settings.is_debug_active()<EOL>if debug:<EOL><INDENT>print(err.__str__())<EOL><DEDENT>if raise_exceptions:<EOL><INDENT>raise err<EOL><DEDENT>return False<EOL><DEDENT>
Checks if the Logout Request received is valid
:param request_data: Request Data
:type request_data: dict
:param raise_exceptions: Whether to return false on failure or raise an exception
:type raise_exceptions: Boolean
:return: If the Logout Request is or not valid
:rtype: boolean