def get_sp_metadata(self):
metadata = OneLogin_Saml2_Metadata.builder(<EOL>self.__sp, self.__security['<STR_LIT>'],<EOL>self.__security['<STR_LIT>'],<EOL>self.__security['<STR_LIT>'],<EOL>self.__security['<STR_LIT>'],<EOL>self.get_contacts(), self.get_organization()<EOL>)<EOL>add_encryption = self.__security['<STR_LIT>'] or self.__security['<STR_LIT>']<EOL>cert_new = self.get_sp_cert_new()<EOL>metadata = OneLogin_Saml2_Metadata.add_x509_key_descriptors(metadata, cert_new, add_encryption)<EOL>cert = self.get_sp_cert()<EOL>metadata = OneLogin_Saml2_Metadata.add_x509_key_descriptors(metadata, cert, add_encryption)<EOL>if '<STR_LIT>' in self.__security and self.__security['<STR_LIT>'] is not False:<EOL><INDENT>if self.__security['<STR_LIT>'] is True:<EOL><INDENT>if not cert:<EOL><INDENT>raise OneLogin_Saml2_Error(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_Error.PUBLIC_CERT_FILE_NOT_FOUND<EOL>)<EOL><DEDENT>cert_metadata = cert<EOL>key_metadata = self.get_sp_key()<EOL>if not key_metadata:<EOL><INDENT>raise OneLogin_Saml2_Error(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_Error.PRIVATE_KEY_FILE_NOT_FOUND<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if ('<STR_LIT>' not in self.__security['<STR_LIT>'] or<EOL>'<STR_LIT>' not in self.__security['<STR_LIT>']):<EOL><INDENT>raise OneLogin_Saml2_Error(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_Error.SETTINGS_INVALID_SYNTAX<EOL>)<EOL><DEDENT>key_file_name = self.__security['<STR_LIT>']['<STR_LIT>']<EOL>cert_file_name = self.__security['<STR_LIT>']['<STR_LIT>']<EOL>key_metadata_file = self.__paths['<STR_LIT>'] + key_file_name<EOL>cert_metadata_file = self.__paths['<STR_LIT>'] + cert_file_name<EOL>try:<EOL><INDENT>with open(key_metadata_file, '<STR_LIT:r>') as f_metadata_key:<EOL><INDENT>key_metadata = f_metadata_key.read()<EOL><DEDENT><DEDENT>except IOError:<EOL><INDENT>raise OneLogin_Saml2_Error(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_Error.PRIVATE_KEY_FILE_NOT_FOUND,<EOL>key_metadata_file<EOL>)<EOL><DEDENT>try:<EOL><INDENT>with open(cert_metadata_file, '<STR_LIT:r>') as f_metadata_cert:<EOL><INDENT>cert_metadata = f_metadata_cert.read()<EOL><DEDENT><DEDENT>except IOError:<EOL><INDENT>raise OneLogin_Saml2_Error(<EOL>'<STR_LIT>',<EOL>OneLogin_Saml2_Error.PUBLIC_CERT_FILE_NOT_FOUND,<EOL>cert_metadata_file<EOL>)<EOL><DEDENT><DEDENT>signature_algorithm = self.__security['<STR_LIT>']<EOL>digest_algorithm = self.__security['<STR_LIT>']<EOL>metadata = OneLogin_Saml2_Metadata.sign_metadata(metadata, key_metadata, cert_metadata, signature_algorithm, digest_algorithm)<EOL><DEDENT>return metadata<EOL>
Gets the SP metadata. The XML representation.

:returns: SP metadata (xml)
:rtype: string