<commit_before>import json

import sys
import traceback

import cherrypy

from cherrypy import HTTPError
from cherrypy.lib import httputil as cphttputil
from blueberrypy.util import from_collection, to_collection

from GDGUkraine import api
from GDGUkraine.model import User, Event, EventParticipant, Place


class Participants:

    _cp_config = {"tools.json_in.on": True}

    @cherrypy.tools.json_out()
    def create(self, **kwargs):
        #return 'creating someone'
        req = cherrypy.request
        orm_session = req.orm_session
        user = from_collection(req.json, User())
        orm_session.add(user)
        orm_session.commit()
        return to_collection(user, sort_keys=True)

    @cherrypy.tools.json_out()
    def show(self, id, **kwargs):
        #return 'getting someone'
        id = int(id)
        user = api.find_user_by_id(cherrypy.request.orm_session, id)
        if user:
            return to_collection(user, excludes=("password", "salt"),
                              sort_keys=True)
        #else:
        #    return {}
        raise HTTPError(404)

    @cherrypy.tools.json_out()
    def update(self, id, **kwargs):
        return 'changing someone'
        id = int(id)
        req = cherrypy.request
        orm_session = req.orm_session
        user = api.find_user_by_id(orm_session, id)
        if user:
            user = from_collection(req.json, user)
            orm_session.commit()
            return to_collection(user, includes="age", excludes=("password", "salt"),
                              sort_keys=True)
        raise HTTPError(404)

    def delete(self, id, **kwargs):
        return 'removing someone'
        id = int(id)
        req = cherrypy.request
        orm_session = req.orm_session
        if not api.delete_user_by_id(orm_session, id):
            raise HTTPError(404)
        else:
            orm_session.commit()


participants_api = cherrypy.dispatch.RoutesDispatcher()
participants_api.mapper.explicit = False
participants_api.connect("add", "/add", Participants, action="create",
                        conditions={"method":["POST","GET"]})
participants_api.connect("get", "/get/{id}", Participants, action="show",
                        conditions={"method":["POST","GET"]})
participants_api.connect("edit", "/edit/{id}", Participants, action="update",
                        conditions={"method":["POST","GET"]})
participants_api.connect("remove", "/remove/{id}", Participants, action="delete",
                        conditions={"method":["POST","GET"]})

# Error handlers

def generic_error_handler(status, message, traceback, version):
    """error_page.default"""
    
    response = cherrypy.response
    response.headers['Content-Type'] = "application/json"
    response.headers.pop('Content-Length', None)
<commit_msg>changed to REST<commit_after>import json

import sys
import traceback

import cherrypy

from cherrypy import HTTPError
from cherrypy.lib import httputil as cphttputil
from blueberrypy.util import from_collection, to_collection

from GDGUkraine import api
from GDGUkraine.model import User, Event, EventParticipant, Place


class Participants:

    _cp_config = {"tools.json_in.on": True}

    @cherrypy.tools.json_out()
    def create(self, **kwargs):
        #return 'creating someone'
        req = cherrypy.request
        orm_session = req.orm_session
        user = from_collection(req.json, User())
        orm_session.add(user)
        orm_session.commit()
        return to_collection(user, sort_keys=True)

    @cherrypy.tools.json_out()
    def show(self, id, **kwargs):
        #return 'getting someone'
        id = int(id)
        user = api.find_user_by_id(cherrypy.request.orm_session, id)
        if user:
            return to_collection(user, excludes=("password", "salt"),
                              sort_keys=True)
        #else:
        #    return {}
        raise HTTPError(404)

    @cherrypy.tools.json_out()
    def update(self, id, **kwargs):
        return 'changing someone'
        id = int(id)
        req = cherrypy.request
        orm_session = req.orm_session
        user = api.find_user_by_id(orm_session, id)
        if user:
            user = from_collection(req.json, user)
            orm_session.commit()
            return to_collection(user, includes="age", excludes=("password", "salt"),
                              sort_keys=True)
        raise HTTPError(404)

    def delete(self, id, **kwargs):
        return 'removing someone'
        id = int(id)
        req = cherrypy.request
        orm_session = req.orm_session
        if not api.delete_user_by_id(orm_session, id):
            raise HTTPError(404)
        else:
            orm_session.commit()


participants_api = cherrypy.dispatch.RoutesDispatcher()
participants_api.mapper.explicit = False
participants_api.connect("add", "/", Participants, action="create",
                        conditions={"method":["GET"]})
participants_api.connect("get", "/{id}", Participants, action="show",
                        conditions={"method":["POST"]})
participants_api.connect("edit", "/{id}", Participants, action="update",
                        conditions={"method":["PUT"]})
participants_api.connect("remove", "/{id}", Participants, action="delete",
                        conditions={"method":["DELETE"]})

# Error handlers

def generic_error_handler(status, message, traceback, version):
    """error_page.default"""
    
    response = cherrypy.response
    response.headers['Content-Type'] = "application/json"
    response.headers.pop('Content-Length', None)

{'fraction_non_alphanumeric': 0.12045820655092178, 'fraction_numerical': 0.0032217648111687847, 'mean_word_length': 2.681159420289855, 'pattern_counts': {'":': 10, '<': 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': '5196083', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1584, 'n_words': 345}