Created
March 5, 2013 15:12
-
-
Save t0ster/5090969 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 user_validator(obj): | |
return True | |
class BaseHandler(object): | |
validator = None | |
def post(self, data): | |
if self.validator(data): | |
return 'ok' | |
else: | |
return 'error' | |
class UserHandler(BaseHandler): | |
validator = user_validator | |
def main(): | |
user_handler = UserHandler() | |
print user_handler.post('somedata') | |
if __name__ == '__main__': | |
main() |
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
Traceback (most recent call last): | |
File "/Users/t0ster/Desktop/test.py", line 24, in <module> | |
main() | |
File "/Users/t0ster/Desktop/test.py", line 20, in main | |
print user_handler.post('somedata') | |
File "/Users/t0ster/Desktop/test.py", line 8, in post | |
if self.validator(data): | |
TypeError: user_validator() takes exactly 1 argument (2 given) | |
[Finished in 0.1s with exit code 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment