import six
import re


def gen_filename(collection_name, format_part, date_string, extension):
    """
    Creates a filename based on various properties of a Poll Request and Content Block

    :param collection_name: The collection name
    :param format_part: The format part (e.g., '_STIX_10_')
    :param date_string: A datestring
    :param extension: The file extension to use
    :return: A string containing the generated filename
    """
    if six.PY3:
        return (collection_name.lstrip(".") +
                format_part +
                re.sub(r"[^a-zA-Z0-9]", "_", date_string) + extension
                ).translate('/\\:*?"<>|')
    else:
        return (collection_name.lstrip(".") +
                format_part +
                re.sub(r"[^a-zA-Z0-9]", "_", date_string) + extension
                ).translate(None, '/\\:*?"<>|')