# Path: smc/compat.py
# PY3 = sys.version_info > (3,)
# def min_smc_version(version):
# 
# Path: smc/base/util.py
# def save_to_file(filename, content):
#     """
#     Save content to file. Used by node initial contact but
#     can be used anywhere.
# 
#     :param str filename: name of file to save to
#     :param str content: content to save
#     :return: None
#     :raises IOError: permissions issue saving, invalid directory, etc
#     """
#     import os.path
#     path = os.path.abspath(filename)
#     with open(path, "w") as text_file:
#         text_file.write("{}".format(content))
# 
# Path: smc/api/exceptions.py
# class CertificateImportError(CertificateError):
#     """
#     Failure to import a certificate or private key
#     """
# 
# class CertificateExportError(CertificateError):
#     """
#     Failure to export a certificate
#     """


import re
from smc.compat import unicode
from smc.base.util import save_to_file
from smc.api.exceptions import CertificateImportError, CertificateExportError
        :raises IOError: file not found, permissions, etc.
        :return: None
        """
        multi_part = 'signed_certificate' if self.typeof == 'tls_server_credentials'\
            else 'certificate'
        self.make_request(
            CertificateImportError,
            method='create',
            resource='certificate_import',
            headers = {'content-type': 'multipart/form-data'}, 
            files={ 
                    multi_part: open(certificate, 'rb') if not \
                        pem_as_string(certificate) else certificate
                })
    
    def export_certificate(self, filename=None):
        """
        Export the certificate. Returned certificate will be in string
        format. If filename is provided, the certificate will also be saved
        to the file specified.
        
        :raises CertificateExportError: error exporting certificate
        :rtype: str or None
        """
        result = self.make_request(
            CertificateExportError,
            raw_result=True,
            resource='certificate_export')
            
        if filename is not None:

# Path: smc/compat.py
# PY3 = sys.version_info > (3,)
# def min_smc_version(version):
# 
# Path: smc/base/util.py
# def save_to_file(filename, content):
#     """
#     Save content to file. Used by node initial contact but
#     can be used anywhere.
# 
#     :param str filename: name of file to save to
#     :param str content: content to save
#     :return: None
#     :raises IOError: permissions issue saving, invalid directory, etc
#     """
#     import os.path
#     path = os.path.abspath(filename)
#     with open(path, "w") as text_file:
#         text_file.write("{}".format(content))
# 
# Path: smc/api/exceptions.py
# class CertificateImportError(CertificateError):
#     """
#     Failure to import a certificate or private key
#     """
# 
# class CertificateExportError(CertificateError):
#     """
#     Failure to export a certificate
#     """


# Path: smc/administration/certificates/tls_common.py
import re
from smc.compat import unicode
from smc.base.util import save_to_file
from smc.api.exceptions import CertificateImportError, CertificateExportError

        :raises IOError: file not found, permissions, etc.
        :return: None
        """
        multi_part = 'signed_certificate' if self.typeof == 'tls_server_credentials'\
            else 'certificate'
        self.make_request(
            CertificateImportError,
            method='create',
            resource='certificate_import',
            headers = {'content-type': 'multipart/form-data'}, 
            files={ 
                    multi_part: open(certificate, 'rb') if not \
                        pem_as_string(certificate) else certificate
                })
    
    def export_certificate(self, filename=None):
        """
        Export the certificate. Returned certificate will be in string
        format. If filename is provided, the certificate will also be saved
        to the file specified.
        
        :raises CertificateExportError: error exporting certificate
        :rtype: str or None
        """
        result = self.make_request(
            CertificateExportError,
            raw_result=True,
            resource='certificate_export')
            
        if filename is not None:

            save_to_file(filename, result.content)