Use decorator library
This commit is contained in:
+13
-20
@@ -1,5 +1,6 @@
|
||||
from difflib import get_close_matches
|
||||
from functools import wraps
|
||||
from decorator import decorator
|
||||
|
||||
import os
|
||||
import pickle
|
||||
@@ -47,12 +48,9 @@ def wrap_settings(params):
|
||||
print(settings.apt)
|
||||
|
||||
"""
|
||||
def decorator(fn):
|
||||
@wraps(fn)
|
||||
def wrapper(command, settings):
|
||||
return fn(command, settings.update(**params))
|
||||
return wrapper
|
||||
return decorator
|
||||
def _wrap_settings(fn, command, settings):
|
||||
return fn(command, settings.update(**params))
|
||||
return decorator(_wrap_settings)
|
||||
|
||||
|
||||
def memoize(fn):
|
||||
@@ -110,11 +108,9 @@ def replace_argument(script, from_, to):
|
||||
u' {} '.format(from_), u' {} '.format(to), 1)
|
||||
|
||||
|
||||
def eager(fn):
|
||||
@wraps(fn)
|
||||
def wrapper(*args, **kwargs):
|
||||
return list(fn(*args, **kwargs))
|
||||
return wrapper
|
||||
@decorator
|
||||
def eager(fn, *args, **kwargs):
|
||||
return list(fn(*args, **kwargs))
|
||||
|
||||
|
||||
@eager
|
||||
@@ -146,13 +142,10 @@ def is_app(command, *app_names):
|
||||
|
||||
def for_app(*app_names):
|
||||
"""Specifies that matching script is for on of app names."""
|
||||
def decorator(fn):
|
||||
@wraps(fn)
|
||||
def wrapper(command, settings):
|
||||
if is_app(command, *app_names):
|
||||
return fn(command, settings)
|
||||
else:
|
||||
return False
|
||||
def _for_app(fn, command, settings):
|
||||
if is_app(command, *app_names):
|
||||
return fn(command, settings)
|
||||
else:
|
||||
return False
|
||||
|
||||
return wrapper
|
||||
return decorator
|
||||
return decorator(_for_app)
|
||||
|
||||
Reference in New Issue
Block a user