SHARE
TWEET

Untitled

a guest Feb 20th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Using class expressions for declarative programming in python
  2. import traceback
  3. import inspect
  4.  
  5.  
  6. classes = {}
  7.  
  8. def route(path, func, *methods):
  9.     clsname = inspect.currentframe().f_back.f_code.co_name
  10.     classes.setdefault(clsname, []).extend([path, func, *methods])
  11.  
  12.  
  13. def foo():
  14.     pass
  15.  
  16. class Routes:
  17.     # When this run Routes class doesn't exists yet
  18.     route('/foo', foo, 'POST', 'GET')
  19.  
  20. print(classes)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top