<commit_before>import sys
import os
import platform
import os.path

import dcos.util
import dcos.constants
from dcos.subcommand import package_dir

BASE_URL="https://github.com/mesosphere/kubernetes-mesos/releases/download/"
KUBECTL_VERSION="v0.5.0"

def kubectl_binary_path_and_url():
    data_dir = package_dir("kubernetes")
    base = os.path.join(data_dir, "kubectl")
    system, node, release, version, machine, processor = platform.uname()

    if system == "Darwin":
        return (base + "_darwin", BASE_URL + KUBECTL_VERSION + "/kubectl-" + KUBECTL_VERSION + "-darwin-amd64.tgz")
    elif system == "Linux":
        return (base + "_linux", BASE_URL + KUBECTL_VERSION + "/kubectl-" + KUBECTL_VERSION + "-linux-amd64.tgz")
    else:
        return (None, None)

def download_kubectl(url, kubectl_path):
    import tarfile

    with dcos.util.temptext() as (fd, tar_file_path):
        try:
            # download tar.gz
            print "Download kubectl from " + url
            from clint.textui import progress
            import requests
            r = requests.get(url, stream=True)
            total_length = int(r.headers.get("content-length"))
            for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1):
                if chunk:
                    os.write(fd, chunk)

            # unarchive kubectl from tar.gz
            tar_file = tarfile.open(tar_file_path, mode="r:gz")
            tar_file.getmembers()<commit_msg>Port to urllib2 to escape InsecurePlatform exception Mac<commit_after>import sys
import os
import platform
import os.path

import dcos.util
import dcos.constants
from dcos.subcommand import package_dir

BASE_URL="https://github.com/mesosphere/kubernetes-mesos/releases/download/"
KUBECTL_VERSION="v0.5.0"

def kubectl_binary_path_and_url():
    data_dir = package_dir("kubernetes")
    base = os.path.join(data_dir, "kubectl")
    system, node, release, version, machine, processor = platform.uname()

    if system == "Darwin":
        return (base + "_darwin", BASE_URL + KUBECTL_VERSION + "/kubectl-" + KUBECTL_VERSION + "-darwin-amd64.tgz")
    elif system == "Linux":
        return (base + "_linux", BASE_URL + KUBECTL_VERSION + "/kubectl-" + KUBECTL_VERSION + "-linux-amd64.tgz")
    else:
        return (None, None)

def read_in_chunks(file_object, chunk_size=1024):
    while True:
        data = file_object.read(chunk_size)
        if not data:
            break
        yield data

def download_kubectl(url, kubectl_path):
    import tarfile

    with dcos.util.temptext() as (fd, tar_file_path):
        try:
            # download tar.gz
            print "Download kubectl from " + url
            from clint.textui import progress
            import urllib2
            f = urllib2.urlopen(url)
            total_length = int(f.info().getheader("Content-Length"))
            for chunk in progress.bar(read_in_chunks(f), expected_size=(total_length/1024) + 1):
                if chunk:
                    os.write(fd, chunk)

            # unarchive kubectl from tar.gz
            tar_file = tarfile.open(tar_file_path, mode="r:gz")
            tar_file.getmembers()
{'fraction_non_alphanumeric': 0.10974842767295598, 'fraction_numerical': 0.0110062893081761, 'mean_word_length': 2.7161214953271027, 'pattern_counts': {'":': 4, '<': 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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1839488', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1023, 'n_words': 228}