コード例 #1
0
ファイル: redis_async.py プロジェクト: lint-ai/vibora
async def home(request):
    print(request.session.dump())
    await request.load_session()
    if request.session.get('count') is None:
        request.session['count'] = 0
    request.session['count'] += 1
    return Response(str(request.session['count']).encode())
コード例 #2
0
ファイル: app.py プロジェクト: scutwukai/simple-benchmark
async def redis(req: Request):
    values = parse_qs((await req.stream.read()).decode('utf-8'))
    key = values['key'][0]

    await app.redis.set(key, 'hello redis')
    word = await app.redis.get(key)

    return Response(word, headers={'Content-Type': 'text/plain; charset=utf-8'})
コード例 #3
0
ファイル: app.py プロジェクト: scutwukai/simple-benchmark
async def mysql(req: Request):
    values = parse_qs((await req.stream.read()).decode('utf-8'))
    sql = values['sql'][0]

    async with app.mysql.acquire() as conn:
        async with conn.cursor() as cur:
            await cur.execute(sql)
            value = await cur.fetchone()

            return Response(bytes(str(value[0]), 'utf-8'), headers={'Content-Type': 'text/plain; charset=utf-8'})
コード例 #4
0
async def redis_hello_world(request: Request):
    if request.method == b"GET":
        return Response(hello_redis.get(), headers={'content-type': 'json'})
    if request.method == b"POST":
        schema = await AddValueSchema.load_json(request)
        hello_redis.post(schema.value)
        return JsonResponse({})
    if request.method == b"DELETE":
        hello_redis.delete()
        return JsonResponse({})
コード例 #5
0
ファイル: responses.py プロジェクト: lint-ai/vibora
 def test_plain_response_attributes(self):
     headers = {'server': 'Vibora'}
     cookies = [Cookie('server', 'Vibora')]
     status_code = 404
     content = b'HelloWorld'
     response = Response(content,
                         headers=headers,
                         cookies=cookies,
                         status_code=status_code)
     self.assertEqual(response.cookies, cookies)
     self.assertEqual(response.headers['server'], headers['server'])
     self.assertEqual(response.status_code, status_code)
     self.assertEqual(response.content, content)
コード例 #6
0
 def test_plain_response_attributes(self):
     headers = {"server": "Vibora"}
     cookies = [Cookie("server", "Vibora")]
     status_code = 404
     content = b"HelloWorld"
     response = Response(content,
                         headers=headers,
                         cookies=cookies,
                         status_code=status_code)
     self.assertEqual(response.cookies, cookies)
     self.assertEqual(response.headers["server"], headers["server"])
     self.assertEqual(response.status_code, status_code)
     self.assertEqual(response.content, content)
コード例 #7
0
ファイル: main.py プロジェクト: lwakefield/rhender
async def render(request: Request):
    body = await request.json()
    repository_url = body.get('repository_url')
    encoded_url = urllib.parse.quote_plus(repository_url)
    project_path = Config.DATA_DIR + '/' + encoded_url

    # this is either the first time and we need to clone the repo, or it
    # is not the first time, and we should pull to make sure it is up to
    # date
    if not os.path.isdir(project_path):
        with cd(Config.DATA_DIR):
            os.system('git clone %s %s' % (repository_url, encoded_url))
    else:
        with cd(project_path):
            os.system('git pull origin master')

    entry = body.get('entry')
    data = body.get('data')
    template_type = body.get('type')

    result = None
    if template_type == 'mustache':
        with cd(project_path):
            renderer = Renderer()
            result = renderer.render_path(entry, data)
    elif template_type == 'jinja':
        env = Environment(loader=FileSystemLoader(project_path))
        template = env.get_template(entry)
        result = template.render(**data)
    else:
        return Response(status=400)

    return Response(
        content=bytes(result, 'utf-8'),
        headers={
            'Content-Type': 'text/plain'
        }
    )
