Skip to content

Instantly share code, notes, and snippets.

@uranusjr
Forked from mrjohannchang/api.py
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uranusjr/1e824ad86f02d0a262e2 to your computer and use it in GitHub Desktop.
Save uranusjr/1e824ad86f02d0a262e2 to your computer and use it in GitHub Desktop.
import functools
class Api:
def __init__(self):
self.apis = []
def register(self, f):
self.apis.append(f.__name__)
@functools.wraps(f)
def wrapper(*args, **kwargs):
f(*args, **kwargs)
return wrapper
import api
myapi = api.Api()
@myapi.register
def p(s, q=None):
print(s)
print(q)
@myapi.register
def b():
print('b')
myapi2 = api.Api()
@myapi2.register
def c():
print('c')
print(myapi.apis)
print(myapi2.apis)
p('s', q='q')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment