# Path: ifcb/data/transfer/smb_utils.py
# def smb_connect(remote_server, username, password, netbios_name=None, timeout=DEFAULT_TIMEOUT):
# 
#     if netbios_name is None:
#         logging.debug('Querying NetBIOS for name of {}'.format(remote_server))
#         netbios_name = get_netbios_name(remote_server, timeout=timeout)
#         logging.debug('Name is {}'.format(netbios_name))
# 
#     logging.debug('Connecting to {}'.format(remote_server))
# 
#     c = SMBConnection(username, password, 'ignore', netbios_name)
#     c.connect(remote_server, timeout=timeout)
# 
#     return c
# 
# def get_netbios_name(remote_addr, timeout=DEFAULT_TIMEOUT):
#     nb = NetBIOS()
#     names = nb.queryIPForName(remote_addr, timeout=timeout)
#     nb.close()
#     if names is None or len(names) == 0:
#         raise NameError('No NetBIOS name found for {}'.format(remote_addr))
#     elif len(names) > 1:
#         logging.warn('More than one NetBIOS name for {}'.format(remote_addr))
#     return names[0]
# 
# class NameError(Exception):
#     pass


import os
from collections import defaultdict
from .smb_utils import smb_connect, get_netbios_name, NameError
from smb.base import SharedDevice
        self.directory = directory
        self._c = None
    def open(self):
        if self._c is not None:
            return
        try:
            self._c = smb_connect(self.addr, self.username, self.password, self.netbios_name, self.timeout)
        except:
            raise IfcbConnectionError('unable to connect to IFCB')
    def close(self):
        if self._c is not None:
            self._c.close()
            self._c = None
    def __enter__(self):
        if self.connect:
            self.open()
        return self
    def __exit__(self, type, value, traceback):
        self.close()
    def ensure_connected(self):
        if self._c is None:
            raise IfcbConnectionError('IFCB is not connected')
    def is_responding(self):
        # tries to get NetBIOS name to see if IFCB is responding
        if self.netbios_name is not None:
            return True # FIXME determine connection state
        if self._c is not None:
            return True
        else:
            try:

# Path: ifcb/data/transfer/smb_utils.py
# def smb_connect(remote_server, username, password, netbios_name=None, timeout=DEFAULT_TIMEOUT):
# 
#     if netbios_name is None:
#         logging.debug('Querying NetBIOS for name of {}'.format(remote_server))
#         netbios_name = get_netbios_name(remote_server, timeout=timeout)
#         logging.debug('Name is {}'.format(netbios_name))
# 
#     logging.debug('Connecting to {}'.format(remote_server))
# 
#     c = SMBConnection(username, password, 'ignore', netbios_name)
#     c.connect(remote_server, timeout=timeout)
# 
#     return c
# 
# def get_netbios_name(remote_addr, timeout=DEFAULT_TIMEOUT):
#     nb = NetBIOS()
#     names = nb.queryIPForName(remote_addr, timeout=timeout)
#     nb.close()
#     if names is None or len(names) == 0:
#         raise NameError('No NetBIOS name found for {}'.format(remote_addr))
#     elif len(names) > 1:
#         logging.warn('More than one NetBIOS name for {}'.format(remote_addr))
#     return names[0]
# 
# class NameError(Exception):
#     pass


# Path: ifcb/data/transfer/remote.py
import os
from collections import defaultdict
from .smb_utils import smb_connect, get_netbios_name, NameError
from smb.base import SharedDevice

        self.directory = directory
        self._c = None
    def open(self):
        if self._c is not None:
            return
        try:
            self._c = smb_connect(self.addr, self.username, self.password, self.netbios_name, self.timeout)
        except:
            raise IfcbConnectionError('unable to connect to IFCB')
    def close(self):
        if self._c is not None:
            self._c.close()
            self._c = None
    def __enter__(self):
        if self.connect:
            self.open()
        return self
    def __exit__(self, type, value, traceback):
        self.close()
    def ensure_connected(self):
        if self._c is None:
            raise IfcbConnectionError('IFCB is not connected')
    def is_responding(self):
        # tries to get NetBIOS name to see if IFCB is responding
        if self.netbios_name is not None:
            return True # FIXME determine connection state
        if self._c is not None:
            return True
        else:
            try:

                get_netbios_name(self.addr, timeout=self.timeout)