<commit_before>import shelve
import sys
from wsgiref.simple_server import make_server

import pyramid.httpexceptions as exc
from pyramid.config import Configurator
from pyramid.response import Response

DB_NAME = 'score_set'


with shelve.open(DB_NAME) as db:
    db['p1'] = 1000
    db['p2'] = 2000


def home(request):
    with shelve.open(DB_NAME) as db:
        for key in db:
            p1_score = key.upper() + " " + str(db[key])

    return Response(str(p1_score))


def players(request):
    content = """
    <form action="" method="POST">
        <input id="player-name" type="text" name="player-name">
        <input id="submit" type="submit" value="Create">
    </form>
    """

    return Response(content) 


def create_player(request):
    name = request.POST['player-name']

    with shelve.open(DB_NAME) as db:
        db[name] = 1000

    raise exc.HTTPFound('/players/test')


def view_player(request):
    name = request.matchdict['player']

    with shelve.open(DB_NAME) as db:
        player_score = name.upper() + ' ' + str(db[name])

    return Response(player_score)


config = Configurator()
config.add_route('home', '/')
config.add_view(home, route_name='home')

config.add_route('players', '/players')
config.add_view(players, route_name='players', request_method='GET')
config.add_view(create_player, route_name='players', request_method='POST')

config.add_route('player', '/players/{player}')
config.add_view(view_player, route_name='player')

app = config.make_wsgi_app()


if __name__ == '__main__':
    sys.stderr.write("started\n")
    sys.stderr.flush()

    server = make_server('127.0.0.1', 8080, app)
    server.serve_forever()
<commit_msg>Remove hard coded URL for user<commit_after>import shelve
import sys
from wsgiref.simple_server import make_server

import pyramid.httpexceptions as exc
from pyramid.config import Configurator
from pyramid.response import Response

DB_NAME = 'score_set'


with shelve.open(DB_NAME) as db:
    db['p1'] = 1000
    db['p2'] = 2000


def home(request):
    with shelve.open(DB_NAME) as db:
        for key in db:
            p1_score = key.upper() + " " + str(db[key])

    return Response(str(p1_score))


def players(request):
    content = """
    <form action="" method="POST">
        <input id="player-name" type="text" name="player-name">
        <input id="submit" type="submit" value="Create">
    </form>
    """

    return Response(content) 


def create_player(request):
    name = request.POST['player-name']

    with shelve.open(DB_NAME) as db:
        db[name] = 1000

    raise exc.HTTPFound(request.route_url('player', player=name))


def view_player(request):
    name = request.matchdict['player']

    with shelve.open(DB_NAME) as db:
        player_score = name.upper() + ' ' + str(db[name])

    return Response(player_score)


config = Configurator()
config.add_route('home', '/')
config.add_view(home, route_name='home')

config.add_route('players', '/players')
config.add_view(players, route_name='players', request_method='GET')
config.add_view(create_player, route_name='players', request_method='POST')

config.add_route('player', '/players/{player}')
config.add_view(view_player, route_name='player')

app = config.make_wsgi_app()


if __name__ == '__main__':
    sys.stderr.write("started\n")
    sys.stderr.flush()

    server = make_server('127.0.0.1', 8080, app)
    server.serve_forever()

{'fraction_non_alphanumeric': 0.14667842445620224, 'fraction_numerical': 0.015285126396237508, 'mean_word_length': 4.034023668639053, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4083795', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1132, 'n_words': 238}