<commit_before>"""
Adapters for different languages.
"""
import ConfigParser

import code
import sys

import StringIO
import urlparse

CONFIG = ConfigParser.RawConfigParser()
CONFIG.read('app.conf')


def grep_stdout(func):
    """
    Wrap stderr and stdout to a str return value.
    :param func:
    """

    def wrap(*args):
        """
        Wraps a function.

        :param args: Bunch of Arguments.
        """
        old_out = sys.stdout
        old_err = sys.stderr
        sys.stdout = StringIO.StringIO()
        sys.stderr = StringIO.StringIO()
        func(*args)
        err = sys.stderr.getvalue()
        out = sys.stdout.getvalue().strip().split('\n')
        sys.stdout.close()
        sys.stderr.close()
        sys.stdout = old_out
        sys.stderr = old_err
        return out, err
    return wrap


class PythonWrapper(object):
    """
    Wrapper to use Python for Analytics.
    """

    def __init__(self, uid, token, mongo_uri):
        self.console = code.InteractiveConsole()
        sdk = CONFIG.get('suricate', 'python_sdk')
        # set User identifier and tell where object store is.
        self.console.push('UID = \'' + str(uid) + '\'')
        self.console.push('TOKEN = \'' + str(token) + '\'')
        uri = urlparse(mongo_uri)
        str_uri = uri.scheme + '://'+ uid + ':' + token + '@' + uri.netloc \
                  + '/' + uid
        self.console.push('OBJECT_STORE_URI = \'' + str(str_uri) + '\'')
        # This preload will be downloaded with the notebook.
        preload = file(sdk).read()
        self.console.runcode(preload)

    @grep_stdout
    def run(self, src):
        """
        Run some code.
        """
        self.console.resetbuffer()
        self.console.runcode(src)

    @grep_stdout
    def interact(self, loc):
        """
        Interact with the interpreter directly.
        """
        self.console.push(loc)


class RWrapper(object):
    """
    Wrapper to use the R language...
    """

    pass<commit_msg>minor fix.<commit_after>"""
Adapters for different languages.
"""
import ConfigParser

import code
import sys

import StringIO
import urlparse

CONFIG = ConfigParser.RawConfigParser()
CONFIG.read('app.conf')


def grep_stdout(func):
    """
    Wrap stderr and stdout to a str return value.
    :param func:
    """

    def wrap(*args):
        """
        Wraps a function.

        :param args: Bunch of Arguments.
        """
        old_out = sys.stdout
        old_err = sys.stderr
        sys.stdout = StringIO.StringIO()
        sys.stderr = StringIO.StringIO()
        func(*args)
        err = sys.stderr.getvalue()
        out = sys.stdout.getvalue().strip().split('\n')
        sys.stdout.close()
        sys.stderr.close()
        sys.stdout = old_out
        sys.stderr = old_err
        return out, err
    return wrap


class PythonWrapper(object):
    """
    Wrapper to use Python for Analytics.
    """

    def __init__(self, uid, token, mongo_uri):
        self.console = code.InteractiveConsole()
        sdk = CONFIG.get('suricate', 'python_sdk')
        # set User identifier and tell where object store is.
        self.console.push('UID = \'' + str(uid) + '\'')
        self.console.push('TOKEN = \'' + str(token) + '\'')
        uri = urlparse.urlparse(mongo_uri)
        str_uri = uri.scheme + '://'+ uid + ':' + token + '@' + uri.netloc \
                  + '/' + uid
        self.console.push('OBJECT_STORE_URI = \'' + str(str_uri) + '\'')
        # This preload will be downloaded with the notebook.
        preload = file(sdk).read()
        self.console.runcode(preload)

    @grep_stdout
    def run(self, src):
        """
        Run some code.
        """
        self.console.resetbuffer()
        self.console.runcode(src)

    @grep_stdout
    def interact(self, loc):
        """
        Interact with the interpreter directly.
        """
        self.console.push(loc)


class RWrapper(object):
    """
    Wrapper to use the R language...
    """

    pass
{'fraction_non_alphanumeric': 0.13413413413413414, 'fraction_numerical': 0.0, 'mean_word_length': 2.0326251896813354, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5790186', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1198, 'n_words': 290}