<commit_before>from session import Session
from visualization import Visualization


class Lightning(object):

    def __init__(self, host="http://localhost:3000", ipython=False, auth=None):
        self.host = host

        self.auth = auth
        if auth is not None:
            if isinstance(auth, tuple):
                self.set_basic_auth(auth[0], auth[1])

        if ipython:
            self.enable_ipython()

    def enable_ipython(self, **kwargs):
        """
        ipython code inspired by code powering similar functionality in mpld3:
        https://github.com/jakevdp/mpld3/blob/master/mpld3/_display.py#L357
        """

        from IPython.core.getipython import get_ipython
        ip = get_ipython()
        formatter = ip.display_formatter.formatters['text/html']
        formatter.for_type(Visualization,
                           lambda viz, kwds=kwargs: viz.get_html())

    def disable_ipython(self):
        from IPython.core.getipython import get_ipython
        ip = get_ipython()
        formatter = ip.display_formatter.formatters['text/html']
        formatter.type_printers.pop(Visualization, None)

    def create_session(self, name=None):
        self.session = Session.create(self.host, name=name, auth=self.auth)
        return self.session
<commit_msg>Add repr<commit_after>from session import Session
from visualization import Visualization


class Lightning(object):

    def __init__(self, host="http://localhost:3000", ipython=False, auth=None):
        self.host = host

        self.auth = auth
        if auth is not None:
            if isinstance(auth, tuple):
                self.set_basic_auth(auth[0], auth[1])

        if ipython:
            self.enable_ipython()

    def __repr__(self):
        s = 'Lightning at host: %s' % self.host
        return s

    def enable_ipython(self, **kwargs):
        """
        ipython code inspired by code powering similar functionality in mpld3:
        https://github.com/jakevdp/mpld3/blob/master/mpld3/_display.py#L357
        """

        from IPython.core.getipython import get_ipython
        ip = get_ipython()
        formatter = ip.display_formatter.formatters['text/html']
        formatter.for_type(Visualization,
                           lambda viz, kwds=kwargs: viz.get_html())

    def disable_ipython(self):
        from IPython.core.getipython import get_ipython
        ip = get_ipython()
        formatter = ip.display_formatter.formatters['text/html']
        formatter.type_printers.pop(Visualization, None)

    def create_session(self, name=None):
        self.session = Session.create(self.host, name=name, auth=self.auth)
        return self.session

{'fraction_non_alphanumeric': 0.09951365506921063, 'fraction_numerical': 0.008978675645342313, 'mean_word_length': 2.537037037037037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '5349858', 'n_tokens_mistral': 836, 'n_tokens_neox': 785, 'n_words': 171}