<commit_before>from collections import defaultdict
import logging

from .. import HTTPClient

from atlassian import Service, PermissionEntry, Project


__author__ = '<NAME>'
l = logging.getLogger(__name__)


class Jira(Service):
    name = 'Jira'

    @property
    def client(self):
        if 'client' not in self._data:
            raise RuntimeError('Please login')
        return self._data['client']

    def login(self, user, password):
        super().login(user, password)
        self._data['client'] = HTTPClient(self.url, user=user, password=password)

    def logout(self):
        pass  # TODO logout of jira

    def get_projects(self):
        for project in self.client.get('rest/api/2/project'):
            yield Project(project)

    def get_permissions(self, projectkey):
        permissions = defaultdict(lambda: defaultdict(lambda: list()))
        for name, url in self.get_roles(projectkey).items():
            role = self.client.get(url)
            for actor in role.get('actors', ()):
                if actor['type'] is 'atlassian-group-role-actor':
                    permissions[name][PermissionEntry.GROUP].append(actor['name'])
                elif actor['type'] in 'atlassian-user-role-actor':
                    permissions[name][PermissionEntry.USER].append(actor['name'])
                else:
                    self.l.error('Could not match type "{}" to user or group'.format(actor['type']),
                                 extra={'actor': actor})
        for perm, types in permissions.items():
            for type, members in types:
                yield PermissionEntry(perm, type, members)

    def get_roles(self, projectkey):
        return self.client.get('rest/api/2/project/{}/role'.format(projectkey))<commit_msg>Iterate over dicts correctly<commit_after>from collections import defaultdict
import logging

from .. import HTTPClient

from atlassian import Service, PermissionEntry, Project


__author__ = '<NAME>'
l = logging.getLogger(__name__)


class Jira(Service):
    name = 'Jira'

    @property
    def client(self):
        if 'client' not in self._data:
            raise RuntimeError('Please login')
        return self._data['client']

    def login(self, user, password):
        super().login(user, password)
        self._data['client'] = HTTPClient(self.url, user=user, password=password)

    def logout(self):
        pass  # TODO logout of jira

    def get_projects(self):
        for project in self.client.get('rest/api/2/project'):
            yield Project(project)

    def get_permissions(self, projectkey):
        permissions = defaultdict(lambda: defaultdict(lambda: list()))
        for name, url in self.get_roles(projectkey).items():
            role = self.client.get(url)
            for actor in role.get('actors', ()):
                if actor['type'] is 'atlassian-group-role-actor':
                    permissions[name][PermissionEntry.GROUP].append(actor['name'])
                elif actor['type'] in 'atlassian-user-role-actor':
                    permissions[name][PermissionEntry.USER].append(actor['name'])
                else:
                    self.l.error('Could not match type "{}" to user or group'.format(actor['type']),
                                 extra={'actor': actor})
        for perm, types in permissions.items():
            for type, members in types.items():
                yield PermissionEntry(perm, type, members)

    def get_roles(self, projectkey):
        return self.client.get('rest/api/2/project/{}/role'.format(projectkey))
{'fraction_non_alphanumeric': 0.12278729980331554, 'fraction_numerical': 0.00112391121101433, 'mean_word_length': 2.473170731707317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2235653', 'n_tokens_mistral': 976, 'n_tokens_neox': 945, 'n_words': 240}