Skip to content

Instantly share code, notes, and snippets.

@DrJackilD
Created October 20, 2017 19:27
Show Gist options
  • Save DrJackilD/612733a7c2fa0b6be3da27536b916b48 to your computer and use it in GitHub Desktop.
Save DrJackilD/612733a7c2fa0b6be3da27536b916b48 to your computer and use it in GitHub Desktop.
def check_setting(param_name):
"""
Simple decorator to disable pipeline for spiders with some attributes
```
class A:
f_enabled = True
@check_setting('f_enabled')
def f(self, times):
print(' '.join(['hey!'] * times))
```
:param param_name: class attribute which must be checked
"""
def func_wrapper(func):
def wrapper(self, *args, **kwargs):
if getattr(self, param_name):
return func(self, *args, **kwargs)
return
return wrapper
return func_wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment