<commit_before>import os
import string
import random
import bcrypt
from enum import Enum
from importlib import import_module
from flask import current_app as app
from .utc import utcnow


class FileSortAttributes(Enum):
    """
    Enum defining the File Story Attributes.
    """
    name = 1
    created = 2
    modified = 3


class SortOrder(Enum):
    """
    Enum defining the sort order.
    """
    asc = 1
    desc = 2


def last_updated(*docs):
    """Get last last updated date for all given docs."""
    dates = [d.get(app.config['LAST_UPDATED']) for d in docs if d and d.get(app.config['LAST_UPDATED'])]
    return max(dates) if dates else utcnow()


def get_random_string(length=12):
    chars = string.ascii_letters + string.digits
    return ''.join([random.choice(chars) for i in range(length)])


def import_by_path(path):
    module_path, class_name = path.rsplit('.', 1)
    module = import_module(module_path)
    return getattr(module, class_name)


def get_hash(input_str, salt):
    hashed = bcrypt.hashpw(input_str.encode('UTF-8'), bcrypt.gensalt(salt))
    return hashed.decode('UTF-8')


def get_sorted_files(path, sort_by=FileSortAttributes.name, sort_order=SortOrder.asc):
    """
    Get the list of files based on the sort order.
    Sort is allowed on name, created and modified datetime
    :param path: directory path
    :param sort_by: "name", "created", "modified"
    :param sort_order: "asc" - ascending, "desc" - descending
    :return: list of files from the path
    """
    # get the files
    files = [file for file in os.listdir(path) if os.path.isfile(os.path.join(path, file))]
    if sort_by == FileSortAttributes.name:
        if sort_order == SortOrder.asc:
            files.sort(reverse=False)
        else:
            files.sort(reverse=True)
    elif sort_by == FileSortAttributes.created:
        if sort_order == SortOrder.asc:
            files.sort(key=lambda file: os.path.getctime(os.path.join(path, file)), reverse=False)
        else:
            files.sort(key=lambda file: os.path.getctime(os.path.join(path, file)), reverse=True)
    elif sort_by == FileSortAttributes.modified:
        if sort_order == SortOrder.asc:
            files.sort(key=lambda file: os.path.getmtime(os.path.join(path, file)), reverse=False)
        else:
            files.sort(key=lambda file: os.path.getmtime(os.path.join(path, file)), reverse=True)
    else:
        if sort_order == SortOrder.asc:
            files.sort(reverse=False)
        else:
            files.sort(reverse=True)

    return files


def is_hashed(input_str):
    """Check if given input_str is hashed."""
    return input_str.startswith('$2a$')

<commit_msg>removed unnecessary if statements.<commit_after>import os
import string
import random
import bcrypt
from enum import Enum
from importlib import import_module
from flask import current_app as app
from .utc import utcnow


class FileSortAttributes(Enum):
    """
    Enum defining the File Story Attributes.
    """
    name = 1
    created = 2
    modified = 3


class SortOrder(Enum):
    """
    Enum defining the sort order.
    """
    asc = 1
    desc = 2


def last_updated(*docs):
    """Get last last updated date for all given docs."""
    dates = [d.get(app.config['LAST_UPDATED']) for d in docs if d and d.get(app.config['LAST_UPDATED'])]
    return max(dates) if dates else utcnow()


def get_random_string(length=12):
    chars = string.ascii_letters + string.digits
    return ''.join([random.choice(chars) for i in range(length)])


def import_by_path(path):
    module_path, class_name = path.rsplit('.', 1)
    module = import_module(module_path)
    return getattr(module, class_name)


def get_hash(input_str, salt):
    hashed = bcrypt.hashpw(input_str.encode('UTF-8'), bcrypt.gensalt(salt))
    return hashed.decode('UTF-8')


def get_sorted_files(path, sort_by=FileSortAttributes.name, sort_order=SortOrder.asc):
    """
    Get the list of files based on the sort order.
    Sort is allowed on name, created and modified datetime
    :param path: directory path
    :param sort_by: "name", "created", "modified"
    :param sort_order: "asc" - ascending, "desc" - descending
    :return: list of files from the path
    """
    # get the files
    files = [file for file in os.listdir(path) if os.path.isfile(os.path.join(path, file))]
    if sort_by == FileSortAttributes.name:
        files.sort(reverse=(sort_order == SortOrder.desc))
    elif sort_by == FileSortAttributes.created:
        files.sort(key=lambda file: os.path.getctime(os.path.join(path, file)), reverse=(sort_order == SortOrder.desc))
    elif sort_by == FileSortAttributes.modified:
        files.sort(key=lambda file: os.path.getmtime(os.path.join(path, file)), reverse=(sort_order == SortOrder.desc))
    else:
        files.sort(reverse=(sort_order == SortOrder.desc))

    return files


def is_hashed(input_str):
    """Check if given input_str is hashed."""
    return input_str.startswith('$2a$')


{'fraction_non_alphanumeric': 0.117138838657826, 'fraction_numerical': 0.004420333534257585, 'mean_word_length': 3.378188214599824, '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': '2713250', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1559, 'n_words': 433}