<commit_before>from pyramid.exceptions import Forbidden

from cornice import Service


PRODUCTS = {
    '1': {
        'id': '1',
        'name': 'some',
        'price': 300},
    '2': {
        'id': '2',
        'name': 'somesome',
        'price': 320},
    '3': {
        'id': '3',
        'name': 'bar',
        'price': 501},
}


cors_policy = {'enabled': True, 'origins': ('*',)}
prod_source = Service(
    name='data_source',
    path='/products',
    description='some',
    cors_policy=cors_policy)


@prod_source.get()
def get_products(request):
    if 'id' in request.GET:
        return [PRODUCTS.get(str(request.GET['id']))]
    else:
        return list(PRODUCTS.values())


@prod_source.post()
def set_products(request):
    data = request.json
    if all(x in data for x in ['id', 'name', 'price']):
        item_id = str(data['id'])
        PRODUCTS[item_id] = {'id': item_id, 'name': data['name'], 'price': int(data['price'])}
        return {'success': True}
    elif all(x in data for x in ['name', 'price']):
        item_id = str(PRODUCTS.keys() + 1)
        PRODUCTS[item_id] = {'id': item_id, 'name': data['name'], 'price': int(data['price'])}
        return {'success': True}
    else:
        raise Forbidden()<commit_msg>udpate backend: update upsert post to put<commit_after>from pyramid.exceptions import Forbidden

from cornice import Service


PRODUCTS = {
    '1': {
        'id': '1',
        'name': 'some',
        'price': 300},
    '2': {
        'id': '2',
        'name': 'somesome',
        'price': 320},
    '3': {
        'id': '3',
        'name': 'bar',
        'price': 501},
}


cors_policy = {'enabled': True, 'origins': ('*',)}
prod_source = Service(
    name='data_source',
    path='/products',
    description='some',
    cors_policy=cors_policy)


@prod_source.get()
def get_products(request):
    if 'id' in request.GET:
        return [PRODUCTS.get(str(request.GET['id']))]
    else:
        return list(PRODUCTS.values())


@prod_source.put()
def set_products(request):
    data = request.json
    if all(x in data for x in ['id', 'name', 'price']):
        item_id = str(data['id'])
        PRODUCTS[item_id] = {'id': item_id, 'name': data['name'], 'price': int(data['price'])}
        return {'success': True}
    elif all(x in data for x in ['name', 'price']):
        item_id = str(PRODUCTS.keys() + 1)
        PRODUCTS[item_id] = {'id': item_id, 'name': data['name'], 'price': int(data['price'])}
        return {'success': True}
    else:
        raise Forbidden()
{'fraction_non_alphanumeric': 0.19256623171213919, 'fraction_numerical': 0.01265322261763543, 'mean_word_length': 2.7592867756315007, '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': '212227', 'n_tokens_mistral': 903, 'n_tokens_neox': 876, 'n_words': 213}