<commit_before>from bottle import Bottle, route, request, run, template
from bottle.ext import sqlalchemy 
from sqlalchemy import create_engine, Column, Integer, Unicode
from sqlalchemy.ext.declarative import declarative_base
from random import randint
import ujson
from operator import attrgetter, itemgetter
from functools import partial

app = Bottle()
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://benchmarkdbuser:benchmarkdbpass@DBHOSTNAME:3306/hello_world?charset=utf8'
Base = declarative_base()
db_engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
plugin = sqlalchemy.Plugin(db_engine, keyword='db', )
app.install(plugin)


class World(Base):
  __tablename__ = "World"
  id = Column(Integer, primary_key=True)
  randomNumber = Column(Integer)

  # http://stackoverflow.com/questions/7102754/jsonify-a-sqlalchemy-result-set-in-flask
  @property
  def serialize(self):
     """Return object data in easily serializeable format"""
     return {
         'id'         : self.id,
         'randomNumber': self.randomNumber
     }

class Fortune(Base):
  __tablename__ = "Fortune"
  id = Column(Integer, primary_key=True)
  message = Column(Unicode)

@app.route("/json")
def hello():
  resp = {"message": "Hello, World!"}
  return ujson.dumps(resp)

@app.route("/db")
def get_random_world(db):
  num_queries = request.query.queries or '1'
  worlds = []
  rp = partial(randint, 1, 10000)
  for i in xrange(int(num_queries)):
    worlds.append(db.query(World).get(rp()).serialize)
  return ujson.dumps(worlds)

@app.route("/dbs")
def get_random_world_single(db):
  wid = randint(1, 10000)
  worlds = [db.query(World).get(wid).serialize]
  return ujson.dumps(worlds)
  
@app.route("/dbraw")
def get_random_world_raw():
  connection = db_engine.connect()
  num_queries = request.query.queries or '1'
  worlds = []
  rp = partial(randint, 1, 10000)
  for i in range(int(num_queries)):
    result = connection.execute("SELECT * FROM world WHERE id = " + str(rp())).fetchone()
    worlds.append({'id': result[0], 'randomNumber': result[1]})
  connection.close()
  return ujson.dumps(worlds)

@app.route("/dbsraw")
def get_random_world_single_raw():
  connection = db_engine.connect()
  wid = randint(1, 10000)
  result = connection.execute("SELECT * FROM world WHERE id = " + str(wid)).fetchone()
  worlds = [{'id': result[0], 'randomNumber': result[1]}]
  connection.close()
  return ujson.dumps(worlds)

@app.route("/fortune")
def fortune_orm(db):
  fortunes=db.query(Fortune).all()
  fortunes.append(Fortune(message="Additional fortune added at request time."))
  fortunes=sorted(fortunes, key=attrgetter('message'))
  return template('fortune-obj', fortunes=fortunes)

@app.route("/fortuneraw")
def fortune_raw():
  connection = db_engine.connect()
  fortunes=[(f.id, f.message) for f in connection.execute("SELECT * FROM Fortune")]
  fortunes.append((0L, u'Additional fortune added at request time.'))
  fortunes=sorted(fortunes, key=itemgetter(1))
  connection.close()
  return template('fortune', fortunes=fortunes)

if __name__ == "__main__":
    app.run(host='0.0.0.0', debug=True)<commit_msg>Fix Syntax error on Python 3<commit_after>from bottle import Bottle, route, request, run, template
from bottle.ext import sqlalchemy 
from sqlalchemy import create_engine, Column, Integer, Unicode
from sqlalchemy.ext.declarative import declarative_base
from random import randint
import ujson
from operator import attrgetter, itemgetter
from functools import partial

app = Bottle()
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://benchmarkdbuser:benchmarkdbpass@DBHOSTNAME:3306/hello_world?charset=utf8'
Base = declarative_base()
db_engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
plugin = sqlalchemy.Plugin(db_engine, keyword='db', )
app.install(plugin)


class World(Base):
  __tablename__ = "World"
  id = Column(Integer, primary_key=True)
  randomNumber = Column(Integer)

  # http://stackoverflow.com/questions/7102754/jsonify-a-sqlalchemy-result-set-in-flask
  @property
  def serialize(self):
     """Return object data in easily serializeable format"""
     return {
         'id'         : self.id,
         'randomNumber': self.randomNumber
     }

class Fortune(Base):
  __tablename__ = "Fortune"
  id = Column(Integer, primary_key=True)
  message = Column(Unicode)

@app.route("/json")
def hello():
  resp = {"message": "Hello, World!"}
  return ujson.dumps(resp)

@app.route("/db")
def get_random_world(db):
  num_queries = request.query.queries or '1'
  worlds = []
  rp = partial(randint, 1, 10000)
  for i in xrange(int(num_queries)):
    worlds.append(db.query(World).get(rp()).serialize)
  return ujson.dumps(worlds)

@app.route("/dbs")
def get_random_world_single(db):
  wid = randint(1, 10000)
  worlds = [db.query(World).get(wid).serialize]
  return ujson.dumps(worlds)
  
@app.route("/dbraw")
def get_random_world_raw():
  connection = db_engine.connect()
  num_queries = request.query.queries or '1'
  worlds = []
  rp = partial(randint, 1, 10000)
  for i in range(int(num_queries)):
    result = connection.execute("SELECT * FROM world WHERE id = " + str(rp())).fetchone()
    worlds.append({'id': result[0], 'randomNumber': result[1]})
  connection.close()
  return ujson.dumps(worlds)

@app.route("/dbsraw")
def get_random_world_single_raw():
  connection = db_engine.connect()
  wid = randint(1, 10000)
  result = connection.execute("SELECT * FROM world WHERE id = " + str(wid)).fetchone()
  worlds = [{'id': result[0], 'randomNumber': result[1]}]
  connection.close()
  return ujson.dumps(worlds)

@app.route("/fortune")
def fortune_orm(db):
  fortunes=db.query(Fortune).all()
  fortunes.append(Fortune(message="Additional fortune added at request time."))
  fortunes=sorted(fortunes, key=attrgetter('message'))
  return template('fortune-obj', fortunes=fortunes)

@app.route("/fortuneraw")
def fortune_raw():
  connection = db_engine.connect()
  fortunes=[(f.id, f.message) for f in connection.execute("SELECT * FROM Fortune")]
  fortunes.append((0, u'Additional fortune added at request time.'))
  fortunes=sorted(fortunes, key=itemgetter(1))
  connection.close()
  return template('fortune', fortunes=fortunes)

if __name__ == "__main__":
    app.run(host='0.0.0.0', debug=True)
{'fraction_non_alphanumeric': 0.1436818473380372, 'fraction_numerical': 0.015554842847979474, 'mean_word_length': 5.175247524752475, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '2792611', 'n_tokens_mistral': 2207, 'n_tokens_neox': 2134, 'n_words': 450}