This file contains hidden or 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_session import get_session | |
def flash(request, message): | |
request.setdefault('flash_outgoing', []).append(message) | |
async def context_processor(request): | |
return { | |
'get_flashed_messages': lambda: request.pop('flash_incoming') |
This file contains hidden or 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
import asyncio | |
from aiohttp import web | |
from aiohttp_session import get_session, session_middleware, SimpleCookieStorage | |
async def show(request): | |
session = await get_session(request) | |
message = session.pop('message', None) | |
return web.Response(text='message: {}'.format(message)) |
This file contains hidden or 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
''' | |
I started one server: | |
$ python aiohttp_rq.py server | |
And three workers in different terminals: | |
$ python aiohttp_rq.py worker | |
And I got next results with ab: |
This file contains hidden or 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 time import time | |
import asyncio | |
import aiohttp | |
from aiohttp import web | |
async def web_handler(request): | |
n = int(request.GET.get('n', 0)) | |
return web.Response(text=str(n+1)) |
This file contains hidden or 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 | |
def get_qs_argument(request, *args, **kwargs): | |
return _get_argument(request.GET, *args, **kwargs) | |
def get_url_argument(request, *args, **kwargs): | |
return _get_argument(request.match_info, *args, **kwargs) | |
This file contains hidden or 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
seq = ['a', 1, True, 'b', 'foo', 'bar'] | |
for item in seq: | |
print(item) | |
print() | |
i = 0 | |
while i < len(seq): |
This file contains hidden or 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
import asyncio | |
import aiorest | |
import aiohttp | |
class RESTResource: | |
# you can redefine it in subclasses | |
handlers = [ | |
('list', 'GET', []), |
This file contains hidden or 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
import os | |
import sqlite3 | |
import ConfigParser | |
class FirefoxCookies(object): | |
''' | |
Usage: | |
cookies = FirefoxCookies() | |
print cookies.items() # [(name, value), ...] |
This file contains hidden or 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
/*jslint node: true */ | |
"use strict"; | |
function noname_deps(paths) { | |
function format_single(path, parent_name) { | |
var dep = {path: path}; | |
if (parent_name) { | |
dep.require = {}; | |
dep.require[parent_name] = parent_name; | |
} |
NewerOlder