<commit_before>#!/usr/bin/env python

import os
import subprocess
import contextlib
import distutils.spawn

import click


__version__ = '0.1.2'
__all__ = ['local_forward_tunnel', 'main']


@contextlib.contextmanager
def local_forward_tunnel(local_addr, remote_addr, hostname):
    cmd = distutils.spawn.find_executable('ssh') or '/usr/bin/ssh'
    forward_string = '%s:%d:%s:%d' % (local_addr + remote_addr)
    proc = subprocess.Popen(
        [cmd, '-N', '-L', forward_string, hostname],
        stdin=subprocess.DEVNULL,
        stdout=subprocess.DEVNULL)
    try:
        yield
    finally:
        proc.kill()
        proc.wait()


def shell(local_addr, hostname):
    cmd = os.environ.get('SHELL', '/bin/sh')
    env = dict(os.environ)
    env['DOCKER_HOST'] = 'tcp://%s:%d' % local_addr
    env['DOCKER_PROMPT_INFO'] = hostname
    proc = subprocess.Popen([cmd, '--login'], env=env)
    proc.wait()


@click.command()
@click.option('--local-host', default='127.0.0.1')
@click.option('--local-port', default=4243)
@click.option('--remote-host', default='127.0.0.1')<commit_msg>fix up the compatible problem of python 2.x<commit_after>#!/usr/bin/env python

import os
import subprocess
import contextlib
import distutils.spawn

import click


__version__ = '0.1.2'
__all__ = ['local_forward_tunnel', 'main']


def devnull(mode):
    if hasattr(subprocess, 'DEVNULL'):
        return subprocess.DEVNULL
    else:
        return open(os.devnull, mode)


@contextlib.contextmanager
def local_forward_tunnel(local_addr, remote_addr, hostname):
    cmd = distutils.spawn.find_executable('ssh') or '/usr/bin/ssh'
    forward_string = '%s:%d:%s:%d' % (local_addr + remote_addr)
    proc = subprocess.Popen(
        [cmd, '-N', '-L', forward_string, hostname],
        stdin=devnull(mode='r'),
        stdout=devnull(mode='w'))
    try:
        yield
    finally:
        proc.kill()
        proc.wait()


def shell(local_addr, hostname):
    cmd = os.environ.get('SHELL', '/bin/sh')
    env = dict(os.environ)
    env['DOCKER_HOST'] = 'tcp://%s:%d' % local_addr
    env['DOCKER_PROMPT_INFO'] = hostname
    proc = subprocess.Popen([cmd, '--login'], env=env)
    proc.wait()


@click.command()
@click.option('--local-host', default='127.0.0.1')
@click.option('--local-port', default=4243)
@click.option('--remote-host', default='127.0.0.1')
{'fraction_non_alphanumeric': 0.17023096663815226, 'fraction_numerical': 0.016680923866552608, 'mean_word_length': 3.5862745098039217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '1305308', 'n_tokens_mistral': 867, 'n_tokens_neox': 840, 'n_words': 155}