예제 #1
0
파일: techem.py 프로젝트: MarkReedZ/mrhttp
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})
예제 #2
0
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>"
예제 #3
0
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]})
예제 #4
0
def login(r):
    app.setUserSessionAndCookies(r, mrjson.dumps({"user": "******"}))
    return 'Logged in!'
예제 #5
0
"\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" )  
예제 #6
0
파일: techem.py 프로젝트: MarkReedZ/mrhttp
def j(r):
    return json.dumps({'message': 'Hello, world!'})
예제 #7
0
파일: s1.py 프로젝트: MarkReedZ/mrhttp
def parseForm(r):
    if r.form == None: return "No form"
    return json.dumps(r.form)
예제 #8
0
#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)