Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bottle
- import functools
- private = bottle.Bottle()
- @private.get('/')
- def private_index():
- return 'Follow the white rabbit.';
- @bottle.get('/')
- def public_index():
- return 'Knock, Knock, Knock, Neo.';
- def auth(callback):
- @functools.wraps(callback)
- def wrapper(*args, **kwargs):
- if bottle.request.remote_addr not in ('::1', '127.0.0.1'):
- bottle.abort(401, 'Go away!')
- else:
- return callback(*args, **kwargs)
- return wrapper
- if __name__ == '__main__':
- private.install(auth)
- bottle.mount(prefix='/private', app=private)
- bottle.run(host=('::'), port=8000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement