Created
October 20, 2017 19:27
-
-
Save DrJackilD/612733a7c2fa0b6be3da27536b916b48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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