Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. import bottle
  2. import functools
  3.  
  4.  
  5. private = bottle.Bottle()
  6.  
  7.  
  8. @private.get('/')
  9. def private_index():
  10. return 'Follow the white rabbit.';
  11.  
  12.  
  13. @bottle.get('/')
  14. def public_index():
  15. return 'Knock, Knock, Knock, Neo.';
  16.  
  17.  
  18. def auth(callback):
  19. @functools.wraps(callback)
  20. def wrapper(*args, **kwargs):
  21. if bottle.request.remote_addr not in ('::1', '127.0.0.1'):
  22. bottle.abort(401, 'Go away!')
  23. else:
  24. return callback(*args, **kwargs)
  25.  
  26. return wrapper
  27.  
  28.  
  29. if __name__ == '__main__':
  30. private.install(auth)
  31.  
  32. bottle.mount(prefix='/private', app=private)
  33. bottle.run(host=('::'), port=8000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement