# Path: pysecure/easy.py
# class EasySsh(object):
#     """This class allows a connection to be opened and closed at two separate 
#     points (as opposed to the callback methods, above).
#     """
# 
#     def __init__(self, user, host, auth_cb, allow_new=True, **session_args):
#         self.__user = user
#         self.__host = host
#         self.__auth_cb = auth_cb
#         self.__allow_new = allow_new
#         self.__session_args = session_args
#         
#         self.__log = logging.getLogger('EasySsh')
# 
#         self.__ssh_session = None
#         self.__ssh_opened = False
# 
#         self.__sftp_session = None
#         self.__sftp_opened = False
# 
#     def __del__(self):
#         if self.__ssh_opened is True:
#             self.close_ssh()
# 
#     def open_ssh(self):
#         self.__log.debug("Opening SSH.")
# 
#         if self.__ssh_opened is True:
#             raise Exception("Can not open SFTP session that is already open.")
# 
# # TODO: This might be required to only be run once, globally.
#         self.__system = SshSystem()
#         self.__system.open()
#         
#         self.__ssh_session = SshSession(user=self.__user, host=self.__host, 
#                                         **self.__session_args)
#         self.__ssh_session.open()
# 
#         self.__connect = SshConnect(self.__ssh_session)
#         self.__connect.open()
#         
#         self.__ssh_session.is_server_known(allow_new=self.__allow_new)
#         self.__auth_cb(self.__ssh_session)
# 
#         self.__ssh_opened = True
# 
#     def close_ssh(self):    
#         self.__log.debug("Closing SSH.")
# 
#         if self.__ssh_opened is False:
#             raise Exception("Can not close SSH session that is not currently "
#                             "opened.")
# 
#         if self.__sftp_opened is True:
#             self.close_sftp()
# 
#         self.__connect.close()
#         self.__ssh_session.close()
#         self.__system.close()
# 
#         self.__ssh_session = None
#         self.__ssh_opened = False
# 
#     def open_sftp(self):
#         self.__log.debug("Opening SFTP.")
# 
#         if self.__sftp_opened is True:
#             raise Exception("Can not open SFTP session that is already open.")
#         
#         self.__sftp_session = SftpSession(self.__ssh_session)
#         self.__sftp_session.open()
# 
#         self.__sftp_opened = True
#         
#     def close_sftp(self):
#         self.__log.debug("Closing SFTP.")
# 
#         if self.__sftp_opened is False:
#             raise Exception("Can not close SFTP session that is not currently "
#                             "opened.")
# 
#         self.__sftp_session.close()
# 
#         self.__sftp_session = None
#         self.__sftp_opened = False
# 
#     @property
#     def ssh(self):
#         if self.__ssh_opened is False:
#             raise Exception("Can not return an SSH session. A session is not "
#                             "open.")
#         
#         return self.__ssh_session
# 
#     @property
#     def sftp(self):
#         if self.__sftp_opened is False:
#             raise Exception("Can not return an SFTP session. A session is not "
#                             "open.")
#         
#         return self.__sftp_session
# 
# def get_key_auth_cb(key_filepath):
#     """This is just a convenience function for key-based login."""
# 
#     def auth_cb(ssh):
#         key = ssh_pki_import_privkey_file(key_filepath)
#         ssh.userauth_publickey(key)
# 
#     return auth_cb
# 
# Path: pysecure/test/test_config.py



import logging
import pysecure.log_config
from unittest import TestCase
from pysecure.easy import EasySsh, get_key_auth_cb
from pysecure.test.test_config import user, host, key_filepath





class SftpNoCbTest(TestCase):
    def __init__(self, *args, **kwargs):
        super(SftpNoCbTest, self).__init__(*args, **kwargs)

        self.__log = logging.getLogger('SftpNoCb')

    def setUp(self):

# Path: pysecure/easy.py
# class EasySsh(object):
#     """This class allows a connection to be opened and closed at two separate 
#     points (as opposed to the callback methods, above).
#     """
# 
#     def __init__(self, user, host, auth_cb, allow_new=True, **session_args):
#         self.__user = user
#         self.__host = host
#         self.__auth_cb = auth_cb
#         self.__allow_new = allow_new
#         self.__session_args = session_args
#         
#         self.__log = logging.getLogger('EasySsh')
# 
#         self.__ssh_session = None
#         self.__ssh_opened = False
# 
#         self.__sftp_session = None
#         self.__sftp_opened = False
# 
#     def __del__(self):
#         if self.__ssh_opened is True:
#             self.close_ssh()
# 
#     def open_ssh(self):
#         self.__log.debug("Opening SSH.")
# 
#         if self.__ssh_opened is True:
#             raise Exception("Can not open SFTP session that is already open.")
# 
# # TODO: This might be required to only be run once, globally.
#         self.__system = SshSystem()
#         self.__system.open()
#         
#         self.__ssh_session = SshSession(user=self.__user, host=self.__host, 
#                                         **self.__session_args)
#         self.__ssh_session.open()
# 
#         self.__connect = SshConnect(self.__ssh_session)
#         self.__connect.open()
#         
#         self.__ssh_session.is_server_known(allow_new=self.__allow_new)
#         self.__auth_cb(self.__ssh_session)
# 
#         self.__ssh_opened = True
# 
#     def close_ssh(self):    
#         self.__log.debug("Closing SSH.")
# 
#         if self.__ssh_opened is False:
#             raise Exception("Can not close SSH session that is not currently "
#                             "opened.")
# 
#         if self.__sftp_opened is True:
#             self.close_sftp()
# 
#         self.__connect.close()
#         self.__ssh_session.close()
#         self.__system.close()
# 
#         self.__ssh_session = None
#         self.__ssh_opened = False
# 
#     def open_sftp(self):
#         self.__log.debug("Opening SFTP.")
# 
#         if self.__sftp_opened is True:
#             raise Exception("Can not open SFTP session that is already open.")
#         
#         self.__sftp_session = SftpSession(self.__ssh_session)
#         self.__sftp_session.open()
# 
#         self.__sftp_opened = True
#         
#     def close_sftp(self):
#         self.__log.debug("Closing SFTP.")
# 
#         if self.__sftp_opened is False:
#             raise Exception("Can not close SFTP session that is not currently "
#                             "opened.")
# 
#         self.__sftp_session.close()
# 
#         self.__sftp_session = None
#         self.__sftp_opened = False
# 
#     @property
#     def ssh(self):
#         if self.__ssh_opened is False:
#             raise Exception("Can not return an SSH session. A session is not "
#                             "open.")
#         
#         return self.__ssh_session
# 
#     @property
#     def sftp(self):
#         if self.__sftp_opened is False:
#             raise Exception("Can not return an SFTP session. A session is not "
#                             "open.")
#         
#         return self.__sftp_session
# 
# def get_key_auth_cb(key_filepath):
#     """This is just a convenience function for key-based login."""
# 
#     def auth_cb(ssh):
#         key = ssh_pki_import_privkey_file(key_filepath)
#         ssh.userauth_publickey(key)
# 
#     return auth_cb
# 
# Path: pysecure/test/test_config.py



# Path: pysecure/test/sftp_no_cb.py
import logging
import pysecure.log_config
from unittest import TestCase
from pysecure.easy import EasySsh, get_key_auth_cb
from pysecure.test.test_config import user, host, key_filepath






class SftpNoCbTest(TestCase):
    def __init__(self, *args, **kwargs):
        super(SftpNoCbTest, self).__init__(*args, **kwargs)

        self.__log = logging.getLogger('SftpNoCb')

    def setUp(self):

        auth_cb = get_key_auth_cb(key_filepath)