<commit_before># -*- coding: utf-8 -*-
"""
hyper/common/util
~~~~~~~~~~~~~~~~~

General utility functions for use with hyper.
"""
from hyper.compat import unicode, bytes, imap

def to_bytestring(element):
    """
    Converts a single string to a bytestring, encoding via UTF-8 if needed.
    """
    if isinstance(element, unicode):
        return element.encode('utf-8')
    elif isinstance(element, bytes):
        return element
    else:
        raise ValueError("Non string type.")


def to_bytestring_tuple(*x):
    """
    Converts the given strings to a bytestring if necessary, returning a
    tuple. Uses ``to_bytestring``.
    """
    return tuple(imap(to_bytestring, x))<commit_msg>Add utility function to properly handle and split hostnames and IPs from ports that handles IPv6<commit_after># -*- coding: utf-8 -*-
"""
hyper/common/util
~~~~~~~~~~~~~~~~~

General utility functions for use with hyper.
"""
from hyper.compat import unicode, bytes, imap

def to_bytestring(element):
    """
    Converts a single string to a bytestring, encoding via UTF-8 if needed.
    """
    if isinstance(element, unicode):
        return element.encode('utf-8')
    elif isinstance(element, bytes):
        return element
    else:
        raise ValueError("Non string type.")


def to_bytestring_tuple(*x):
    """
    Converts the given strings to a bytestring if necessary, returning a
    tuple. Uses ``to_bytestring``.
    """
    return tuple(imap(to_bytestring, x))

def to_host_port_tuple(host_port_str, default_port=80)
    """
    Converts the given string containing a host and possibly a port
    to a tuple.
    """
    try:
        host, port = host_port_str.rsplit(':', 1)
    except ValueError:
        host, port = host_port_str, default_port
    else:
        port = int(port)

    host = host.strip('[]')

    return tuple(host, port)
{'fraction_non_alphanumeric': 0.12405609492988134, 'fraction_numerical': 0.005393743257820928, 'mean_word_length': 3.1591928251121075, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7207790', 'n_tokens_mistral': 559, 'n_tokens_neox': 550, 'n_words': 180}