Skip to content

Commit

Permalink
Merge pull request #8 from alexander-travov/master
Browse files Browse the repository at this point in the history
Fix minimal example
  • Loading branch information
asvetlov committed Apr 24, 2015
2 parents 0918979 + 771cb16 commit 8c709b4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
28 changes: 20 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,33 @@ middleware* in ``aiohttp.web.Application``.

A trivial usage example::

import asycio
import asyncio
import time
from aiohttp import web
import aiohttp_session
from aiohttp_session import get_session, session_middleware
from aiohttp_session.cookie_storage import EncryptedCookieStorage

@asyncio.coroutine
def handler(request):
session = yield from aiohttp_session.get_session(request)
session = yield from get_session(request)
session['last_visit'] = time.time()
return web.Response('OK')
return web.Response(body=b'OK')

app = web.Application(middlewares=[aiohttp_session.session_middleware(
aiohttp_session.EncryptedCookieStorage(b'Sixteen byte key'))])

app.router.add_route('GET', '/', handler)
@asyncio.coroutine
def init(loop):
app = web.Application(middlewares=[session_middleware(
EncryptedCookieStorage(b'Sixteen byte key'))])
app.router.add_route('GET', '/', handler)
srv = yield from loop.create_server(
app.make_handler(), '0.0.0.0', 8080)
return srv

loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
try:
loop.run_forever()
except KeyboardInterrupt:
pass

All storages uses HTTP Cookie named ``AIOHTTP_COOKIE_SESSION`` for storing data.

Expand Down
28 changes: 20 additions & 8 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,33 @@ middleware* in ``aiohttp.web.Application``.

A trivial usage example::

import asycio
import asyncio
import time
from aiohttp import web
import aiohttp_session
from aiohttp_session import get_session, session_middleware
from aiohttp_session.cookie_storage import EncryptedCookieStorage

@asyncio.coroutine
def handler(request):
session = yield from aiohttp_session.get_session(request)
session = yield from get_session(request)
session['last_visit'] = time.time()
return web.Response('OK')
return web.Response(body=b'OK')

app = web.Application(middlewares=[aiohttp_session.session_middleware(
aiohttp_session.EncryptedCookieStorage(b'Sixteen byte key'))])

app.router.add_route('GET', '/', handler)
@asyncio.coroutine
def init(loop):
app = web.Application(middlewares=[session_middleware(
EncryptedCookieStorage(b'Sixteen byte key'))])
app.router.add_route('GET', '/', handler)
srv = yield from loop.create_server(
app.make_handler(), '0.0.0.0', 8080)
return srv

loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
try:
loop.run_forever()
except KeyboardInterrupt:
pass

All storages uses HTTP Cookie named ``AIOHTTP_COOKIE_SESSION`` for storing data.

Expand Down

0 comments on commit 8c709b4

Please sign in to comment.