<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright 2010 Asidev s.r.l.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""


from aybu.manager.exc import ParamsError
from aybu.manager.models import Group
from sqlalchemy.exc import IntegrityError

from pyramid.httpexceptions import (HTTPCreated,
                                    HTTPNoContent,
                                    HTTPConflict,
                                    HTTPPreconditionFailed)
from pyramid.view import view_config


@view_config(route_name='groups', request_method='GET')
def list(context, request):
    return {group.name: group.to_dict() for group in
            Group.all(request.db_session)}


@view_config(route_name='groups', request_method='POST')
def create(context, request):

    try:
        name = request.params['name']
        g = Group(name=name)
        request.db_session.add(g)
        request.db_session.flush()

    except KeyError as e:
        raise ParamsError(e)

    except IntegrityError as e:
        error = 'Group {} already exists'.format(name)
        raise HTTPConflict(headers={'X-Request-Error': error})

    else:
        request.db_session.commit()
        return HTTPCreated()


@view_config(route_name='group', request_method=('GET', 'HEAD'))
def info(context, request):
    group = Group.get(request.db_session, request.matchdict['name'])
    return group.to_dict()

<commit_msg>Fixed group parsing, change http error code when groups are not found<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright 2010 Asidev s.r.l.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""


from aybu.manager.exc import ParamsError
from aybu.manager.models import Group
from sqlalchemy.exc import IntegrityError

from pyramid.httpexceptions import (HTTPCreated,
                                    HTTPNoContent,
                                    HTTPConflict,
                                    HTTPPreconditionFailed)
from pyramid.view import view_config


@view_config(route_name='groups', request_method='GET')
def list(context, request):
    return {group.name: group.to_dict() for group in
            Group.all(request.db_session)}


@view_config(route_name='groups', request_method='POST')
def create(context, request):

    try:
        name = request.params['name']
        g = Group(name=name)
        request.db_session.add(g)
        request.db_session.flush()

    except KeyError as e:
        raise ParamsError('Missing parameter: {}'.format(e))

    except IntegrityError as e:
        error = 'Group {} already exists'.format(name)
        raise HTTPConflict(headers={'X-Request-Error': error})

    else:
        request.db_session.commit()
        return HTTPCreated()


@view_config(route_name='group', request_method=('GET', 'HEAD'))
def info(context, request):
    group = Group.get(request.db_session, request.matchdict['name'])
    return group.to_dict()


{'fraction_non_alphanumeric': 0.09603501544799176, 'fraction_numerical': 0.004634397528321318, 'mean_word_length': 3.11983032873807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6518927', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1044, 'n_words': 343}