<commit_before>#from sshpubkeys import SSHKey


class Usermgmt(object):
    def attrs(self):
        raise NotImplementedError

    def get_dict(self):
        return dict((key, value) for key, value in self.__dict__.items()
            if not callable(value) and not key.startswith('__'))

    def __values(self):
        return (getattr(self, attr) for attr in self.attrs())

    def __eq__(self, other):
        # print('self:\t' + str(self.get_dict()))
        # print('other:\t' + str(other.get_dict()))
        return self.get_dict() == other.get_dict()

    def __str__(self):
        return "<Usermgmt {0}>".format(self.get_dict())

    def refresh():
        raise NotImplementedError

    def save():
        raise NotImplementedError

class Role(Usermgmt):
    def __init__(self, rolename=None, groups=[]):
        self.rolename = str(rolename)
        if groups:
            self.groups = set(sorted(groups))
        else:
            self.groups = set()

    def __eq__(self, other):
        return self.rolename == other.rolename and \
            self.groups == other.groups

    def __str__(self):
        return "<Role {}>".format(self.rolename)

    def attrs(self):
        return ['rolename', 'roles']

class Group(Usermgmt):
    def __init__(self, groupname=None, gid=None):
        self.groupname = str(groupname)
        self.gid = str(gid)

    def __cmp__(self, other):
        return self.gid == other.gid and self.groupname == other.groupname

    def __eq__(self, other):
        return self.__cmp__(other)

    def attrs(self):
        return ['groupname', 'gid']


class User(Usermgmt):
    def __init__(self, username=None, password=<PASSWORD>, email=None, uid=None, public_keys=None, groups=None):
        self.username = str(username)
        self.password = str(password)
        self.email = str(email)
        self.uid = str(uid)
        if public_keys:
            self.public_keys = [str(k) for k in public_keys]
        else:
            self.public_keys = None
        if groups:
            self.groups = [str(g) for g in groups]
        else:
            self.groups = None

    def __cmp__(self, other):
        for a in self.attrs():
            self_a = getattr(self, a)
            other_a = getattr(other, a)
            if type(self_a) == list and type(other_a) == list or type(self_a) == set and type(other_a) == set:
                self_a = sorted(list(self_a))
                other_a = sorted(list(other_a))
            c = cmp(self_a, other_a)
            if c:
                return c
        return 0

    def attrs(self):
        return ['username', 'password', 'email', 'uid', 'public_keys', 'groups']

    def validate_key(self, key):
        try:
            ssh = SSHKey(key)
            ssh.parse()
            return ssh
        except:
            return False

    def get_ssh_key_comment(self, key):
        ssh = SSHKey(key)
        ssh.parse()<commit_msg>Add some user attrs<commit_after>#from sshpubkeys import SSHKey

class Usermgmt(object):
    def attrs(self):
        raise NotImplementedError

    def get_dict(self):
        return dict((key, value) for key, value in self.__dict__.items()
            if not callable(value) and not key.startswith('__'))

    def __values(self):
        return (getattr(self, attr) for attr in self.attrs())

    def __eq__(self, other):
        # print('self:\t' + str(self.get_dict()))
        # print('other:\t' + str(other.get_dict()))
        return self.get_dict() == other.get_dict()

    def __str__(self):
        return "<Usermgmt {0}>".format(self.get_dict())

    def refresh():
        raise NotImplementedError

    def save():
        raise NotImplementedError

class Role(Usermgmt):
    def __init__(self, rolename=None, groups=[]):
        self.rolename = str(rolename)
        if groups:
            self.groups = set(sorted(groups))
        else:
            self.groups = set()

    def __eq__(self, other):
        return self.rolename == other.rolename and \
            self.groups == other.groups

    def __str__(self):
        return "<Role {}>".format(self.rolename)

    def attrs(self):
        return ['rolename', 'roles']

class Group(Usermgmt):
    def __init__(self, groupname=None, gid=None):
        self.groupname = str(groupname)
        self.gid = str(gid)

    def __cmp__(self, other):
        return self.gid == other.gid and self.groupname == other.groupname

    def __eq__(self, other):
        return self.__cmp__(other)

    def attrs(self):
        return ['groupname', 'gid']


class User(Usermgmt):
    def __init__(self, username=None, password=<PASSWORD>, email=None, uid=None, public_keys=None, groups=None):
        self.username = str(username)
        self.password = <PASSWORD>)
        self.email = str(email)
        self.uid = str(uid)
        if public_keys:
            self.public_keys = [str(k) for k in public_keys]
        else:
            self.public_keys = None
        if groups:
            self.groups = [str(g) for g in groups]
        else:
            self.groups = None

    def __cmp__(self, other):
        for a in self.attrs():
            self_a = getattr(self, a)
            other_a = getattr(other, a)
            if type(self_a) == list and type(other_a) == list or type(self_a) == set and type(other_a) == set:
                self_a = sorted(list(self_a))
                other_a = sorted(list(other_a))
            c = cmp(self_a, other_a)
            if c:
                return c
        return 0

    def attrs(self):
        return ['username', 'password', 'email', 'uid', 'public_keys', 'groups', 'hash_ldap', 'password_mod_date', 'sshkey_mod_date', 'auth_code', 'auth_code_date']

    def validate_key(self, key):
        try:
            ssh = SSHKey(key)
            ssh.parse()
            return ssh
        except:
            return False

    def get_ssh_key_comment(self, key):
        ssh = SSHKey(key)
        ssh.parse()
{'fraction_non_alphanumeric': 0.12367312552653749, 'fraction_numerical': 0.0006739679865206403, 'mean_word_length': 2.167556029882604, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '5846449', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1821, 'n_words': 459}