<commit_before>import hashlib
import os.path
from pathlib import Path
from urllib.parse import urlparse
from urllib.request import urlopen

_BLOCK_SIZE = 16384


def download(url, checksum=None, **kwargs):
    """Download file from a URL

    Parameters
    ----------
    url : str
        URL from which to download
    checksum : str or None
        MD5 checksum to check against
    **kwargs : dict
        Optional arguements passed to urlopen()
        context: ssl.SSLContext object
            Describes the various SSL options,
            e.g. context=ssl._create_unverified_context()

    Returns
    -------
    basename : str
        Name of file written locally

    """
    req = urlopen(url, **kwargs)
    # Get file size from header
    file_size = req.length

    # Check if file already downloaded
    basename = Path(urlparse(url).path).name
    if os.path.exists(basename):
        if os.path.getsize(basename) == file_size:
            print('Skipping {}, already downloaded'.format(basename))
            return basename

    # Copy file to disk in chunks
    print('Downloading {}... '.format(basename), end='')
    downloaded = 0
    with open(basename, 'wb') as fh:
        while True:
            chunk = req.read(_BLOCK_SIZE)
            if not chunk:
                break
            fh.write(chunk)
            downloaded += len(chunk)
            status = '{:10}  [{:3.2f}%]'.format(
                downloaded, downloaded * 100. / file_size)
            print(status + '\b'*len(status), end='')<commit_msg>removed contex related comments<commit_after>import hashlib
import os.path
from pathlib import Path
from urllib.parse import urlparse
from urllib.request import urlopen

_BLOCK_SIZE = 16384


def download(url, checksum=None, **kwargs):
    """Download file from a URL

    Parameters
    ----------
    url : str
        URL from which to download
    checksum : str or None
        MD5 checksum to check against
    **kwargs : dict
        Keyword arguments passed to :func:urllib.request.urlopen

    Returns
    -------
    basename : str
        Name of file written locally

    """
    req = urlopen(url, **kwargs)
    # Get file size from header
    file_size = req.length

    # Check if file already downloaded
    basename = Path(urlparse(url).path).name
    if os.path.exists(basename):
        if os.path.getsize(basename) == file_size:
            print('Skipping {}, already downloaded'.format(basename))
            return basename

    # Copy file to disk in chunks
    print('Downloading {}... '.format(basename), end='')
    downloaded = 0
    with open(basename, 'wb') as fh:
        while True:
            chunk = req.read(_BLOCK_SIZE)
            if not chunk:
                break
            fh.write(chunk)
            downloaded += len(chunk)
            status = '{:10}  [{:3.2f}%]'.format(
                downloaded, downloaded * 100. / file_size)
            print(status + '\b'*len(status), end='')
{'fraction_non_alphanumeric': 0.10811721118221623, 'fraction_numerical': 0.009430784776018861, 'mean_word_length': 2.119747899159664, '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': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2708044', 'n_tokens_mistral': 874, 'n_tokens_neox': 833, 'n_words': 258}