async def db(r): #id_ = random.randint(1, 500) id_ = int(random.random() * 500) #id_ = 1 async with app.pg_pool.acquire() as conn: r = await conn.fetchval('SELECT randomnumber FROM world WHERE id = $1', id_) return json.dumps({'id': id_, 'randomNumber': r})
async def login(r): # This creates a session key, stores it in memcache with the user's data, and sets the session # cookie in the browser try: app.setUserSessionAndCookies( r, json.dumps({"user":"******"}) ) except Exception as e: print(e) return "You are now logged in! <a href='/'> Try the main page </a>"
async def db(r): #id_ = int(random.random() * 500) id_ = mrhttp.randint(0, 500) #id_ = 1 async with app.my_pool.acquire() as conn: async with conn.cursor() as cur: await cur.execute("SELECT randomnumber FROM World WHERE id = %s", id_) r = await cur.fetchone() return json.dumps({'id': id_, 'randomNumber': r[0]})
def login(r): app.setUserSessionAndCookies(r, mrjson.dumps({"user": "******"})) return 'Logged in!'
"\xe6\x97\xa5\xd1\x88", "\xf0\x90\x8d\x86", "\xf3\xbf\xbf\xbffadfadsfas", "fadsfasd\xe6\x97\xa5\xd1\x88", [[[[]]]] * 20, [31337.31337, 31337.31337, 31337.31337, 31337.31337] * 10, {'a': -12345678901234.56789012}, "fadfasd \\ / \r \t \n \b \fxx fadsfas", "这是unicode吧你喜欢吗?我的中文最漂亮", ["别","停","believing", -1,True,"zero",False, 1.0], None, True,False,float('inf'), [18446744073709551615, 18446744073709551615, 18446744073709551615], ] # NaN != Nan so check str rep o = j.loads( j.dumps( float('nan') ) ) eq( str(o), 'nan' ) for o in objs: try: eq( o, j.loads(j.dumps(o)) ) except Exception as e: print( "ERROR",str(e), o ) raises( "NaNd", j.loads, ValueError, "JSON_BAD_IDENTIFIER" ) raises( "[", j.loads, ValueError, "JSON_UNEXPECTED_END" ) raises( "]", j.loads, ValueError, "JSON_STACK_UNDERFLOW" ) raises( "{", j.loads, ValueError, "JSON_UNEXPECTED_END" ) raises( "}", j.loads, ValueError, "JSON_STACK_UNDERFLOW" )
def j(r): return json.dumps({'message': 'Hello, world!'})
def parseForm(r): if r.form == None: return "No form" return json.dumps(r.form)
#o = {"name":55,"tl":2004,"dankmemes":True,"list":[1,2,3,4,5,6]} #o = [ "fadsfds", 213 , 123, 1, 2, 3, "lists are cool", [1,2,3,] ] for x in range(1): if 1: #st = time.time() b = mrp.pack(o) #print( "took ", time.time()-st) #st = time.time() #o = mrp.unpack( b ) #print( "took ", time.time()-st) #exit(1) if 0: #st = time.time() b = mrjson.dumps(o) #print( "took ", time.time()-st) #st = time.time() #o = mrjson.loads( b ) #print( "took ", time.time()-st) if 0: #print(b) print("ujson:") st = time.time() b = ujson.dumps(o) print("took ", time.time() - st) st = time.time() o = ujson.loads(b) print("took ", time.time() - st) #print(b)