<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import six

try:
    from urllib.parse import urljoin
    from urllib.request import pathname2url, url2pathname
except:
    from urlparse import urljoin
    from urllib import pathname2url, url2pathname

def path_to_url(path):
    if six.PY2:
        path = path.encode('utf-8')
    return pathname2url(path)

def url_to_path(url):
    if six.PY2:
        url = url.encode('utf-8')
    return url2pathname(url)

def package_resource(path):
    """Get resource from package

    @param path: the relative path of resource

    @return: the absolute path of resource
    """

    curr_path = os.path.split(os.path.abspath(__file__))[0]
    return os.path.abspath(os.path.join(curr_path, path))
<commit_msg>Add a method to encode url<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import re
import six

try:
    from urllib.parse import urljoin
    from urllib.request import pathname2url, url2pathname
except:
    from urlparse import urljoin
    from urllib import pathname2url, url2pathname

def path_to_url(path):
    if six.PY2:
        path = path.encode('utf-8')
    return pathname2url(path)

def url_to_path(url):
    if six.PY2:
        url = url.encode('utf-8')
    return url2pathname(url)

def url_safe(string):
    new_str = re.sub(
            r'[<>,~!#&\{\}\(\)\[\]\*\^\$\?]', ' ', string
    )

    return '-'.join(new_str.strip().split())


def package_resource(path):
    """Get resource from package

    @param path: the relative path of resource

    @return: the absolute path of resource
    """

    curr_path = os.path.split(os.path.abspath(__file__))[0]
    return os.path.abspath(os.path.join(curr_path, path))

{'fraction_non_alphanumeric': 0.12824956672443674, 'fraction_numerical': 0.01386481802426343, 'mean_word_length': 3.123809523809524, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, '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': '456623', 'n_tokens_mistral': 609, 'n_tokens_neox': 599, 'n_words': 151}