This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aiohttp test coverage badge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aiohttp.web import Request | |
from aiohttp_catcher import catch, Catcher | |
async def message(exc: MyException, request: Request): | |
return "This isn't allowed" | |
async def fields(exc: MyException, req: Request): | |
return { | |
"method": req.method, | |
"error_type": exc.some_error_class_attribute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aiohttp import web | |
from aiohttp_catcher import Catcher | |
from aiohttp_catcher.canned import AIOHTTP_SCENARIOS | |
async def main(): | |
# Add a catcher: | |
catcher = Catcher() | |
# Register aiohttp web errors: | |
await catcher.add_scenario(*AIOHTTP_SCENARIOS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aiohttp import web | |
from aiohttp_catcher import catch, Catcher | |
async def divide(request): | |
quotient = int(request.query.get("x")) / int(request.query.get("y")) | |
return web.json_response(data={"quotient": quotient}) | |
msg = "Zero division makes zero sense" | |
async def main(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@routes.get("/user/{username}") | |
async def get_user(request: web.Request): | |
username = request.match_info.get("username") | |
if username not in USER_DB: | |
return web.json_response( | |
data={"message": "User not found"}, | |
status=404 | |
) | |
return web.json_response(data=USER_DB.get(username)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fetch ace's language tools module: | |
var langTools = ace.require('ace/ext/language_tools'); | |
// data stub: | |
var sqlTables = [ | |
{ name: 'users', description: 'Users in the system' }, | |
{ name: 'userGroups', description: 'User groups to which users belong' }, | |
{ name: 'customers', description: 'Customer entries' }, | |
{ name: 'companies', description: 'Legal entities of customers' }, | |
{ name: 'loginLog', description: 'Log entries for user log-ins' }, |