SHARE
TWEET

Untitled

a guest May 3rd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # coding: utf-8
  2. import functools
  3.  
  4.  
  5. def my_retry(function):
  6.     @functools.wraps(function)
  7.     def wrapped(*args, **kwargs):
  8.         print("my_retry calls", function.__name__)
  9.         return function(*args, **kwargs)
  10.  
  11.     return wrapped
  12.  
  13.  
  14. def another_retry(function):
  15.     @functools.wraps(function)
  16.     def wrapped(*args, **kwargs):
  17.         print("another_retry calls", function.__name__)
  18.         return function(*args, **kwargs)
  19.  
  20.     return wrapped
  21.  
  22.  
  23. class ApiClient:
  24.     def __init__(self, retry_function=None):
  25.         # self.retry_function = my_retry
  26.         # if retry_function:
  27.         #     self.retry_function = retry_function
  28.         pass
  29.  
  30.     @my_retry
  31.     def execute_hoge_api(self):
  32.         print("hoge!")
  33.  
  34.     @my_retry
  35.     def execute_fuga_api(self):
  36.         print("fuga!")
  37.  
  38.  
  39. def main():
  40.     ac = ApiClient()
  41.     ac.execute_hoge_api()
  42.     ac.execute_fuga_api()
  43.  
  44.     bc = ApiClient(retry_function=another_retry)
  45.     bc.execute_hoge_api()
  46.     bc.execute_fuga_api()
  47.  
  48.  
  49. if __name__ == '__main__':
  50.     main()
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