Last active
July 6, 2020 05:19
-
-
Save mtreacy002/3cb67497f971c4651cf2cacdf5fae532 to your computer and use it in GitHub Desktop.
Python decorator - tuple to namedtuple
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
@http_response_namedtuple_converter | |
def http_response_checker(result): | |
if result.status_code == HTTPStatus.NOT_FOUND: | |
result = http_not_found_status_checker(result) | |
#... more 'if' here | |
return result | |
@http_response_namedtuple_converter | |
def http_not_found_status_checker(result): | |
if result.message == messages.WRONG_USERNAME_OR_PASSWORD: | |
return result._replace(status_code=HTTPStatus.UNAUTHORIZED) | |
#... more 'if' here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment