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
[pipeline:main] | |
pipeline = auth hello | |
[app:hello] | |
paste.app_factory = app_layer:app_factory | |
[filter:auth] | |
paste.filter_factory = auth_layer:filter_factory |
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 webob import Response | |
from webob.dec import wsgify | |
@wsgify | |
def application(request): | |
return Response('Hello, welcome to paste \n') | |
def app_factory(global_config, **local_config): | |
return application |
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 webob.dec import wsgify | |
from webob import exc | |
@wsgify.middleware | |
def auth_filter(request, app): | |
if request.headers.get('X-Auth-Token') != 'open-sesame': | |
return exc.HTTPForbidden() | |
return app(request) | |
def filter_factory(global_config, **local_config): |
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 paste import httpserver | |
from paste.deploy import loadapp | |
wsgi_app = loadapp('config:' + '/etc/example/paste.ini') | |
httpserver.serve(wsgi_app, host='127.0.0.1', port=8080) |
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
import sys | |
import urllib2 | |
req = urllib2.Request('http://127.0.0.1:8080') | |
req.add_header('X-Auth-Token', sys.argv[1]) | |
try: | |
res = urllib2.urlopen(req) | |
print res.read() | |
except urllib2.HTTPError as e: |
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
$ python start_app.py | |
serving on http://127.0.0.1:8080 | |
$ python do_get.py wrong-token | |
HTTP Error 403: Forbidden | |
$ py do_get.py open-sesame | |
Hello, welcome to paste |
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
$ python start_app.py | |
serving on http://127.0.0.1:8080 | |
$ curl -H "X-Auth-Token:open-sesame" http://127.0.0.1:8080 | |
Hello, welccome to paste | |
$ curl -H "X-Auth-Token:bad-token" http://127.0.0.1:8080 | |
<html> |
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
import eventlet | |
def add(x, y): | |
return x + y | |
e = eventlet.spawn(add, 1, 2) | |
print e | |
res = e.wait() | |
print '1 + 2 =', res |
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
import eventlet | |
def func1(): | |
# suspend me and run something else | |
# but switch back to me after 2 seconds (if you can) | |
eventlet.sleep(2) | |
print "func1" | |
def func2(): | |
eventlet.sleep(1) |
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
import eventlet | |
from eventlet import event | |
evt = event.Event() | |
def waiter(): | |
evt.wait() | |
print "waiter" | |
w = eventlet.spawn(waiter) |
OlderNewer