<commit_before>"""
fileperms is small library for describing file permissions.
"""

import enum
import os
import pathlib
import re
import stat

__version__ = '1.0.2'


class Permission(enum.IntEnum):
    """
    Enum with available permissions
    """
    suid = stat.S_ISUID
    sgid = stat.S_ISGID
    sticky = stat.S_ISVTX

    owner_read = stat.S_IRUSR
    owner_write = stat.S_IWUSR
    owner_exec = stat.S_IXUSR

    group_read = stat.S_IRGRP
    group_write = stat.S_IWGRP
    group_exec = stat.S_IXGRP

    other_read = stat.S_IROTH
    other_write = stat.S_IWOTH
    other_exec = stat.S_IXOTH


# pylint: disable=too-many-instance-attributes
class Permissions:
    """
    Class that helps manipulating permissions of file
    """
    RXP_FILEMODE = re.compile(r'^[r-][w-][xsS-][r-][w-][xsS-][r-][w-][xtT-]$')
    RXP_OCTAL = re.compile(r'^[0-7]{3,4}$')

    def __init__(self):
        self.suid = False
        self.sgid = False
        self.sticky = False
        self.owner_read = False
        self.owner_write = False
        self.owner_exec = False
        self.group_read = False
        self.group_write = False
        self.group_exec = False
        self.other_read = False
        self.other_write = False
        self.other_exec = False

    def set(self, perm: Permission, value: bool):
        """
        Enable or disable permission
        :param perm:One of Permission item
        :param value:
        :return self:
        """
        setattr(self, perm.name, value)
        return self

    def get(self, perm: Permission):
        """
        Return value of permission
        :param perm:
        :return:
        """
        return getattr(self, perm.name)

    @classmethod
    def from_path(cls, path):
        """
        Read files permissions and create Permissions object with filled properties
        :param path:String or pathlib.Path
        :return:
        """
        if isinstance(path, pathlib.Path):
            modes = path.lstat().st_mode
        elif isinstance(path, str):
            modes = os.lstat(path).st_mode
        else:
            raise TypeError("path must be a string or pathilb.Path instance")

        prm = cls()
        for mode in Permission:
            setattr(prm, mode.name, modes & mode == mode)

        return prm

    @classmethod
    def from_int(cls, perms: int):
        """
        Create Permissions object, read permissions from int value
        :param perms:
        :return:
        """<commit_msg>improved docs (return) for Permissions.get<commit_after>"""
fileperms is small library for describing file permissions.
"""

import enum
import os
import pathlib
import re
import stat

__version__ = '1.0.2'


class Permission(enum.IntEnum):
    """
    Enum with available permissions
    """
    suid = stat.S_ISUID
    sgid = stat.S_ISGID
    sticky = stat.S_ISVTX

    owner_read = stat.S_IRUSR
    owner_write = stat.S_IWUSR
    owner_exec = stat.S_IXUSR

    group_read = stat.S_IRGRP
    group_write = stat.S_IWGRP
    group_exec = stat.S_IXGRP

    other_read = stat.S_IROTH
    other_write = stat.S_IWOTH
    other_exec = stat.S_IXOTH


# pylint: disable=too-many-instance-attributes
class Permissions:
    """
    Class that helps manipulating permissions of file
    """
    RXP_FILEMODE = re.compile(r'^[r-][w-][xsS-][r-][w-][xsS-][r-][w-][xtT-]$')
    RXP_OCTAL = re.compile(r'^[0-7]{3,4}$')

    def __init__(self):
        self.suid = False
        self.sgid = False
        self.sticky = False
        self.owner_read = False
        self.owner_write = False
        self.owner_exec = False
        self.group_read = False
        self.group_write = False
        self.group_exec = False
        self.other_read = False
        self.other_write = False
        self.other_exec = False

    def set(self, perm: Permission, value: bool):
        """
        Enable or disable permission
        :param perm:One of Permission item
        :param value:
        :return self:
        """
        setattr(self, perm.name, value)
        return self

    def get(self, perm: Permission):
        """
        Return value of permission
        :param perm:
        :return Permission:
        """
        return getattr(self, perm.name)

    @classmethod
    def from_path(cls, path):
        """
        Read files permissions and create Permissions object with filled properties
        :param path:String or pathlib.Path
        :return:
        """
        if isinstance(path, pathlib.Path):
            modes = path.lstat().st_mode
        elif isinstance(path, str):
            modes = os.lstat(path).st_mode
        else:
            raise TypeError("path must be a string or pathilb.Path instance")

        prm = cls()
        for mode in Permission:
            setattr(prm, mode.name, modes & mode == mode)

        return prm

    @classmethod
    def from_int(cls, perms: int):
        """
        Create Permissions object, read permissions from int value
        :param perms:
        :return:
        """
{'fraction_non_alphanumeric': 0.10063770426464727, 'fraction_numerical': 0.0027899561578318055, 'mean_word_length': 2.1077399380804955, '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': '6472274', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1537, 'n_words': 401}