<commit_before>import os

from collections import defaultdict

from .smb_utils import smb_connect, get_netbios_name, NameError
from smb.base import SharedDevice

DEFAULT_TIMEOUT = 30
DEFAULT_SHARE = 'data'

class IfcbConnectionError(Exception):
    pass

def do_nothing(*args, **kw):
    pass

class RemoteIfcb(object):
    def __init__(self, addr, username, password, timeout=DEFAULT_TIMEOUT,
                    share=DEFAULT_SHARE, connect=True):
        self.addr = addr
        self.username = username
        self.password = password
        self.timeout = timeout
        self.share = share
        self.connect = connect
        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.timeout)
        except:
            raise IfcbConnectionError('unable to connect to IFCB')
    def close(self):
        if self._c is not None:
            self._c.close()
    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._c is not None:
            return True
        else:
            try:
                get_netbios_name(self.addr, timeout=self.timeout)
                return True
            except:
                return False
    def share_exists(self):
        self.ensure_connected()
        for share in self._c.listShares():
            if share.type == SharedDevice.DISK_TREE:
                if share.name.lower() == self.share.lower():<commit_msg>minor state mgt bugfix<commit_after>import os

from collections import defaultdict

from .smb_utils import smb_connect, get_netbios_name, NameError
from smb.base import SharedDevice

DEFAULT_TIMEOUT = 30
DEFAULT_SHARE = 'data'

class IfcbConnectionError(Exception):
    pass

def do_nothing(*args, **kw):
    pass

class RemoteIfcb(object):
    def __init__(self, addr, username, password, timeout=DEFAULT_TIMEOUT,
                    share=DEFAULT_SHARE, connect=True):
        self.addr = addr
        self.username = username
        self.password = password
        self.timeout = timeout
        self.share = share
        self.connect = connect
        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.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._c is not None:
            return True
        else:
            try:
                get_netbios_name(self.addr, timeout=self.timeout)
                return True
            except:
                return False
    def share_exists(self):
        self.ensure_connected()
        for share in self._c.listShares():
            if share.type == SharedDevice.DISK_TREE:
                if share.name.lower() == self.share.lower():
{'fraction_non_alphanumeric': 0.08125677139761647, 'fraction_numerical': 0.0010834236186348862, 'mean_word_length': 2.017156862745098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '491210', 'n_tokens_mistral': 1040, 'n_tokens_neox': 1022, 'n_words': 296}