コード例 #8
0
ファイル: gui.py プロジェクト: novolei/Miyagi
 async def create_modify_object_handler(request: Request, uid: int):
     """Handler for forms:
     Instantiates the given template with kwargs, renders it and returns it"""
     obj = kwargs.get('obj')
     session = self.app.db.session()
     if request.method == b'GET':
         if uid:
             inst = session.query(obj.cls).filter_by(uid=uid).first()
             if not inst:
                 # TODO: raise
                 inst = obj.cls.new()
         else:
             inst = obj.cls.new()
     elif request.method == b'POST':
         if uid:
             inst = session.query(obj.cls).filter_by(uid=uid).first()
         else:
             inst = obj.cls.new()
         form = await request.form()
         inst.set_dict(form)
         inst.save()
     kwargs['inst'] = inst
     return Response(template(self.app, **kwargs).render().encode())
コード例 #9
0
 async def home(count: int):
     return Response(str(count + 1).encode())
コード例 #10
0
 async def home():
     return Response(b'Correct.')
コード例 #11
0
 async def home():
     await asyncio.sleep(10)
     return Response(b'Wrong. This request should timeout.')
コード例 #12
0
 async def home():
     return Response(b"Correct.")
コード例 #13
0
ファイル: strategies.py プロジェクト: wulfnb/vibora-old
 async def home(name: str):
     return Response(name.encode())
コード例 #14
0
ファイル: limits.py プロジェクト: lint-ai/vibora
 async def home():
     return Response(b'Wrong. Request should halted earlier.')
コード例 #15
0
ファイル: limits.py プロジェクト: lint-ai/vibora
 async def home(request: Request):
     await request.stream.read()
     return Response(b'Correct. Request should pass without problems.')
コード例 #16
0
def home():
    time.sleep(10)
    return Response(b'123')
コード例 #17
0
ファイル: limits.py プロジェクト: lint-ai/vibora
 async def home(request: Request):
     await request.stream.read()
     return Response(b'Correct. Request should not be blocked.')
コード例 #18
0
 async def home(name: bytes):
     return Response(name)
コード例 #19
0
async def plaintext():
    return Response(b'Hello, World!',
                    headers={
                        'Server': 'Vibora',
                        'Content-Type': 'text/plain'
                    })
コード例 #20
0
ファイル: upload.py プロジェクト: wulfnb/vibora-old
def home(request: Request):
    print(request.form)
    return Response(b'asd')
コード例 #21
0
 async def handle_errors3():
     return Response(b"Child!", status_code=500)
コード例 #22
0
 async def handle_errors2():
     return Response(b"Parent!", status_code=500)
コード例 #23
0
async def plaintext():
    return Response(b"Hello, World!",
                    headers={
                        "Server": "Vibora",
                        "Content-Type": "text/plain"
                    })
コード例 #24
0
 async def home():
     return Response(b"test")
コード例 #25
0
ファイル: limits.py プロジェクト: lint-ai/vibora
 async def home(request: Request):
     await request.stream.read()
     return Response(b'Wrong. Request should halted earlier.')
コード例 #26
0
ファイル: vibora_app.py プロジェクト: telemansoft/xweb
async def home(request: Request):
    return Response(b'hello world')
コード例 #27
0
ファイル: limits.py プロジェクト: lint-ai/vibora
 async def home():
     return Response(b'Correct. Request should pass without problems.')
コード例 #28
0
ファイル: strategies.py プロジェクト: wulfnb/vibora-old
 async def home():
     return Response(b'123')
コード例 #29
0
ファイル: limits.py プロジェクト: lint-ai/vibora
 async def home(request: Request):
     await request.stream.read()
     return Response(
         b'Wrong. Request must be blocked because this route is more restrictive.'
     )
コード例 #30
0
ファイル: strategies.py プロジェクト: wulfnb/vibora-old
 async def home(name: int):
     self.assertEqual(name, 123)
     return Response(b'123')